1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

act/nektosを使ってローカル環境でgithub actions走らせてコケた時の話

Last updated at Posted at 2023-10-07

概要

github actionsをローカル環境で動作確認したい!という理由から、
nektos/act を導入してみた。

どんなworkflowを組みたかったか

github actions のtask内でpythonのスクリプトを実行したい。
ランナーで走らせているUbuntuにpythonをインストールしたい。

構成

ディレクトリ

.
├── .github
│   └── workflows
│       ├── deploy.yaml
│       └── scripts
│           └── main.py

workflows/deploy.yaml

name: Test

on: [push]

jobs:
  test:
    runs-on: ubuntu-20.04
    timeout-minutes: 30

    steps:
      - name: "checkout"
        uses: actions/checkout@v4

      - name: "install python"
        uses: actions/setup-python@v4
        with:
          python-version: "3.9"
        env:
          AGENT_TOOLSDIRECTORY: /opt/hostedtoolcache

      - name: "Run a Python script"
        run: python .github/workflows/scripts/main.py

workflows/scripts/main.py

print("Hello World")

問題発生

$ act push

[Test/test] 🚀  Start image=node:16-buster-slim
[Test/test]   🐳  docker pull image=node:16-buster-slim platform= username= forcePull=true
[Test/test]   🐳  docker create image=node:16-buster-slim platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[]
[Test/test]   🐳  docker run image=node:16-buster-slim platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[]
[Test/test]   ☁  git clone 'https://github.com/actions/setup-python' # ref=v4
[Test/test] ⭐ Run Main checkout
[Test/test]   🐳  docker cp src=/Users/owner/works/**/. dst=/Users/owner/works/**
[Test/test]   ✅  Success - Main checkout
[Test/test] ⭐ Run Main install python
[Test/test]   🐳  docker cp src=/Users/owner/.cache/act/actions-setup-python@v4/ dst=/var/run/act/actions/actions-setup-python@v4/
[Test/test]   🐳  docker exec cmd=[node /var/run/act/actions/actions-setup-python@v4/dist/setup/index.js] user= workdir=
[Test/test]   💬  ::debug::Python is expected to be installed into /opt/hostedtoolcache
[Test/test]   ❓  ::group::Installed versions
[Test/test]   💬  ::debug::Semantic version spec of 3.9 is 3.9
[Test/test]   💬  ::debug::isExplicit: 
[Test/test]   💬  ::debug::explicit? false
[Test/test]   💬  ::debug::evaluating 0 versions
[Test/test]   💬  ::debug::match not found
| Version 3.9 was not found in the local cache
[Test/test]   💬  ::debug::Getting manifest from actions/python-versions@main
[Test/test]   💬  ::debug::check 3.12.0 satisfies 3.9
[Test/test]   💬  ::debug::check 3.12.0-rc.3 satisfies 3.9
[Test/test]   💬  ::debug::check 3.12.0-rc.2 satisfies 3.9
[Test/test]   💬  ::debug::check 3.12.0-rc.1 satisfies 3.9
[Test/test]   💬  ::debug::check 3.12.0-beta.4 satisfies 3.9
[Test/test]   💬  ::debug::check 3.12.0-beta.3 satisfies 3.9
[Test/test]   💬  ::debug::check 3.12.0-beta.2 satisfies 3.9
[Test/test]   💬  ::debug::check 3.12.0-beta.1 satisfies 3.9

〜〜中略〜〜

[Test/test]   💬  ::debug::check 3.6.13 satisfies 3.9
[Test/test]   💬  ::debug::check 3.6.12 satisfies 3.9
[Test/test]   💬  ::debug::check 3.6.11 satisfies 3.9
[Test/test]   💬  ::debug::check 3.6.10 satisfies 3.9
[Test/test]   💬  ::debug::check 3.6.9 satisfies 3.9
[Test/test]   💬  ::debug::check 3.6.8 satisfies 3.9
[Test/test]   💬  ::debug::check 3.6.7 satisfies 3.9
[Test/test]   💬  ::debug::check 3.5.10 satisfies 3.9
[Test/test]   💬  ::debug::check 3.5.9 satisfies 3.9
[Test/test]   💬  ::debug::check 3.5.4 satisfies 3.9
[Test/test]   💬  ::debug::check 3.4.10 satisfies 3.9
[Test/test]   💬  ::debug::check 3.4.4 satisfies 3.9
[Test/test]   💬  ::debug::check 3.3.7 satisfies 3.9
[Test/test]   💬  ::debug::check 3.3.5 satisfies 3.9
[Test/test]   💬  ::debug::check 3.2.5 satisfies 3.9
[Test/test]   💬  ::debug::check 3.1.4 satisfies 3.9
[Test/test]   💬  ::debug::check 3.0.1 satisfies 3.9
[Test/test]   💬  ::debug::Unable to locate executable file: lsb_release. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.
[Test/test]   ❗  ::error::The version '3.9' with architecture 'x64' was not found for this operating system.%0AThe list of all available versions can be found here: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json
[Test/test]   ❌  Failure - Main install python
[Test/test] exitcode '1': failure
[Test/test] 🏁  Job failed

ん、 Version 3.9 was not found in the local cache... python v3.9 not found?
おや、 architecture 'x64' was not found for this operating ... MacBook Pro intelチップに
対応していないのか?んな、馬鹿な。

解決方法

act -P ubuntu-20.04=catthehacker/ubuntu:act-20.04 push

解説

actのランナーがdockerコンテナイメージ node:16-buster-slim だったらしく、
これが原因でエラーになっていた。
github actions をローカル環境で動作させる時のコンテナイメージを catthehacker/ubuntu:act-20.04
変更したらうまくいった。

補足

明示的にコマンドにオプション -P <platform>=<docker-image> を付けて指定しているが、
ここは永続化できる。

$ cat ~/.actrc 
-P ubuntu-latest=node:16-buster-slim
-P ubuntu-22.04=node:16-bullseye-slim
-P ubuntu-20.04=node:16-buster-slim
-P ubuntu-18.04=node:16-buster-slim

この部分をエディタで開いて書き換えればOK

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?