Skip to content

Commit

Permalink
ci(release): use conventionalcommits preset for release (#380)
Browse files Browse the repository at this point in the history
Closes #354, closes #356
  • Loading branch information
mcous authored Jun 9, 2024
1 parent 326fb58 commit ee1c966
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
24 changes: 7 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,23 @@ jobs:
needs: main
runs-on: ubuntu-latest
if: ${{ github.repository == 'testing-library/svelte-testing-library' &&
contains('refs/heads/main,refs/heads/beta,refs/heads/next,refs/heads/alpha',
github.ref) && github.event_name == 'push' }}
contains('refs/heads/main,refs/heads/next', github.ref) &&
github.event_name == 'push' }}
steps:
- name: ⬇️ Checkout repo
uses: actions/checkout@v4

- name: ⎔ Setup node
uses: actions/setup-node@v4
with:
node-version: 16

- name: 📥 Download deps
run: npm install --no-package-lock
node-version: 20

- name: 🚀 Release
uses: cycjimmy/semantic-release-action@v2
uses: cycjimmy/semantic-release-action@v4
with:
semantic_version: 17
branches: |
[
'+([0-9])?(.{+([0-9]),x}).x',
'main',
'next',
'next-major',
{name: 'beta', prerelease: true},
{name: 'alpha', prerelease: true}
]
semantic_version: 24
extra_plugins: |
conventional-changelog-conventionalcommits@8
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
15 changes: 14 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,23 @@

## Release

The module is released automatically from the `main` branch using [semantic-release-action][]. Version bumps and change logs are generated from the commit messages.
The module is released automatically from the `main` and `next` branches using [semantic-release-action][]. Version bumps and change logs are generated from the commit messages.

[semantic-release-action]: https://github.com/cycjimmy/semantic-release-action

### Preview release

If you would like to preview the release from a given branch, and...

- You have push access to the repository
- The branch exists in GitHub

...you can preview the next release version and changelog using:

```shell
npm run preview-release
```

## Development setup

After cloning the repository, install the project's dependencies and run the `validate` script to run all checks and tests to verify your setup.
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@
"test:vitest:happy-dom": "vitest run --coverage --environment happy-dom",
"test:jest": "npx --node-options=\"--experimental-vm-modules --no-warnings\" jest --coverage",
"types": "svelte-check",
"validate": "npm-run-all test:vitest:* types",
"validate": "npm-run-all test:vitest:* test:jest types",
"contributors:add": "all-contributors add",
"contributors:generate": "all-contributors generate"
"contributors:generate": "all-contributors generate",
"preview-release": "./scripts/preview-release"
},
"peerDependencies": {
"svelte": "^3 || ^4 || ^5",
Expand Down
4 changes: 4 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
preset: 'conventionalcommits',
branches: ['main', { name: 'next', prerelease: true }],
}
21 changes: 21 additions & 0 deletions scripts/preview-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash
# Preview the next release from a branch
#
# Prerequisites:
# - You must have push access to repository at the `origin` URL
# - The branch you are on must exist on `origin`

set -euxo pipefail

branch="$(git rev-parse --abbrev-ref HEAD)"
repository_url="$(git remote get-url origin)"

npx \
--package semantic-release@24 \
--package conventional-changelog-conventionalcommits@8 \
-- \
semantic-release \
--plugins="@semantic-release/commit-analyzer,@semantic-release/release-notes-generator" \
--dry-run \
--branches="$branch" \
--repository-url="$repository_url"

0 comments on commit ee1c966

Please sign in to comment.