LoginSignup
1
0

More than 1 year has passed since last update.

Organization でプライベートな GitHub Action を作成してみた

Last updated at Posted at 2023-04-03

Organization でプライベートな GitHub Action を試しに作成してみた記録です。

前提

Ubuntu 20.04 に Docker がインストールされている(Zscaler 環境下で作る WSL2(Ubuntu 20.04) + Docker 環境)。

nektos/act のインストール

ローカルでワークフローの try&failure が出来るようにnektos/actを導入しておきます。

各種パッケージマネージャーに対応していますが、apt に対応していないので手動でインストールしました。

# インストール
$ cd ~
$ curl -s https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
nektos/act info checking GitHub for latest tag
nektos/act info found version: 0.2.43 for v0.2.43/Linux/x86_64
nektos/act info installed ./bin/act

Hello GitHub Action

プライベートトリポジトリを準備する

デフォルトではプライベートリポジトリの Action は同一オーナーであっても他のリポジトリから使えないようになっているので、プライベートリポジトリの設定を更新しておきます。

Settings->Actions->General の一番下に Access というセクションがあります。

2023-03-30-08-48-40.png

Accessible from repositories in the '<Organization名>' を選択し、 Save をクリックして設定を保存します。
なお、個人リポジトリの場合はここの文言は Accessible from repositories owned by the user '<ユーザー名>' になります。

最低限のファイルを作成する

Docker コンテナーのアクションを作成するを参考に最低限のファイルを作成します。

  • Dockerfile
  • action.yml
  • entrypoint.sh

また、entrypoint.shには実行権限を付与しておきます。

$ chmod a+x entrypoint.sh

ローカルで動作確認する

  1. ワークフローファイル(.github/workflows/main.yml)を記述する(ポイントは★印を付けている部分です)

    on: [push]
    
    jobs:
    hello_world_job:
        runs-on: ubuntu-latest
        name: A job to say hello
        steps:
       # (★)docker cp src=<local> dst=<container>が行われる
       - name: Checkout
         uses: actions/checkout@v3
         with:
           repository: <ユーザー名>/<リポジトリ名>
        - name: Hello world action step
            id: hello
            uses: ./ # (★)localからコピーされたリソースを元にactionが実行される
            with:
             who-to-greet: 'Mona the Octocat'
        # Use the output from the `hello` step
        - name: Get the output time
            run: echo "The time was ${{ steps.hello.outputs.time }}"
    
  2. シークレットを指定して実行する

    $ act push -s GITHUB_TOKEN=<GITHUB_TOKEN>
    

作成した Action をコミットしてプッシュします

$ git add action.yml entrypoint.sh Dockerfile
$ git update-index --chmod=+x entrypoint.sh
git commit -m "My first action is ready"
git tag -a -m "My first action release" v0.0.1
git push --follow-tags

参考

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