GitHub Actions とは
ワールドクラスのCI / CDですべてのソフトウェアワークフローを簡単に自動化できます。 GitHubから直接コードをビルド、テスト、デプロイでき、コードレビュー、ブランチ管理、問題のトリアージを希望どおりに機能させます。
環境変数
env(Global)
on:
push:
branches:
- master
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ap-northeast-1
env(Step)
jobs:
Build:
runs-on: ubuntu-latest
steps:
- name: install
run: yarn install
env:
ENVIRONMENT: dev
複数コマンド簡略化
run
jobs:
Build:
runs-on: ubuntu-latest
steps:
- name: install and build
run: |
yarn install
yarn build
サブフォルダの指定
working-directory
jobs:
Build:
runs-on: ubuntu-latest
steps:
- name: deploy
working-directory: build
run: |
yarn deploy
アクションのトリガー条件
指定フォルダ
paths
on:
push:
branches:
- master
paths:
- docker/**
指定フォルダ以外
paths-ignore
on:
push:
branches:
- master
paths-ignore:
- docker/**
複数ジョブの実行順番
needs
jobs:
Build:
runs-on: ubuntu-latest
steps:
- run: xxxxxx
Deploy:
needs:
- Build
runs-on: ubuntu-latest
steps:
- run: xxxxxx
リポジトリ間のワークフロー実行
repository-dispatch(From)
jobs:
Backend:
runs-on: ubuntu-latest
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1.1.0
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
repository: owner/repository
event-type: next
repository-dispatch(To)
on:
repository_dispatch:
types: next
Slack への結果通知
jobs:
Slack:
runs-on: ubuntu-latest
steps:
- name: Slack Notify
uses: rtCamp/action-slack-notify@v2.0.1
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: build
SLACK_TITLE: Build Success
SLACK_COLOR: '#43a047'
SLACK_MESSAGE: ${{ github.repository }} Build Success
SLACK_USERNAME: ${{ github.repository }}
設定用ツール
VSCode で Plugin を追加すれば、より効率的に設定できます。