Rasbypy
Rasbypy

Reputation: 261

GitHub Action: How to fix mvn: command not found issue with nektos/act

Introduction

I'm currently contributing to a GitHub project.
For this, I'm writing a GitHub workflow inside a GitHub Action that tests the creation of JavaDoc files.
This workflow should be run with act.
The project of the GitHub Action when I want to add this GitHub Workflow: https://github.com/MathieuSoysal/Javadoc-publisher.yml

Problem

The problem, when I execute my GitHub workflow with act I obtain this error.

[Test Actions/Test with Java 11] 🚀  Start image=catthehacker/ubuntu:act-latest
[Test Actions/Test with Java 11]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=false
[Test Actions/Test with Java 11]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[Test Actions/Test with Java 11]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[Test Actions/Test with Java 11]   ☁  git clone 'https://github.com/GuillaumeFalourd/assert-command-line-output' # ref=v2
[Test Actions/Test with Java 11] ⭐ Run Pre GuillaumeFalourd/assert-command-line-output@v2
[Test Actions/Test with Java 11]   ☁  git clone 'https://github.com/actions/setup-node' # ref=v2
[Test Actions/Test with Java 11]   ✅  Success - Pre GuillaumeFalourd/assert-command-line-output@v2
[Test Actions/Test with Java 11] ⭐ Run Main actions/checkout@v3
[Test Actions/Test with Java 11]   🐳  docker cp src=/workspaces/Javadoc-publisher.yml/. dst=/workspaces/Javadoc-publisher.yml
[Test Actions/Test with Java 11]   ✅  Success - Main actions/checkout@v3
[Test Actions/Test with Java 11] ⭐ Run Main ./
[Test Actions/Test with Java 11] ⭐ Run Main actions/checkout@v3
[Test Actions/Test with Java 11]   🐳  docker cp src=/workspaces/Javadoc-publisher.yml/. dst=/workspaces/Javadoc-publisher.yml
[Test Actions/Test with Java 11]   ✅  Success - Main actions/checkout@v3
[Test Actions/Test with Java 11]   ☁  git clone 'https://github.com/actions/setup-java' # ref=v3
[Test Actions/Test with Java 11] ⭐ Run Main actions/setup-java@v3
[Test Actions/Test with Java 11]   🐳  docker cp src=/home/codespace/.cache/act/actions-setup-java@v3/ dst=/var/run/act/actions/actions-setup-java@v3/
[Test Actions/Test with Java 11]   🐳  docker exec cmd=[node /var/run/act/actions/actions-setup-java@v3/dist/setup/index.js] user= workdir=
[Test Actions/Test with Java 11]   ❓  ::group::Installed distributions
| Trying to resolve the latest version from remote
| Resolved latest version as 11.0.17+8
| Trying to download...
| Downloading Java 11.0.17+8 (Adopt-Hotspot) from https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.17%2B8/OpenJDK11U-jdk_x64_linux_hotspot_11.0.17_8.tar.gz ...
[Test Actions/Test with Java 11]   💬  ::debug::Downloading https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.17%252B8/OpenJDK11U-jdk_x64_linux_hotspot_11.0.17_8.tar.gz
[Test Actions/Test with Java 11]   💬  ::debug::Destination /tmp/8533ad34-250e-4794-b6bd-f014648ce8b2
[Test Actions/Test with Java 11]   💬  ::debug::download complete
| Extracting Java archive...
[Test Actions/Test with Java 11]   💬  ::debug::Checking tar --version
[Test Actions/Test with Java 11]   💬  ::debug::tar (GNU tar) 1.30%0ACopyright (C) 2017 Free Software Foundation, Inc.%0ALicense GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.%0AThis is free software: you are free to change and redistribute it.%0AThere is NO WARRANTY, to the extent permitted by law.%0A%0AWritten by John Gilmore and Jay Fenlason.
| [command]/usr/bin/tar xz --warning=no-unknown-keyword -C /tmp/4f3b749d-13d5-497d-87d7-45e30a9927cc -f /tmp/8533ad34-250e-4794-b6bd-f014648ce8b2
[Test Actions/Test with Java 11]   💬  ::debug::Caching tool Java_Adopt_jdk 11.0.17-8 x64
[Test Actions/Test with Java 11]   💬  ::debug::source dir: /tmp/4f3b749d-13d5-497d-87d7-45e30a9927cc/jdk-11.0.17+8
[Test Actions/Test with Java 11]   💬  ::debug::destination /opt/hostedtoolcache/Java_Adopt_jdk/11.0.17-8/x64
[Test Actions/Test with Java 11]   💬  ::debug::finished caching tool
| Java 11.0.17+8 was downloaded
| Setting Java 11.0.17+8 as the default
| Creating toolchains.xml for JDK version 11 from adopt
| Writing to /root/.m2/toolchains.xml
| 
| Java configuration:
|   Distribution: adopt
|   Version: 11.0.17+8
|   Path: /opt/hostedtoolcache/Java_Adopt_jdk/11.0.17-8/x64
| 
[Test Actions/Test with Java 11]   ❓  ::endgroup::
[Test Actions/Test with Java 11]   ❓  ##[add-matcher]/run/act/actions/actions-setup-java@v3/.github/java.json
| Creating settings.xml with server-id: github
| Writing to /root/.m2/settings.xml
[Test Actions/Test with Java 11]   ✅  Success - Main actions/setup-java@v3
[Test Actions/Test with Java 11]   ⚙  ::set-output:: distribution=Adopt-Hotspot
[Test Actions/Test with Java 11]   ⚙  ::set-output:: path=/opt/hostedtoolcache/Java_Adopt_jdk/11.0.17-8/x64
[Test Actions/Test with Java 11]   ⚙  ::set-output:: version=11.0.17+8
[Test Actions/Test with Java 11] ⭐ Run Main Generate Javadoc
[Test Actions/Test with Java 11]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/1-composite-2.sh] user= workdir=
| /var/run/act/workflow/1-composite-2.sh: line 2: mvn: command not found
[Test Actions/Test with Java 11]   ❌  Failure - Main Generate Javadoc
[Test Actions/Test with Java 11] exitcode '127': command not found, please refer to https://github.com/nektos/act/issues/107 for more information
[Test Actions/Test with Java 11]   ☁  git clone 'https://github.com/JamesIves/github-pages-deploy-action' # ref=v4.4.0
[Test Actions/Test with Java 11]   ❌  Failure - Main ./
[Test Actions/Test with Java 11] exitcode '127': command not found, please refer to https://github.com/nektos/act/issues/107 for more information
[Test Actions/Test with Java 11] ⭐ Run Post ./
[Test Actions/Test with Java 11] ⭐ Run Post actions/setup-java@v3
[Test Actions/Test with Java 11]   🐳  docker exec cmd=[node /var/run/act/actions/actions-setup-java@v3/dist/cleanup/index.js] user= workdir=
[Test Actions/Test with Java 11]   ✅  Success - Post actions/setup-java@v3
[Test Actions/Test with Java 11]   ✅  Success - Post ./
[Test Actions/Test with Java 11] 🏁  Job failed

