首页 > 解决方案 > 在另一个目录中为“uses”运行 github 操作

问题描述

我的 Maven 存储库在./java目录中。我想在./java目录中运行 Maven 测试,但出现以下错误:

The goal you specified requires a project to execute but there is no POM in this directory (/github/workspace). Please verify you invoked Maven from the correct directory. -> [Help 1]

这是我的工作流程:

# This is a basic workflow to help you get started with Actions

name: CI
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

  workflow_dispatch:


jobs:
  build:
    defaults:
      run:
        working-directory: java
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        
      - name: Run maven test
        uses: xlui/action-maven-cli@master
    
        with:
          lifecycle: 'clean package test'

好像working-directory没用,怎么解决?

标签: mavengithubgithub-actions

解决方案


working-directory只能应用于run:步骤(例如,它不适用于动作)

该操作xlui/action-maven-cli@master当前不允许通知 apath执行 maven 命令。

你也可以

  • 使用Github Marketplace 上可用的另一个(类似)操作,它允许directory path在执行 maven 命令之前通知 a,

  • 打开 PR 以更新xlui/action-maven-cli操作,添加输入path(或env变量)以cd在执行 maven 命令之前执行命令,

  • 在一个步骤中直接安装maven在您的工作流程上(例如setup maven action),然后在另一个步骤(不使用该操作)上直接运行 maven 命令之前使用run: |before cd ./javaexecution sh -c "mvn clean package test"

像这样的东西(对于第三个选项)

steps:
  - uses: actions/checkout@v2
    
  - name: Install maven
    run: |
      ...
  - name: Run maven command
    run: |
      cd ./java
      mvn clean package test

推荐阅读