「Git/github/actions」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→WIPのときに実行しないように) |
|||
(同じ利用者による、間の7版が非表示) | |||
行12: | 行12: | ||
</pre> | </pre> | ||
公式:https://docs.github.com/ja/github/setting-up-and-managing-billing-and-payments-on-github/about-billing-for-github-actions# | 公式:https://docs.github.com/ja/github/setting-up-and-managing-billing-and-payments-on-github/about-billing-for-github-actions# | ||
+ | |||
+ | ==action種類== | ||
+ | *githubホスティング | ||
+ | *self-hosted runner | ||
+ | |||
+ | self-hosted runnerはローカル端末で動作させるもの | ||
+ | |||
+ | ==self-hosted runnerで動作== | ||
+ | ===downloadとinstall=== | ||
+ | Download | ||
+ | <pre> | ||
+ | # Create a folder | ||
+ | $ mkdir actions-runner && cd actions-runner # Download the latest runner package | ||
+ | $ curl -O -L https://github.com/actions/runner/releases/download/v2.277.1/actions-runner-osx-x64-2.277.1.tar.gz # Extract the installer | ||
+ | $ tar xzf ./actions-runner-osx-x64-2.277.1.tar.gz | ||
+ | </pre> | ||
+ | Configure | ||
+ | <pre> | ||
+ | # Create the runner and start the configuration experience | ||
+ | $ ./config.sh --url https://github.com/[user1]/helloworld --token [tokenxxxxxxxxxxxxxxxxxxxxxxxxxxx] # Last step, run it! | ||
+ | $ ./run.sh | ||
+ | </pre> | ||
+ | [user]と[token]は適宜変更する | ||
==有効無効== | ==有効無効== | ||
行18: | 行41: | ||
公式参考:https://docs.github.com/ja/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository | 公式参考:https://docs.github.com/ja/github/administering-a-repository/disabling-or-limiting-github-actions-for-a-repository | ||
− | == | + | ==設定ファイル例== |
.github/workflows/hogehoge.yml | .github/workflows/hogehoge.yml | ||
+ | |||
+ | <pre> | ||
+ | name: hoge CI | ||
+ | |||
+ | on: | ||
+ | push: | ||
+ | branches: [ develop, master ] | ||
+ | pull_request: | ||
+ | branches: [ develop, master ] | ||
+ | |||
+ | jobs: | ||
+ | build: | ||
+ | |||
+ | runs-on: self-hosted | ||
+ | timeout-minutes: 120 # 全体 | ||
+ | if: "contains(join(github.event.pull_request.labels.*.name), 'WIP')" | ||
+ | steps: | ||
+ | - uses: actions/checkout@v2 | ||
+ | </pre> | ||
+ | |||
+ | WIP以外のラベルがついてれば、checkoutだけする | ||
+ | |||
+ | ==github-actionの種類の設定方法== | ||
+ | hostingの場合(ubuntu-latest) | ||
+ | <pre> | ||
+ | jobs: | ||
+ | build: | ||
+ | runs-on: ubuntu-latest | ||
+ | </pre> | ||
+ | |||
+ | self-hostedの場合(mac) | ||
+ | <pre> | ||
+ | jobs: | ||
+ | build: | ||
+ | runs-on: self-hosted | ||
+ | </pre> | ||
==タイムアウト設定== | ==タイムアウト設定== | ||
行36: | 行95: | ||
==WIPのときに実行しないように== | ==WIPのときに実行しないように== | ||
+ | WIPラベルがあるときは、実行しない。 | ||
+ | runs-onの下あたりに追加。 | ||
+ | <pre> | ||
+ | runs-on: self-hosted | ||
+ | if: "contains(join(github.event.pull_request.labels.*.name), 'WIP') == false" | ||
+ | </pre> | ||
参考:https://qiita.com/hkusu/items/10ac4e3579b921f68b6a | 参考:https://qiita.com/hkusu/items/10ac4e3579b921f68b6a | ||
参考:https://qiita.com/HeRo/items/935d5e268208d411ab5a | 参考:https://qiita.com/HeRo/items/935d5e268208d411ab5a |
2021年3月11日 (木) 13:20時点における最新版
目次
github_actionとは
pull_requestやpushしたときに、実行する処理
利用できるプラン
利用時間(分)
GitHub Free 500 MB 2,000 GitHub Pro 1 GB 3,000 Organization の GitHub Free 500 MB 2,000 GitHub Team 2 GB 3,000 GitHub Enterprise Cloud 50 GB 50,000
action種類
- githubホスティング
- self-hosted runner
self-hosted runnerはローカル端末で動作させるもの
self-hosted runnerで動作
downloadとinstall
Download
# Create a folder $ mkdir actions-runner && cd actions-runner # Download the latest runner package $ curl -O -L https://github.com/actions/runner/releases/download/v2.277.1/actions-runner-osx-x64-2.277.1.tar.gz # Extract the installer $ tar xzf ./actions-runner-osx-x64-2.277.1.tar.gz
Configure
# Create the runner and start the configuration experience $ ./config.sh --url https://github.com/[user1]/helloworld --token [tokenxxxxxxxxxxxxxxxxxxxxxxxxxxx] # Last step, run it! $ ./run.sh
[user]と[token]は適宜変更する
有効無効
githubのプロジェクトのsettingsからactionsを選択し、有効無効を選択。
設定ファイル例
.github/workflows/hogehoge.yml
name: hoge CI on: push: branches: [ develop, master ] pull_request: branches: [ develop, master ] jobs: build: runs-on: self-hosted timeout-minutes: 120 # 全体 if: "contains(join(github.event.pull_request.labels.*.name), 'WIP')" steps: - uses: actions/checkout@v2
WIP以外のラベルがついてれば、checkoutだけする
github-actionの種類の設定方法
hostingの場合(ubuntu-latest)
jobs: build: runs-on: ubuntu-latest
self-hostedの場合(mac)
jobs: build: runs-on: self-hosted
タイムアウト設定
timeout-minutesで設定できる。
jobs: my-job: runs-on: ubuntu-latest timeout-minutes: 120 # 全体 steps: - run: sleep 500 timeout-minutes: 80 # 個別
参考:https://dev.classmethod.jp/articles/must-set-timeout-on-actions-for-save-cost/
WIPのときに実行しないように
WIPラベルがあるときは、実行しない。
runs-onの下あたりに追加。
runs-on: self-hosted if: "contains(join(github.event.pull_request.labels.*.name), 'WIP') == false"