release-github-actions
release-github-actions copied to clipboard
GitHub Actions to automate the release of GitHub Actions
Release GitHub Actions
Read this in other languages: English, 日本語.
This is a GitHub Actions that automates the release of GitHub Actions.
Once you create a new tag, this action will automatically
- Run build
- Create branch for release
- Change tags to release branch
- If there is release which has same tag name and has been published, re-publish it (Because if the tag is changed, the release will be in a draft state).
Table of Contents
Details
- Usage
- CLI Tool
- Screenshot
- Options
- Execute commands
- Build
- Delete files
- Action event details
- Target events
- condition
- Motivation
- Addition
- Tags
- Author
generated with TOC Generator
Usage
e.g. .github/workflows/release.yml
#on:
# push:
# tags:
# - "v*"
on: create
name: Release
jobs:
release:
name: Release GitHub Actions
runs-on: ubuntu-latest
steps:
- uses: technote-space/release-github-actions@v6
More details of target event
CLI Tool
Screenshot

Options
| name | description | default | required | e.g. |
|---|---|---|---|---|
| BUILD_COMMAND | Build command More details of execute command |
yarn build:all |
||
| CLEAN_TARGETS | Files or directories to clean before release (Comma separated) Absolute path and .. are not permitted to use.More details of execute command |
.[!.]*,__tests__,docs,src,*.js,*.ts,*.json,*.lock,*.yml,*.yaml |
true | .[!.]*,*.txt |
| PACKAGE_MANAGER | Package manager to use to install dependencies If there is yarn.lock or package-lock.json, the action automatically determines the package manager to use, but this option can be used to specify it explicitly.( npm or yarn) |
yarn |
||
| COMMIT_MESSAGE | Commit message | feat: build for release |
true | feat: release |
| COMMIT_NAME | Commit name | github-actions[bot] |
true | |
| COMMIT_EMAIL | Commit email | 41898282+github-actions[bot]@users.noreply.github.com |
true | |
| BRANCH_NAME | Branch name for GitHub Actions release |
gh-actions |
true | gh-actions/${MAJOR}/${MINOR}/${PATCH} |
| BUILD_COMMAND_TARGET | Command for search build command | prepare, build, production, prod, package, pack |
compile |
|
| ALLOW_MULTIPLE_BUILD_COMMANDS | Whether to allow run multiple build commands. | true |
false |
|
| CREATE_MAJOR_VERSION_TAG | Whether to create major version tag (e.g. v1) Detail of tags |
true |
false |
|
| CREATE_MINOR_VERSION_TAG | Whether to create minor version tag (e.g. v1.2) Detail of tags |
true |
false |
|
| CREATE_PATCH_VERSION_TAG | Whether to create patch version tag (e.g. v1.2.3) Detail of tags |
true |
false |
|
| FETCH_DEPTH | Limit fetching to the specified number of commits from the tip of each remote branch history | 3 |
5 |
|
| TEST_TAG_PREFIX | Prefix for test tag | test/ |
||
| CLEAN_TEST_TAG | Whether to clean test tag | false |
true |
|
| ORIGINAL_TAG_PREFIX | Prefix to add when leaving the original tag | original/ |
||
| DELETE_NODE_MODULES | Whether to delete node_modules | false |
true |
|
| GITHUB_TOKEN | Access token | ${{github.token}} |
true | ${{secrets.ACCESS_TOKEN}} |
Execute commands
Build
- If package.json includes
prepare,build,production,prod,packageorpackin scripts, the commands are used for build. (You can change this with BUILD_COMMAND_TARGET) - If command does not have install command like
npm run installoryarn install, install commands are added.
so if BUILD_COMMAND is not provided and package.json has build script,
the following commands are executed for build.
yarn install
yarn build
yarn install --production
If build and pack are included, the commands are:
yarn install
yarn build
yarn pack
yarn install --production
Delete files
To execute GitHub Actions, src files used for build, test files, test settings, etc. are not required.
And GitHub Actions is downloaded every time when it is used, so fewer files are better.
CLEAN_TARGETS option is used for this purpose.
default: .[!.]*,__tests__,docs,src,*.js,*.ts,*.json,*.lock,*.yml,*.yaml
rm -rdf .[!.]*
rm -rdf *.js
rm -rdf *.ts
rm -rdf *.json
rm -rdf *.lock
rm -rdf *.yml
rm -rdf *.yaml
rm -rdf __tests__ docs src
(action.yml is not subject to deletion.)
The default setting assumes the use of Action template for TypeScript or Action template for JavaScript.
https://github.com/actions/typescript-action
https://github.com/actions/javascript-action
However, these templates have security issues etc, you must do the following.
Action template for JavaScript
If a pull request includes a built file, it is highly likely that even malicious code will be missed in a review, so you need to fix .gitignore as follows:
.gitignore
+ /dist
Action template for TypeScript
Since processing by ncc is unnecessary, delete the related commands and packages and modify action.yml to use script built with tsc.
action.yml
name: 'Your name here'
description: 'Provide a description here'
author: 'Your name or organization here'
inputs:
myInput: # change this
description: 'input description here'
default: 'default value if applicable'
runs:
using: 'node12'
- main: 'dist/index.js'
+ main: 'lib/main.js'
package.json
"scripts": {
"build": "tsc",
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
- "package": "ncc build --source-map --license licenses.txt",
- "test": "jest",
- "all": "npm run build && npm run format && npm run lint && npm run package && npm test"
+ "test": "jest"
},
"devDependencies": {
"@types/jest": "^26.0.10",
"@types/node": "^14.6.0",
"@typescript-eslint/parser": "^3.10.1",
- "@vercel/ncc": "^0.23.0",
"eslint": "^7.7.0",
"eslint-plugin-github": "^4.1.1",
"eslint-plugin-jest": "^23.20.0",
"jest": "^24.9.0",
"jest-circus": "^26.4.2",
"js-yaml": "^3.14.0",
"prettier": "2.1.1",
"ts-jest": "^24.3.0",
"typescript": "^4.0.2"
}
You can see an example of GitHub Actions with unnecessary files deleted below.
https://github.com/technote-space/release-github-actions/tree/gh-actions
Action event details
Target events
| eventName: action | condition |
|---|---|
| push: * | condition |
| release: published | condition |
| create: * | condition |
condition
- tags
- semantic versioning tag (e.g.
v1.2.3) - test tag (e.g.
test/v1.2.3)
- semantic versioning tag (e.g.
Motivation
Releasing GitHub Actions needs all build files and dependencies like node_modules, but are not usually committed.
So if you want to release GitHub Actions, you have to do following steps.
- Develop locally on the branch for develop
- Build for release
- Commit all source code including dependencies like
node_modulesto branch for release - Add tags (consider major, minor and patch versions)
- Push to GitHub
- Publish release
It is very troublesome to do this steps for every release.
If you use this GitHub Actions, the steps to do are simpler.
- Develop locally on the branch for develop
- Publish release (Create tag)
- Wait for the automated steps to finish
- Build for release
- Commit all source code including dependencies like
node_modulesto branch for release - Add tags (consider major, minor and patch versions)
- Push to GitHub
Addition
Tags
Tag name format must be Semantic Versioning.
The following tags will be created.
- tag name
- major tag name (generated by tag name)
- e.g.
v1
- e.g.
- minor tag name (generated by tag name)
- e.g.
v1.2
- e.g.
- patch tag name (generated by tag name)
- e.g.
v1.2.3
- e.g.