semantic-release-final
v1.1.0
Published
This is a minimal Node.js Express application with a single controller endpoint. The main purpose of this project is to demonstrate how easily semantic release can be set up using the semantic-release package and a GitHub Actions pipeline.
Downloads
5
Readme
📦 🚀 Semantic release
This is a minimal Node.js Express application with a single controller endpoint. The main purpose of this project is to demonstrate how easily semantic release can be set up using the semantic-release package and a GitHub Actions pipeline.
🛫 Getting Started
Follow these instructions to set up the project and configure semantic release.
Prerequisites
- Node.js and npm installed on your machine.
- A GitHub repository for your project.
Clone the repository to your local machine:
git clone https://github.com/lukasnerdware/semantic-release.git cd semantic-release
Install project dependencies:
npm install
Usage
npm start
Your application will be available at http://localhost:3000.
👨🏼⚖️ Conventional Commits
Enforcing Conventional Commits with Husky and Commitlint
Install Husky to enforce conventional commit messages and commitlint:
npm install --save-dev @commitlint/{config-conventional,cli} npm install --save-dev husky npx husky install npx husky add .husky/commit-msg 'npx --no -- commitlint --edit ${1}'
This will ensure that commit messages follow the conventional commit guideline.
Create a commitlint.config.js file in your project root:
module.exports = { extends: ['@commitlint/config-conventional'] };
📓 Semantic Release Setup
- Install semantic-release and required plugins:
npm install --save-dev semantic-release @semantic-release/changelog @semantic-release/git @semantic-release/github
- Create a release.config.js file in your project root:
module.exports = {
branches: ['main'],
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
'@semantic-release/changelog',
'@semantic-release/npm',
'@semantic-release/github',
'@semantic-release/git',
],
};
- Configure GitHub Actions for semantic release by creating a .github/workflows/release.yml file:
name: Semantic Release
on:
push:
branches:
- main
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 18
- name: Install dependencies
run: npm install
- name: Semantic Release
run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- Commit the changes and push to your GitHub repository.
- Ensure you give the Read and write permissions permision to your github workflow (Settings --> Actions --> General --> Workflow permissions)
- Add NPM_TOKEN as Github Secret
- GO to Settings
- Security --> Secrets and variables --> New Repository secret
- Create NPM_TOKEN secret (requires npm account)
- Now, whenever you merge changes into the main branch, the GitHub Actions pipeline will automatically trigger a semantic release based on your commit messages and versioning rules defined in release.config.js.