GitHub Actions
The following config declares the release action that run on all branches. The job will either release:
- a new
latestversion frombaseBranch - a
canarybuild from a pull request (only on the main fork and if your package manager plugin implements them)
.github/workflows/release.yml
⚠️ You must use some sort of action that implements
skip cifunctionality (as seen below). Otherwise you will get stuck in a release loop!
name: Release on: [push] jobs: release: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')" steps: - uses: actions/checkout@v2 - name: Prepare repository run: git fetch --unshallow --tags - name: Use Node.js 12.x uses: actions/setup-node@v1 with: node-version: 12.x - name: Cache node modules uses: actions/cache@v1 with: path: node_modules key: yarn-deps-${{ hashFiles('yarn.lock') }} restore-keys: | yarn-deps-${{ hashFiles('yarn.lock') }} - name: Create Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | yarn install --frozen-lockfile yarn build npx auto shipitname: Release on: [push] jobs: release: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')" steps: - uses: actions/checkout@v2 - name: Prepare repository run: git fetch --unshallow --tags - name: Use Node.js 12.x uses: actions/setup-node@v1 with: node-version: 12.x - name: Cache node modules uses: actions/cache@v1 with: path: node_modules key: yarn-deps-${{ hashFiles('yarn.lock') }} restore-keys: | yarn-deps-${{ hashFiles('yarn.lock') }} - name: Create Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | yarn install --frozen-lockfile yarn build npx auto shipit
NPM: Github Package Registry
If you are publishing to the Github Package Registry you will need to change a few things.
- Modify the node action to use the Github Package Registry and your user scope.
- name: Use Node.js 12.x uses: actions/setup-node@v1 with: node-version: 12.x registry-url: "https://npm.pkg.github.com" scope: "@your-username-scope"- name: Use Node.js 12.x uses: actions/setup-node@v1 with: node-version: 12.x registry-url: "https://npm.pkg.github.com" scope: "@your-username-scope"
- Use the
GITHUB_TOKENas theNODE_AUTH_TOKENto publish to the Github Package Registry.
- name: Create Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | yarn install --frozen-lockfile yarn build npx auto shipit- name: Create Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | yarn install --frozen-lockfile yarn build npx auto shipit
The NODE_AUTH_TOKEN variable is required for the .npmrc that actions/setup-node@v1 sets up.
If you aren't using actions/setup-node@v1 replace the variable name NODE_AUTH_TOKEN with NPM_TOKEN and the .npmrc auto will handle authentication instead.
Troubleshooting
If you are having problems make sure you have done the following:
- Any required secrets for plugins are set (e.g.
NPM_TOKENwith the NPM plugin) - Update references of
<your-github-user>,<project-owner>, and<project-repo>with the appropriate values
Running With Branch Protection
GitHub actions require a little more setup to use auto with branch protection.
We can't use the GITHUB_TOKEN to commit to the branch because it does not have high enough permissions.
You will need to create a token with admin access to your repo and modify your build config like the following:
steps: - uses: actions/checkout@v2 with: # Ensure that git uses your token with admin access to the repo token: ${{ secrets.ADMIN_TOKEN }} - name: Prepare repository # Fetch full git history and tags run: git fetch --unshallow --tagssteps: - uses: actions/checkout@v2 with: # Ensure that git uses your token with admin access to the repo token: ${{ secrets.ADMIN_TOKEN }} - name: Prepare repository # Fetch full git history and tags run: git fetch --unshallow --tags