GitHub Action:如何修复 mvn:nektos/act 的命令未找到问题

Ras*_*ypy 2 java continuous-integration github github-actions

介绍

\n

我目前正在为 GitHub 项目做出贡献。
\n为此,我在 GitHub Action 中编写了一个 GitHub 工作流程,用于测试 JavaDoc 文件的创建。
\n此工作流程应使用act运行。
\n当我想添加此 GitHub 工作流时 GitHub Action 的项目:https://github.com/MathieuSoysal/Javadoc-publisher.yml

\n

问题

\n

问题是,当我使用 act 执行 GitHub 工作流程时,出现此错误。

\n
[Test Actions/Test with Java 11]   Start image=catthehacker/ubuntu:act-latest\n[Test Actions/Test with Java 11]     docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=false\n[Test Actions/Test with Java 11]     docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]\n[Test Actions/Test with Java 11]     docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]\n[Test Actions/Test with Java 11]   \xe2\x98\x81  git clone \'https://github.com/GuillaumeFalourd/assert-command-line-output\' # ref=v2\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Pre GuillaumeFalourd/assert-command-line-output@v2\n[Test Actions/Test with Java 11]   \xe2\x98\x81  git clone \'https://github.com/actions/setup-node\' # ref=v2\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Pre GuillaumeFalourd/assert-command-line-output@v2\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Main actions/checkout@v3\n[Test Actions/Test with Java 11]     docker cp src=/workspaces/Javadoc-publisher.yml/. dst=/workspaces/Javadoc-publisher.yml\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Main actions/checkout@v3\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Main ./\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Main actions/checkout@v3\n[Test Actions/Test with Java 11]     docker cp src=/workspaces/Javadoc-publisher.yml/. dst=/workspaces/Javadoc-publisher.yml\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Main actions/checkout@v3\n[Test Actions/Test with Java 11]   \xe2\x98\x81  git clone \'https://github.com/actions/setup-java\' # ref=v3\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Main actions/setup-java@v3\n[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/\n[Test Actions/Test with Java 11]     docker exec cmd=[node /var/run/act/actions/actions-setup-java@v3/dist/setup/index.js] user= workdir=\n[Test Actions/Test with Java 11]   \xe2\x9d\x93  ::group::Installed distributions\n| Trying to resolve the latest version from remote\n| Resolved latest version as 11.0.17+8\n| Trying to download...\n| 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 ...\n[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\n[Test Actions/Test with Java 11]     ::debug::Destination /tmp/8533ad34-250e-4794-b6bd-f014648ce8b2\n[Test Actions/Test with Java 11]     ::debug::download complete\n| Extracting Java archive...\n[Test Actions/Test with Java 11]     ::debug::Checking tar --version\n[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.\n| [command]/usr/bin/tar xz --warning=no-unknown-keyword -C /tmp/4f3b749d-13d5-497d-87d7-45e30a9927cc -f /tmp/8533ad34-250e-4794-b6bd-f014648ce8b2\n[Test Actions/Test with Java 11]     ::debug::Caching tool Java_Adopt_jdk 11.0.17-8 x64\n[Test Actions/Test with Java 11]     ::debug::source dir: /tmp/4f3b749d-13d5-497d-87d7-45e30a9927cc/jdk-11.0.17+8\n[Test Actions/Test with Java 11]     ::debug::destination /opt/hostedtoolcache/Java_Adopt_jdk/11.0.17-8/x64\n[Test Actions/Test with Java 11]     ::debug::finished caching tool\n| Java 11.0.17+8 was downloaded\n| Setting Java 11.0.17+8 as the default\n| Creating toolchains.xml for JDK version 11 from adopt\n| Writing to /root/.m2/toolchains.xml\n| \n| Java configuration:\n|   Distribution: adopt\n|   Version: 11.0.17+8\n|   Path: /opt/hostedtoolcache/Java_Adopt_jdk/11.0.17-8/x64\n| \n[Test Actions/Test with Java 11]   \xe2\x9d\x93  ::endgroup::\n[Test Actions/Test with Java 11]   \xe2\x9d\x93  ##[add-matcher]/run/act/actions/actions-setup-java@v3/.github/java.json\n| Creating settings.xml with server-id: github\n| Writing to /root/.m2/settings.xml\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Main actions/setup-java@v3\n[Test Actions/Test with Java 11]   \xe2\x9a\x99  ::set-output:: distribution=Adopt-Hotspot\n[Test Actions/Test with Java 11]   \xe2\x9a\x99  ::set-output:: path=/opt/hostedtoolcache/Java_Adopt_jdk/11.0.17-8/x64\n[Test Actions/Test with Java 11]   \xe2\x9a\x99  ::set-output:: version=11.0.17+8\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Main Generate Javadoc\n[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=\n| /var/run/act/workflow/1-composite-2.sh: line 2: mvn: command not found\n[Test Actions/Test with Java 11]   \xe2\x9d\x8c  Failure - Main Generate Javadoc\n[Test Actions/Test with Java 11] exitcode \'127\': command not found, please refer to https://github.com/nektos/act/issues/107 for more information\n[Test Actions/Test with Java 11]   \xe2\x98\x81  git clone \'https://github.com/JamesIves/github-pages-deploy-action\' # ref=v4.4.0\n[Test Actions/Test with Java 11]   \xe2\x9d\x8c  Failure - Main ./\n[Test Actions/Test with Java 11] exitcode \'127\': command not found, please refer to https://github.com/nektos/act/issues/107 for more information\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Post ./\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Post actions/setup-java@v3\n[Test Actions/Test with Java 11]     docker exec cmd=[node /var/run/act/actions/actions-setup-java@v3/dist/cleanup/index.js] user= workdir=\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Post actions/setup-java@v3\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Post ./\n[Test Actions/Test with Java 11]   Job failed\n\n
Run Code Online (Sandbox Code Playgroud)\n

