Skip to content

Commit

Permalink
feat: add semantic-release (#3)
Browse files Browse the repository at this point in the history
## Context

Currently I am missing some features in `release-it` like: env
variables, branch protection and auto-labels

## Changes

After some extensive research I went with `semantic-releases` because it
supports all these features (and more)

## Checklist

- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] I have made corresponding changes to the documentation
- [x] I have tested my code for breaking changes and added the
corresponding footer in this PR if needed
- [ ] I have added tests that prove my fix is effective or that my
feature works
  • Loading branch information
remcolakens committed Mar 30, 2023
1 parent 5b6a0de commit 3da69a2
Show file tree
Hide file tree
Showing 8 changed files with 750 additions and 1,342 deletions.
32 changes: 4 additions & 28 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ name: release

on:
workflow_dispatch:
inputs:
choice:
type: choice
description: What kind of release do you want to create?
options:
- beta
- prod

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand All @@ -18,34 +11,17 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Check main branch
if: github.event_name == 'workflow_dispatch' && github.ref != 'refs/heads/main'
run: |
echo "This workflow should not be triggered with workflow_dispatch on a branch other than main"
exit 1
- name: Checkout Code
uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.PAT }}
persist-credentials: false

- uses: ./.github/actions/setup

- name: Git config
run: |
git config --global user.name "${GITHUB_ACTOR}"
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
- name: Install
run: pnpm install

- name: Make release
run: |
if [ "${{ github.event.inputs.choice }}" = "beta" ]; then
pnpm release --preRelease=beta
else
pnpm release
fi
- name: Release
run: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
36 changes: 0 additions & 36 deletions .release-it.json

This file was deleted.

94 changes: 94 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"branches": [
"main",
{
"name": "beta",
"channel": "beta",
"prerelease": true
}
],
"plugins": [
"@semantic-release/commit-analyzer",
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "🚀 Features"
},
{
"type": "perf",
"section": "🏎 Performance"
},
{
"type": "fix",
"section": "🐞 Bug Fixes"
},
{
"type": "refactor",
"section": "💅 Refactors"
},
{
"type": "docs",
"section": "📖 Documentation"
},
{
"type": "build",
"section": "📦 Build"
},
{
"type": "types",
"section": "🌊 Types"
},
{
"type": "chore",
"section": "🏡 Chore"
},
{
"type": "examples",
"section": "🏀 Examples"
},
{
"type": "test",
"section": "✅ Tests"
},
{
"type": "style",
"section": "🎨 Styles"
},
{
"type": "ci",
"section": "🤖 CI"
}
]
}
}
],
[
"@semantic-release/changelog",
{
"changelogFile": "docs/CHANGELOG.md"
}
],
[
"@semantic-release/npm",
{
"npmPublish": false
}
],
[
"@semantic-release/git",
{
"message": "v${nextRelease.version}\n\n[skip ci]",
"assets": [
"package.json",
"docs/CHANGELOG.md"
]
}
],
"@semantic-release/github"
]
}
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- Automatically formats your code by using `Prettier`
- JavaScript Testing Framework
- Friendly errors & warnings
- Automated releases with `release-it` and `Github Actions`
- Automated releases with `semantic-release` and `Github Actions`
- Includes Chakra UI to quickly build user-friendly interfaces
- Automatically optimizes all your SVGs

Expand All @@ -35,6 +35,7 @@
│ └── molecules # Molecules (e.g. wrappers, combined atoms)
│ └── organisms # Organisms (e.g. carousels, content blocks)
├── docs # Documentation
│ └── CHANGELOG.md # the changelog
│ └── ci.md # docs for CI
│ └── commit-convention.md # docs for commit convention
├── pages # Pages folder
Expand All @@ -60,7 +61,7 @@
├── .nvmrc # Compatible node version
├── .prettierignore # Files that will be ignored by Prettier (package)
├── .priettierc # Prettier config (package)
├── .release-it.json # release it config
├── .releaserc # semantic-release config
├── commitlint.config.js # commitlint config (package)
├── jest.config.js # Config file for jest
├── jest.setup.js # Used for __tests__/testing-library.js
Expand Down Expand Up @@ -116,6 +117,7 @@ To learn more about Next.js and the other tools, take a look at the following re
- [React Testing Library](https://testing-library.com/docs/) - Simple and complete testing utilities that encourage good
testing practices
- [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) - A specification for adding human and machine readable meaning to commit messages
- [semantic-release](https://github.com/semantic-release/semantic-release) - Fully automated version management and package publishing

## Deploy

Expand All @@ -127,6 +129,7 @@ from the creators of Next.js.

## Documentation

- [CHANGELOG](/docs/CHANGELOG.md) - Changelog with all notable changes made to a project
- [CI](/docs/ci.md) - Short explanation of the continuous integration process
- [Commit Convention](/docs/commit-convention.md) - Short introduction of the commit convention

Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions docs/ci.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Feel free to adjust the workflows to your own requirements, you can find all of
To ensure code quality it's a common practice to create a set of rules that will apply to the `main` branch.
It's highly recommended that you only submit your code by using pull request and never push directly into the `main` branch.

To automate the release process, we will be using the "Github Actions Bot" and it is also affected by these rules.
To automate the release process, we will be using the GitHub bots and they are also affected by these rules.
Below I will describe the workaround, we are going to give the bot administrator privileges so it will be able to bypass all of the rule sets.

- As administrator, create a classic [Personal Access Token](https://github.com/settings/tokens) with "repo" rights
Expand All @@ -18,6 +18,6 @@ Below I will describe the workaround, we are going to give the bot administrator
- Click on: Secrets and variables -> Actions
- Now click on the button: "New repository secret"
- Configure the name as: `PAT`, copy your generated token and set expiration time
- Under Actions -> release, you will see the button: "Run workflow" this will start the release on the CI

Alternatively you can also go with a different strategy where you manually create the release by using `pnpm release` and then submit the code by pull-request.
While using this strategy do not squash your commits otherwise your release commit might get lost.
Alternatively you can also create manually releases by using `pnpm release --no-ci` in this case it will use your local machine git variables and tokens.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"lint": "pnpm lint:typescript && pnpm lint:eslint",
"preinstall": "npx only-allow pnpm",
"prepare": "husky install",
"release": "release-it --ci",
"release": "semantic-release",
"start": "next start",
"test:ci": "jest --ci",
"test": "jest"
Expand All @@ -23,8 +23,9 @@
"@commitlint/cli": "^17.5.1",
"@commitlint/config-conventional": "^17.4.4",
"@commitlint/cz-commitlint": "^17.5.0",
"@release-it/conventional-changelog": "^5.1.1",
"@remcolakens/simple-component-generator": "^1.0.5",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@svgr/cli": "^7.0.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
Expand All @@ -50,7 +51,7 @@
"lint-staged": "^13.2.0",
"prettier": "^2.8.7",
"prettier-plugin-organize-imports": "^3.2.2",
"release-it": "^15.9.3",
"semantic-release": "^21.0.0",
"typescript": "^4.9.5"
},
"dependencies": {
Expand Down
Loading

0 comments on commit 3da69a2

Please sign in to comment.