I am trying to integrate semantic-release
into my Node CI/CD workflow. I have tried following the documentation and tutorials but I am clearly missing something. The testing step passes, but the publish step fails at "Run npx semantic release".
This is the YML script I am using:
name: Test and Release CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [16.x]
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm test
publish:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@v3
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: "16.x"
- run: npm ci
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Here is the error from the Github action:
Run npx semantic-release
[5:46:35 PM] [semantic-release] › ℹ Running semantic-release version 19.0.2
[5:46:35 PM] [semantic-release] › ✔ Loaded plugin "verifyConditions" from "@semantic-release/npm"
[5:46:35 PM] [semantic-release] › ✔ Loaded plugin "verifyConditions" from "@semantic-release/github"
[5:46:35 PM] [semantic-release] › ✔ Loaded plugin "analyzeCommits" from "@semantic-release/commit-analyzer"
[5:46:35 PM] [semantic-release] › ✔ Loaded plugin "generateNotes" from "@semantic-release/release-notes-generator"
[5:46:35 PM] [semantic-release] › ✔ Loaded plugin "prepare" from "@semantic-release/npm"
[5:46:35 PM] [semantic-release] › ✔ Loaded plugin "publish" from "@semantic-release/npm"
[5:46:35 PM] [semantic-release] › ✔ Loaded plugin "publish" from "@semantic-release/github"
[5:46:35 PM] [semantic-release] › ✔ Loaded plugin "addChannel" from "@semantic-release/npm"
[5:46:35 PM] [semantic-release] › ✔ Loaded plugin "addChannel" from "@semantic-release/github"
[5:46:35 PM] [semantic-release] › ✔ Loaded plugin "success" from "@semantic-release/github"
[5:46:35 PM] [semantic-release] › ✔ Loaded plugin "fail" from "@semantic-release/github"
[5:46:36 PM] [semantic-release] › ℹ Start step "fail" of plugin "@semantic-release/github"
[5:46:36 PM] [semantic-release] [@semantic-release/github] › ℹ Verify GitHub authentication (https://api.github.com)
[5:46:36 PM] [semantic-release] › ✖ Failed step "fail" of plugin "@semantic-release/github"
[5:46:36 PM] [semantic-release] › ✖ An error occurred while running semantic-release: TypeError: Cannot read properties of undefined (reading 'name')
at module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/@semantic-release/github/lib/get-fail-comment.js:19:10)
at module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/@semantic-release/github/lib/fail.js:28:74)
at async fail (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/@semantic-release/github/index.js:64:3)
at async validator (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/plugins/normalize.js:34:24)
at async /home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/plugins/pipeline.js:37:34
at async /home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/plugins/pipeline.js:31:3
at async Object.pluginsConf.<computed> [as fail] (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/plugins/index.js:80:11)
at async callFail (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:243:7)
at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:272:7)
at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/cli.js:55:5) {
pluginName: '@semantic-release/github'
}
[5:46:36 PM] [semantic-release] › ✖ ERELEASEBRANCHES The release branches are invalid in the `branches` configuration.
A minimum of 1 and a maximum of 3 release branches are required in the branches configuration (https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#branches).
This may occur if your repository does not have a release branch, such as master.
Your configuration for the problematic branches is [].
AggregateError:
SemanticReleaseError: The release branches are invalid in the `branches` configuration.
at module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/get-error.js:6:10)
at /home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/branches/index.js:44:19
at Array.reduce (<anonymous>)
at module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/branches/index.js:34:46)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async run (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:65:22)
at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:268:22)
at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/cli.js:55:5)
at module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/lib/branches/index.js:66:11)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async run (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:65:22)
at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/index.js:268:22)
at async module.exports (/home/runner/work/Alphanumeric-Encoder/Alphanumeric-Encoder/node_modules/semantic-release/cli.js:55:5)
Error: Process completed with exit code 1.
I have successfully published using the NPM_TOKEN
from this project during other troubleshooting, so I know that isn't the problem. I believe the issue might be with the GitHub authentication token, but for the life of me I'm stumped. I have no idea what I am doing wrong. How do I correct this error?
EDIT - Related: semantic release - TypeError: Cannot read property 'name' of undefined
CodePudding user response:
Default config assumes branch master
, so if you're using main
you'll get that ERELEASEBRANCHES
error.
You can try setting the .releaserc.js
file (or the release
property in package.json
) with that branch instead.
"branches": ["main", "next"]
Docs for the config are at https://semantic-release.gitbook.io/semantic-release/usage/configuration
There's a PR for adding main as a fallback default branch, but it's not merged yet.