GitHub 工作流程

\n

我的 GitHub 工作流程:

\n
[Test Actions/Test with Java 11]   Start image=catthehacker/ubuntu:act-latest\n[Test Actions/Test with Java 11]     docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=false\n[Test Actions/Test with Java 11]     docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]\n[Test Actions/Test with Java 11]     docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]\n[Test Actions/Test with Java 11]   \xe2\x98\x81  git clone \'https://github.com/GuillaumeFalourd/assert-command-line-output\' # ref=v2\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Pre GuillaumeFalourd/assert-command-line-output@v2\n[Test Actions/Test with Java 11]   \xe2\x98\x81  git clone \'https://github.com/actions/setup-node\' # ref=v2\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Pre GuillaumeFalourd/assert-command-line-output@v2\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Main actions/checkout@v3\n[Test Actions/Test with Java 11]     docker cp src=/workspaces/Javadoc-publisher.yml/. dst=/workspaces/Javadoc-publisher.yml\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Main actions/checkout@v3\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Main ./\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Main actions/checkout@v3\n[Test Actions/Test with Java 11]     docker cp src=/workspaces/Javadoc-publisher.yml/. dst=/workspaces/Javadoc-publisher.yml\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Main actions/checkout@v3\n[Test Actions/Test with Java 11]   \xe2\x98\x81  git clone \'https://github.com/actions/setup-java\' # ref=v3\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Main actions/setup-java@v3\n[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/\n[Test Actions/Test with Java 11]     docker exec cmd=[node /var/run/act/actions/actions-setup-java@v3/dist/setup/index.js] user= workdir=\n[Test Actions/Test with Java 11]   \xe2\x9d\x93  ::group::Installed distributions\n| Trying to resolve the latest version from remote\n| Resolved latest version as 11.0.17+8\n| Trying to download...\n| 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 ...\n[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\n[Test Actions/Test with Java 11]     ::debug::Destination /tmp/8533ad34-250e-4794-b6bd-f014648ce8b2\n[Test Actions/Test with Java 11]     ::debug::download complete\n| Extracting Java archive...\n[Test Actions/Test with Java 11]     ::debug::Checking tar --version\n[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.\n| [command]/usr/bin/tar xz --warning=no-unknown-keyword -C /tmp/4f3b749d-13d5-497d-87d7-45e30a9927cc -f /tmp/8533ad34-250e-4794-b6bd-f014648ce8b2\n[Test Actions/Test with Java 11]     ::debug::Caching tool Java_Adopt_jdk 11.0.17-8 x64\n[Test Actions/Test with Java 11]     ::debug::source dir: /tmp/4f3b749d-13d5-497d-87d7-45e30a9927cc/jdk-11.0.17+8\n[Test Actions/Test with Java 11]     ::debug::destination /opt/hostedtoolcache/Java_Adopt_jdk/11.0.17-8/x64\n[Test Actions/Test with Java 11]     ::debug::finished caching tool\n| Java 11.0.17+8 was downloaded\n| Setting Java 11.0.17+8 as the default\n| Creating toolchains.xml for JDK version 11 from adopt\n| Writing to /root/.m2/toolchains.xml\n| \n| Java configuration:\n|   Distribution: adopt\n|   Version: 11.0.17+8\n|   Path: /opt/hostedtoolcache/Java_Adopt_jdk/11.0.17-8/x64\n| \n[Test Actions/Test with Java 11]   \xe2\x9d\x93  ::endgroup::\n[Test Actions/Test with Java 11]   \xe2\x9d\x93  ##[add-matcher]/run/act/actions/actions-setup-java@v3/.github/java.json\n| Creating settings.xml with server-id: github\n| Writing to /root/.m2/settings.xml\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Main actions/setup-java@v3\n[Test Actions/Test with Java 11]   \xe2\x9a\x99  ::set-output:: distribution=Adopt-Hotspot\n[Test Actions/Test with Java 11]   \xe2\x9a\x99  ::set-output:: path=/opt/hostedtoolcache/Java_Adopt_jdk/11.0.17-8/x64\n[Test Actions/Test with Java 11]   \xe2\x9a\x99  ::set-output:: version=11.0.17+8\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Main Generate Javadoc\n[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=\n| /var/run/act/workflow/1-composite-2.sh: line 2: mvn: command not found\n[Test Actions/Test with Java 11]   \xe2\x9d\x8c  Failure - Main Generate Javadoc\n[Test Actions/Test with Java 11] exitcode \'127\': command not found, please refer to https://github.com/nektos/act/issues/107 for more information\n[Test Actions/Test with Java 11]   \xe2\x98\x81  git clone \'https://github.com/JamesIves/github-pages-deploy-action\' # ref=v4.4.0\n[Test Actions/Test with Java 11]   \xe2\x9d\x8c  Failure - Main ./\n[Test Actions/Test with Java 11] exitcode \'127\': command not found, please refer to https://github.com/nektos/act/issues/107 for more information\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Post ./\n[Test Actions/Test with Java 11] \xe2\xad\x90 Run Post actions/setup-java@v3\n[Test Actions/Test with Java 11]     docker exec cmd=[node /var/run/act/actions/actions-setup-java@v3/dist/cleanup/index.js] user= workdir=\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Post actions/setup-java@v3\n[Test Actions/Test with Java 11]   \xe2\x9c\x85  Success - Post ./\n[Test Actions/Test with Java 11]   Job failed\n\n
Run Code Online (Sandbox Code Playgroud)\n

GitHub 行动

\n

该项目的 GitHub Action :https://github.com/MathieuSoysal/Javadoc-publisher.yml/blob/main/action.yml

\n

命令

\n

运行 nektos/act 的执行命令:act

\n

问题

\n

mvn: command not found issue有人知道我们如何用nektos/act解决这个问题吗?

\n

Thr*_*ror 7

解释

您的问题是由于您与 nektos/act 一起使用的图像没有 mvn 造成的。

如何修复它

您有几种修复它的可能性。

第一个解决方案

第一个解决方案:如果你想保持自己的形象。
您可以在 GitHub 工作流程中添加以下行来添加 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
####
Run Code Online (Sandbox Code Playgroud)

第二种解决方案

第二种解决方案:如果您同意更改您使用的图像。您可以执行
以下命令,而不是执行命令:act

act -P ubuntu-latest=quay.io/jamezp/act-maven
Run Code Online (Sandbox Code Playgroud)