Skip to content

Commit 9dd5a06

Browse files
authored
Merge pull request #1048 from scratchfoundation/implement-semantic-release
Implement semantic release
2 parents 34ac8e2 + cb7098c commit 9dd5a06

File tree

9 files changed

+29881
-16812
lines changed

9 files changed

+29881
-16812
lines changed

.github/workflows/ci-cd.yml

+6-32
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ name: CI/CD
22

33
on:
44
workflow_dispatch: # Allows you to run this workflow manually from the Actions tab
5-
pull_request: # Runs whenever a pull request is created or updated
65
push: # Runs whenever a commit is pushed to the repository
7-
branches: [master, develop, hotfix/*]
86

97
concurrency:
108
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
@@ -50,38 +48,14 @@ jobs:
5048
mkdir -p ./test/results
5149
npm test
5250
53-
- name: Generate release version
54-
run: |
55-
export RELEASE_TIMESTAMP=$(date +'%Y%m%d%H%M%S')
56-
export VPKG=$($(npm bin)/json -f package.json version)
57-
export VERSION=${VPKG}-prerelease.${RELEASE_TIMESTAMP}
58-
59-
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
60-
61-
if [[ "${GITHUB_REF##*/}" == hotfix/* ]]; then
62-
echo "NPM_TAG=hotfix" >> $GITHUB_ENV
63-
else
64-
echo "NPM_TAG=latest" >> $GITHUB_ENV
65-
fi
51+
- run: npm run build
6652

67-
- name: Build
68-
run: |
69-
npm run build
70-
npm --no-git-tag-version version $RELEASE_VERSION
71-
72-
- name: Deploy to NPM (do a dry-run if not on master, develop, or hotfix/*)
53+
- name: Run semantic-release
7354
env:
7455
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
75-
NPM_TAG: ${{ env.NPM_TAG }}
76-
run: |
77-
message=$([[ "$TRIGGER_DEPLOY" == "false" ]] && echo "DRY RUN of" || echo "Deploying")
78-
echo "$message version $RELEASE_VERSION to $NPM_TAG"
79-
npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN
80-
npm publish --tag $NPM_TAG $([[ "$TRIGGER_DEPLOY" == "false" ]] && echo "--dry-run")
81-
82-
- name: Check Release Version and Create Tag
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8357
run: |
84-
if npm info | grep -q $RELEASE_VERSION; then
85-
git tag $RELEASE_VERSION
86-
git push origin $RELEASE_VERSION
58+
if [[ ${{contains(github.ref, 'hotfix/')}} ]]; then
59+
sed -e "s|hotfix/REPLACE|${{ github.ref_name }}|" --in-place release.config.js
8760
fi
61+
npx --no -- semantic-release

.github/workflows/commitlint.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Lint commit messages
2+
on: [pull_request]
3+
4+
concurrency:
5+
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.sha }}"
6+
7+
jobs:
8+
commitlint:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: wagoid/commitlint-github-action@v5

.husky/.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text eol=lf

.husky/commit-msg

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx --no-install commitlint --edit "$1"

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,20 @@ npm test
6868

6969
## Donate
7070
We provide [Scratch](https://scratch.mit.edu) free of charge, and want to keep it that way! Please consider making a [donation](https://secure.donationpay.org/scratchfoundation/) to support our continued engineering, design, community, and resource development efforts. Donations of any size are appreciated. Thank you!
71+
72+
## Committing
73+
74+
This project uses [semantic release](https://github.com/semantic-release/semantic-release) to ensure version bumps
75+
follow semver so that projects depending on it don't break unexpectedly.
76+
77+
In order to automatically determine version updates, semantic release expects commit messages to follow the
78+
[conventional-changelog](https://github.com/bcoe/conventional-changelog-standard/blob/master/convention.md)
79+
specification.
80+
81+
You can use the [commitizen CLI](https://github.com/commitizen/cz-cli) to make commits formatted in this way:
82+
83+
```bash
84+
npm install -g commitizen@latest cz-conventional-changelog@latest
85+
```
86+
87+
Now you're ready to make commits using `git cz`.

commitlint.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
ignores: [message => message.startsWith('chore(release):')]
4+
};

0 commit comments

Comments
 (0)