Learning GitHub Actions for DevOps CI/CD視聴メモ
Chapter 1 : Introduction to the GitHub Action Workflows
Overview of GitHub Action Workflow
Exploring Workflow Components – Events

Github Action Workflow Directory: .github/workflows
eventとは例えば、誰かがプルリクエストを作成したりリクエストを作成したり、課題をオープンしたり、リポジトリにコミットをプッシュしたりしたときに発生する。
また、スケジュール、REST APIへの投稿、または手動でワークフローの実行をトリガーすることもでる。
ドキュメントリファレンス
Exploring Workflow Components – Job, Step, and Runner
ジョブは同じランナー上で実行されるワークフロー内のステップのセットである。各ステップは実行されるスクリプトまたは実行されるアクションである。ステップは順番に実行され、互いに依存し合う。各ステップは同じランナーマシン上で実行されるため、ステップ間でデータを転送することができます。例えば、アプリケーションをビルドするステップに続いて、前のステップでビルドされたアプリケーションをテストするステップを持つことができます。デフォルトでは、ジョブは依存関係を持たず、互いに並行して実行されますが、他のジョブとの依存関係を設定することができます。
Running the Workflow and Reading the Logs
workflow_dispatchの補足
workflow_dispatchイベントトリガーを使用するためには、ワークフローが最初にメインブランチ(デフォルトブランチ)にコミットされている必要があります。そうでなければ、このオプションは使用できません。ワークフローがメインブランチまたはデフォルトブランチにコミットされると、そのワークフローをフィーチャーブランチから使用し、実行することが可能になる。しかし、ワークフローがメインブランチにコミットされていなければ、このオプションは表示されない。
Lessons Learned
✘ How to create a workflow
✘ Event Trigger
✘ Job
✘ Step
✘ Runner
✘ How to run a workflow
✘ View Workflow run logs
Chapter 2 : GitHub Actions: Exploring the Features
Environment Variables
変数定義
Default GitHub Variables
デフォルトで設定されているenvを確認するサンプル
GitHub Actions Store Your Secrets and Passwords Securely
Setting -> Secrets / Actions

GitHub_Artifacts
アーティファクトにより、ジョブ完了後のデータを永続化し、同じワークフロー内の別のジョブとデータを共有することができます。アーティファクトとは、ワークフロー実行中に生成されるファイルまたはファイルのコレクションです。
例えば以下の様のものが挙げられる
- Log files and core dumps
- Test results, failures, and screenshots
- Binary or compressed files
- Stress test performance output and code coverage results
GitHub Environments | How to Add Manual Approvals
環境ごとのシークレット変数を設定することができる
また承認フローも設定できる
参考
Sharing Values Between Steps and Jobs in a Workflow
Step間で値の受け渡し
Job間で値の受け渡し
Chapter 3 : GitHub Runners
What Is a GitHub Runner
Adding a Self-Hosted Runner
Running Jobs on Self-Hosted Runner
Chapter 4 : GitHub Actions for Infrastructure Deployment
Azureを使った例を紹介。Azureを使う予定はないので流し見。
Understanding the Need of Infrastructure as Code
Developing IAC Template with Bicep to Deploy Infrastructure - Part 1
Developing IAC Template with Bicep to Deploy Infrastructure - Part 2
Setting Up Authentication
Developing GitHub Actions Workflow for Infra Deployment – Part 1
Developing GitHub Actions Workflow for Infra Deployment – Part 2
Chapter 5 : Continuous Integration and Continuous Deployment
2つの環境(ここでは便宜上devとprodという言葉を使用)にデプロイすることを想定したサンプルを紹介
Chapter 6 : Building, Pushing, and Deploying Docker Containers
dockerコマンドを使う準備
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
コンテナレジストリサービスへのログイン
uses: docker/login-action@v1.10.0
with:
registry: demo010.azurecr.io
username: demo010
password: sHidiT36xMp7b+T2No6TBOC6j7wZKlm3
githubレポジトリ名が大文字が含んでいるとエラーが起こったそうなのでその回避とのこと(Azure特有のものかも)
- name: Lowercase the repo name and username
run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}
docker imageをコンテナレジストリにpush
- name: Build and push container image to registry
uses: docker/build-push-action@v2
with:
push: true
tags: demo010.azurecr.io/${{ env.REPO }}:${{ github.sha }}
file: ./WebApplication02/Dockerfile