An Interest In:
Web News this Week
- April 29, 2024
- April 28, 2024
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
How to setup semantic release with GitHub Actions.
Recently, My coworker is using Nx to automate his workflow, including automated release using semantic version. I found this method quite useful, so I want to re-implement on single GitHub repositories (without Nx).
First Step: Create GitHub's Personal Access Token
You can follow this link on how to create Personal Access Token.
You can choose Fine-grained tokens as you can scope specific repositories. (Or Token (Classic))
Make sure that you grant repository permission to token. For my configuration I use:
Read Access
- variables
- environments
- metadata (default)
- secrets
Read/Write Access
- code
- commit statuses
- issue
- pull requests
- workflows
I might grant unnecessary permission, so feel free to correct me.
Second Step: Setup GitHub token in repository's environment
2.Select Environments
3.Create Environment
4.Create Environment Secret
I use
GH_TOKEN
to representGITHUB_TOKEN
(GitHub not allows naming variables with prefix "GITHUB").
Third Step: Setup workflows
I use this package -> Action for Semantic Release to setup my workflow.
Use this script to create workflow
name: teston: push: branches: # Change this if your primary branch is not main - master - devjobs: main: runs-on: ubuntu-latest environment: name: Semver #your environment name steps: - name: Checkout uses: actions/checkout@v4 with: persist-credentials: false - name: Semantic Release uses: cycjimmy/semantic-release-action@v4 env: GH_TOKEN: ${{ secrets.GH_TOKEN }}
In this code snippets, it's meant to
- setup environment
- perform semantic release
Fourth Step: Create .releaserc
This will be semantic-release
configuration file for
- create release tag
- create change log
- define commit message convention -> conventionalcommits
Create .releaserc
in your project.
{ "branches": [ "master", "dev" ], "plugins": [ "@semantic-release/commit-analyzer", "@semantic-release/release-notes-generator", [ "@semantic-release/changelog", { "changelogFile": "CHANGELOG.md" } ], [ "@semantic-release/git", { "assets": [ "CHANGELOG.md" ] } ], "@semantic-release/github" ]}
Final Step: Add, Commit and Push
This step will be the byproduct of your work so far.
Once you commit your code with message convention, for example, feat: add some features
, it will trigger the semantic-release
. Default convention message with angular
preset included:
fix
-> bug fixes: patch releasefeat
-> feature: minor releasebreaking change
-> break change: major release
Once you push your code it will run GitHub Action and release your project.
Then it will create Release
and CHANGELOG.md
in the project.
Conclusion
semantic-release
can help you automate your versioning and release and really useful tracking and document change.
Feel free to comment or give feedbacks. I'm appreciate your time for reading .
Reference
https://www.conventionalcommits.org/en/v1.0.0/
https://github.com/marketplace/actions/action-for-semantic-release
Or my sample repository -> https://github.com/Sahanon-P/semver-sample
Original Link: https://dev.to/sahanonp/how-to-setup-semantic-release-with-github-actions-31f3
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To