Open6
github actions certification
Ref
Details
-
What is GitHub Actions?
- GitHub Actions are packaged scripts to automate tasks in a software-development workflow in GitHub.
-
Where can you find GitHub Actions?
-
Types of GitHub actions
- There are three types of GitHub actions: container actions, JavaScript actions, and composite actions.
-
What is a GitHub Actions workflow?
- A GitHub Actions workflow is a process that you set up in your repository to automate software-development lifecycle tasks, including GitHub Actions.
- With a workflow, you can build, test, package, release, and deploy any project on GitHub.
- An event will trigger on all activity types for the event unless you specify the type or types.
- A workflow must have at least one job. A job is a section of the workflow associated with a runner.
- Each job will have steps to complete.
構造
- workflow
- job
- step
- action
- step
- job
- 例:workflow
name: A workflow for my Hello World file
on: push
jobs:
build:
name: Hello world action
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./action-a
with:
MY_NAME: "Mona"
-
※
build
は job id となり、名前は任意。他のジョブから参照できる -
例:Action(container action to run containerized code)
name: "Hello Actions"
description: "Greet someone"
author: "octocat@github.com"
inputs:
MY_NAME:
description: "Who to greet"
required: true
default: "World"
runs:
uses: "docker"
image: "Dockerfile"
branding:
icon: "mic"
color: "purple"
components
- Workflows
- A workflow is an automated process that you add to your repository. A workflow needs to have at least one job, and different events can trigger it.
- Jobs
- The job is the first major component within the workflow. A job is a section of the workflow that will be associated with a runner. (A job is a set of steps in a workflow that execute on the same runner)
- You'll specify the runner with the runs-on: attribute.
- Steps
- A step is an individual task that can run commands in a job.
- Steps are executed in order and are dependent on each other.
- Start with
-
, can be- uses: *
/- if: *
/- run: *
/- name: *
- Actions
- The actions inside your workflow are the standalone commands that are executed.
- These standalone commands can reference GitHub actions
- such as using your own custom actions
- or community actions like the one we use in the preceding example, actions/checkout@v2.
- You can also run commands such as run: npm install -g bats to execute a command on the runner.
- These standalone commands can reference GitHub actions
- The actions inside your workflow are the standalone commands that are executed.
Configure a GitHub Actions workflow
- cheduled events
-
manual events
- workflow_dispatch
- repository_dispatch
- webhook events
- check_run etc.
- Use conditional keywords
- ${{ <expression> }}
- as in the case of the if conditional, you can omit the expression syntax.
- Use specific versions of an action
steps:
# Reference a specific commit
- uses: actions/setup-node@c46424eee26de4078d34105d3de3cc4992202b1e
# Reference the major version of a release
- uses: actions/setup-node@v1
# Reference a minor version of a release
- uses: actions/setup-node@v1.2
# Reference a branch
- uses: actions/setup-node@main
Exercise
Create a basic container action
- sample code
name: Post welcome comment
on:
pull_request:
types: [opened, reopened]
permissions:
pull-requests: write
jobs:
build:
name: Post welcome comment
runs-on: ubuntu-latest
steps:
- run: |
gh pr comment $PR_URL --body "Welcome to the repository!"
echo "PR_URL: $PR_URL"
echo "PR_NUMBER: $PR_NUMBER"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ github.event.pull_request.html_url }}
PR_NUMBER: ${{ github.event.number }}
- github link
感想
- トリガーじゃない(サンプル pull_request: types: [opened, reopened])と、steps で実行するコマンドで環境変数の所で使う event のデータが正しく取れない(当たり前)
- echo でデバッグできる。環境変数や event のデータをログに出力できるから
- PR の reopened event は PR をクローズして再 open する場合に発行する event である。
- draft から open する場合は発行されない
- GitHub CLI を使う場合に
GH_TOKEN
環境変数を設定する必要がある-
For each step that uses GitHub CLI, you must set an environment variable called GH_TOKEN to a token with the required scopes.
-