Skip to content

Commit 76379e6

Browse files
authored
Merge pull request #208 from scratchfoundation/implement-semantic-release
Implement semantic release
2 parents a2dfc67 + dca7446 commit 76379e6

File tree

9 files changed

+24738
-11454
lines changed

9 files changed

+24738
-11454
lines changed

.github/workflows/ci-cd.yml

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ name: CI/CD
33

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

108
concurrency:
119
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
@@ -40,42 +38,14 @@ jobs:
4038
GitHub head ref: ${{ github.head_ref }}
4139
EOF
4240
43-
- name: Setup & Test
44-
run: |
45-
npm ci
46-
npm run test
41+
- run: npm ci
4742

48-
- name: Generate release version
49-
run: |
50-
export NODE_ENV=production
51-
export RELEASE_TIMESTAMP=$(date +'%Y%m%d%H%M%S')
52-
export VPKG=$($(npm bin)/json -f package.json version)
53-
export VERSION=${VPKG}-prerelease.${RELEASE_TIMESTAMP}
54-
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
55-
if [[ "${GITHUB_REF##*/}" == hotfix/* ]]; then
56-
echo "NPM_TAG=hotfix" >> $GITHUB_ENV
57-
else
58-
echo "NPM_TAG=latest" >> $GITHUB_ENV
59-
fi
43+
- run: npm test
6044

61-
- name: Build
62-
run: |
63-
npm run build
64-
npm --no-git-tag-version version $RELEASE_VERSION
45+
- run: npm run build
6546

66-
- name: Deploy to NPM (do a dry-run if not on master, develop, or hotfix/*)
47+
- name: Run semantic-release
6748
env:
6849
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
69-
NPM_TAG: ${{ env.NPM_TAG }}
70-
run: |
71-
message=$([[ "$TRIGGER_DEPLOY" == "false" ]] && echo "DRY RUN of" || echo "Deploying")
72-
echo "$message version $RELEASE_VERSION to $NPM_TAG"
73-
npm set //registry.npmjs.org/:_authToken=$NPM_TOKEN
74-
npm publish --tag $NPM_TAG $([[ "$TRIGGER_DEPLOY" == "false" ]] && echo "--dry-run")
75-
76-
- name: Check Release Version and Create Tag
77-
run: |
78-
if npm info | grep -q $RELEASE_VERSION; then
79-
git tag $RELEASE_VERSION
80-
git push origin $RELEASE_VERSION
81-
fi
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: npx --no -- semantic-release

.github/workflows/commitlint.yml

Lines changed: 12 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text eol=lf

.husky/commit-msg

Lines changed: 4 additions & 0 deletions
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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,20 @@ npm test
2828

2929
## Donate
3030
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!
31+
32+
## Committing
33+
34+
This project uses [semantic release](https://github.com/semantic-release/semantic-release) to ensure version bumps
35+
follow semver so that projects depending on it don't break unexpectedly.
36+
37+
In order to automatically determine version updates, semantic release expects commit messages to follow the
38+
[conventional-changelog](https://github.com/bcoe/conventional-changelog-standard/blob/master/convention.md)
39+
specification.
40+
41+
You can use the [commitizen CLI](https://github.com/commitizen/cz-cli) to make commits formatted in this way:
42+
43+
```bash
44+
npm install -g commitizen@latest cz-conventional-changelog@latest
45+
```
46+
47+
Now you're ready to make commits using `git cz`.

commitlint.config.js

Lines changed: 4 additions & 0 deletions
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)