Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running github actions for `uses` in another directory

My maven repository is in ./java directory. I want to run maven test in ./java directory, but I got following error:

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]

Here is my workflow:

# 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'

It seems that working-directory is useless, how can I fix it?

like image 817
syheliel Avatar asked Apr 28 '26 02:04

syheliel


1 Answers

working-directory can only be applied to run: steps (e.g it does not work on actions)

The action xlui/action-maven-cli@master currently doesn't allow to inform a path to execute the maven commands.

You could either

  • use another (similar) action available on the Github Marketplace which allows to inform a directory path before executing maven commands,

  • open a PR to update the xlui/action-maven-cli action, adding an input path (or env variable) to perform a cd command before executing the maven commands,

  • install maven directly on your workflow within a step(for example setup maven action), before running the maven command directly on another step (without uses the action) with run: | with a cd ./java before executing sh -c "mvn clean package test",

Something like this (for the 3rd option):

steps:
  - uses: actions/checkout@v2
    
  - name: Install maven
    run: |
      ...
  - name: Run maven command
    run: |
      cd ./java
      mvn clean package test
like image 128
GuiFalourd Avatar answered Apr 29 '26 16:04

GuiFalourd