Home

Awesome

github-actions-practice

Github Actions Table

1. pull_request

GitHub ActionsTriggerDescription
actionlintpull_requestactionlint lint for GitHub Actions workflows
artifactpull_requestUpload github-sha.txt to artifact. Wanted to download if exists but not worked -> commented out.
auto-approvepull_requestIf change is under automatic-approval, any PR will be automatically approved.
auto-assignpull_requestSet PR author to the assignee when a PR is created.
auto-mergepull_requestIf change is under automatic-merge, any PR will be automatically merged.
auto-release-when-pr-is-mergedpull_requestIf a PR is merged, create a draft release (publish a release if there's release label) and leave a comment on the PR.
conditional-auto-approvepull_requestIf PR's changed files and changes match AUTO_APPROVE_ALLOWED_REGEX and AUTO_APPROVE_FILE_PATH_REGEX respectively, the pr will be automatically merged.
check-actions-namepull_requestCheck actions file name and the name in yaml file are same.
contextpull_requestEcho GitHub context toJson(github) for checking.
default-commandspull_requestCheck default commands (e.g. zip, aws, jq, yq)
docker-layer-cachepull_requestUse satackey/action-docker-layer-caching.
envvarpull_requestHow to set env var and use it.
keep-only-one-comment-on-prpull_requestCreate a comment if not exist. Otherwise, update the existing comment.
labelerpull_requestAdd label to a pr based on the title.
poetry-cachepull_requestcache poetry and python dependencies managed by poetry.
pre-commitpull_requestRun pre-commit.
s3-localpull_requestUse minio for s3 mock in GitHub Actions. This workflow is broken❌.
terrraform-fmtpull_requestRun terraform fmt for **.tf.
changed-filespull_requestdo sth for changed files/dir using https://github.com/tj-actions/changed-files

2. release

GitHub ActionsTriggerDescription
auto-prreleaseWhen a release is published from main branch, update a kubernetes yaml file in another repository nakamasato/k8s-deploy-test and create a pr in the repository.
prereleasedreleaseWhen release is prereleased from main branch, echo "prereleased".
releasedreleaseIf a release is published from main branch, echo the release version
release-with-environmentreleaseIf a release is published from main branch, the workflow needs to be reviewed.
k8s-cireleaseBuild docker image, push it to Github Packages, and update manifest file.

3. push

GitHub ActionsTriggerDescription
branch-and-tagpushIf change is pushed to merge branch or tagged as v1.*, the branch will be merged to main branch. disabled due to branch protection in #1348
pip-cachepushUse actions/cache for caching ~/.cache/pip
pip-no-cachepushFor comparison with pip-cache
python-semantic-releasepush❌ not compatible with branch protection ref

4. schedule

GitHub ActionsTriggerDescription
schedulescheduleEcho "test" at 00:00 every Monday.
create-pr-if-outdatedschedulecreate a pr when last update in readme is outdated

5. workflow_dispatch

GitHub ActionsTriggerDescription
workflow-dispatchworkflow_dispatchYou can run this workflow from here

6. workflow_call

GitHub ActionsTriggerDescription
print-workflow-dispatch-inputsworkflow_callYou can reuse this workflow to print inputs of workflow_dispatch (inputs: environment & logLevel)

6. Matrix

  1. env cannot be used for matrix.
  2. The matrix value cannot be used in if for its job.
  3. fromJson is often used to generate matrix (ref: https://docs.github.com/en/actions/learn-github-actions/expressions)
GitHub ActionsTriggerDescription
matrix-from-previous-job-outputpull_requestmatrix execution from the output of the previous step. fromJson
matrix-from-previous-job-output-2pull_request, pushmatrix execution from the output of the previous step. fromJson
matrix-from-previous-job-output-3pull_request, pushdo something for both prod and dev for push event and do sth only for dev for pull_request event
matrix-by-conditionpull_request, pushrun for dev and prod when merged to main. run only for dev for pull_request.

CheatSheet