iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
📌
A Comprehensive Guide to Writing GitHub Actions by Use Case
Since I often run into issues when using GitHub Actions, I'm putting together this memo as a reference.
Setting environment variables
echo ::set-env name=NAME::name
To reuse a current environment variable across steps:
echo ::set-env name=NAME::$(echo NAME)
Running actions when pushing to the master branch
The pushed branch name is contained in github.ref.
- name update production
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
run: ...
Running actions for PRs containing the string "release"
You can use contains to determine if a specific string is included in the branch name.
The following case is used when you want to merge a branch such as release/1.0.0 into master, etc.
- name release
if: contains(github.head_ref, 'release') && github.event_name == 'pull_request'
run: ...
Setting up AWS CLI
- name: Configure AWS credentials from bot account
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }}
aws-region: ap-northeast-1
Automatic tagging based on package.json
- name: package-version-to-git-tag
uses: pkgdeps/action-package-version-to-git-tag@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
github_repo: ${{ github.repository }}
git_commit_sha: ${{ github.sha }}
git_tag_prefix: ""
Discussion