dhythm / github-release-example

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

github-release-example

Prework

Install and run Docker

Go to docker site and get docker. After then, run Docker on your PC.

Install act

act helps developments for GitHub Actions. Run the following command to install act.

brew install act

Get GitHub Token for development

Go to Settings > Developper Settings > Personal access tokens, then generate a new token. The token is used for local debugging, so you have to set expiry and you can delete after debugging.

Generating GitHub access token

Set local environment variables

export GITHUB_TOKEN=<GITHUB_TOKEN>
export BASE_BRANCH=release
export HEAD_BRANCH=main
export OWNER=dhythm
export REPO=github-release-example
export TEMPLATE=.github/git-pr-release.template
export LABELS=release

You can check environment variables by printenv.

Create manifest.json and config for release-please

Run the following command, then release-please will make a PR to add both initial manifest and config.

npx release-please bootstrap --token=<GITHUB_TOKEN> --repo-url=dhythm/github-release-example --release-type=node

Development

Debug scripts

Run the following command.

node .github/src/create_release_pr.js

Debug GitHub Actions

Run the following command.

act --list --container-architecture linux/amd64
act --secret GITHUB_TOKEN=<GITHUB_TOKEN> -j release_pr --container-architecture linux/amd64

The default docker image in act doesn't have GitHub CLI (gh command). We can use another image as ubuntu-latest to simulate GitHub Actions with gh command like the below.

act --secret GITHUB_TOKEN=<GITHUB_TOKEN> -j update-release-pr --container-architecture linux/amd64 -P ubuntu-latest=catthehacker/ubuntu:full-latest

I recommend to run the command below first, after then run the command the above. Because the docker image is super big. (about 53GB)

docker pull catthehacker/ubuntu:full-latest 

Getting started

Settings

You have to update Settings > Actions > General > Workflow permissions.

Workflow permissions

Create a merge PR with template

You can run the workflow in Actions > Create a release pull-request as the following,

Run workflow with plain action

Create a release PR with release-please

You can run the workflow Create a release pull-request via release-please-cli as below,

Run workflow with release-please

A release PR will be created. github-release will work after the PR is merged. A release PR is updated if new commit(s) is pushed into main branch before the release-pr is merged.

Release with a specific version

The official doc doesn't explain but release-please CLI supports --release-as option. See code.

You can pass a specific version from GitHub Actions workflow.

Troubleshooting

You can run forcibly github release via the following command,

npx release-please github-release --token=<GITHUB_TOKEN> --repo-url=dhythm/github-release-example

You can fix the last release SHA to add "last-release-sha": "xxxxxxx" to release-please-config.json.

References

About