I have a project based on Node/npm and use commitlint, husky and semantic-release. Whenever I push to the protected main
branch I want to create a new release.
In Github I added the following workflow
name: Release on push on main
on:
push:
branches:
- main
jobs:
release-on-push-on-main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 16.x
- name: Install dependencies
run: npm install
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release --branches main
which does the job very well. When moving to the releases I see that semantic-release attaches the source code
Running npm run build
generates me a dist
folder containing all the build files. How can enhance my workflow to add the build to the assets?
Adding the steps
- name: Run build
run: npm run build
- name: Archive build
uses: actions/upload-artifact@v2
with:
name: build
path: dist
before running the Release
step seems to work as expected
but how can I add it as an asset to the release?
CodePudding user response:
You need to configure the semantic-release github-plugin using the configuration file
The CLI uses some default configuration, and if you need a custom config you will have to create an entire config from scratch (as far as I know).
Create a file called release.config.js in the root project folder:
// make sure you install @semantic-release/github as dev dependency
module.exports = {
"plugins": [
// additional config...
["@semantic-release/github", {
"assets": [
{"path": "dist/asset.min.css", "label": "CSS distribution"},
{"path": "dist/asset.min.js", "label": "JS distribution"}
]
}],
]
}
I can also recommend using an alternative to semantic-release called atomic-release. It's an SDK with a strategy to release NPM packages (kind of like semantic-release). Check it out GithubNpmPackageStrategy
Disclaimer: I'm the author of atomic-release.