GitHub Workflow

My GitHub Workflow :

name: Test Actions

on: [pull_request, push]

jobs:
  test:
    runs-on: ubuntu-latest
    
    name: Test with Java 11
    steps:
      - uses: actions/checkout@v3
      - uses: ./ # Uses an action in the root directory
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          javadoc-branch: javadoc-test
          java-version: 11
          target-folder: javadoc

      - uses: GuillaumeFalourd/assert-command-line-output@v2
        with:
          command_line: ls -lha
          contains: javadoc
          expected_result: PASSED

GitHub Action

The GitHub Action of the project : https://github.com/MathieuSoysal/Javadoc-publisher.yml/blob/main/action.yml

Command

The executed command to run nektos/act : act

Question

Does someone know how we can fix this problem mvn: command not found issue with nektos/act?

Upvotes: 2

Views: 2459

Answers (1)

ThrowsError
ThrowsError

Reputation: 1689

Explanation

Your problem is caused by the fact that the image you use with nektos/act does not has mvn.

How to fix it

You have several possibilities to fix it.

First solution

The first solution: if you want to keep your image.
You can add these lines inside your GitHub workflow to add mvn :

#### This step is only needed for GHA local runner, act:
# https://github.com/nektos/act
      - name: Install curl (for nektos/act local CI testing)
        run: apt-get update && apt-get install build-essential curl pkg-config openssl -y
      - name: Download Maven
        run: |
          curl -sL https://www-eu.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.zip -o maven.zip
          apt-get update
          apt-get -y install unzip
          unzip -d /usr/share maven.zip
          rm maven.zip
          ln -s /usr/share/apache-maven-3.6.3/bin/mvn /usr/bin/mvn
          echo "M2_HOME=/usr/share/apache-maven-3.6.3" | tee -a /etc/environment
####

Second solution

The second solution: if you agree to change your used image.
Instead of your act command, you can execute this:

act -P ubuntu-latest=quay.io/jamezp/act-maven

Upvotes: 8

Related Questions