Skip to content

Commit

Permalink
ci: refactor version increment workflow (#39)
Browse files Browse the repository at this point in the history
* chore: update config

* chore: check for minor version changes

* chore: test version increment

* chore: fix formatting

* chore: break build for invalid commit types

* chore: reduce noise for pr title checker
  • Loading branch information
Ruddickmg authored Oct 6, 2024
1 parent be7ca09 commit b0e4f6b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
42 changes: 32 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ workflows:
- build
- unit_tests
- integration_tests
- increment_version:
filters:
branches:
only:
- main
- e2e_tests:
requires:
- publish_manifest
Expand Down Expand Up @@ -110,6 +115,7 @@ workflows:
- main
requires:
- publish_latest_manifest
- increment_version
- build_documentation:
filters:
branches:
Expand All @@ -128,6 +134,32 @@ workflows:
#-----------------------------------------------------------------------------------------------------------------------------

jobs:
increment_version:
executor: node
steps:
- checkout_write
- add_ssh_keys:
fingerprints:
- "SHA256:ikYE/tBNMyIEGqxtAetAV3NW80GFZoioglYDTbyiNG0"
- run:
name: Install rust
command: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- run:
name: Configure git
command: |
git config --global user.email "ruddickmg@gmail.com"
git config --global user.name "ruddickmg"
- run:
name: Increment version
command: |
if [[ "$(git log -1 --pretty=%B)" != *"[skip ci] increment version"* ]]; then
node version/increment.js "$(git log -1 --pretty=%B)"
source $HOME/.cargo/env
cargo fetch
git commit -a -m "[skip ci] increment version"
git push -f origin main
fi
benchmark:
executor: ubuntu
environment:
Expand Down Expand Up @@ -256,12 +288,6 @@ jobs:
- run:
name: Install node
command: apk add --update nodejs npm
- run:
name: Install rust
command: |
apk add curl
apk add gcc
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
- add_ssh_keys:
fingerprints:
- "SHA256:ikYE/tBNMyIEGqxtAetAV3NW80GFZoioglYDTbyiNG0"
Expand All @@ -278,10 +304,6 @@ jobs:
command: |
if [[ "$(git log -1 --pretty=%B)" != *"[skip ci] increment version"* ]]; then
node version/increment.js "$(git log -1 --pretty=%B)"
source $HOME/.cargo/env
cargo build
git commit -a -m "[skip ci] increment version"
git push -f origin main
fi
- run:
name: Package chart
Expand Down
7 changes: 0 additions & 7 deletions .github/workflows/pr-title-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ on:
types:
- edited
- opened
pull_request_target:
types:
- opened
- edited
- synchronize
- labeled
- unlabeled

jobs:
check:
Expand Down
2 changes: 1 addition & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"automerge": true,
"automergeType": "pr",
"automergeStrategy": "squash",
"bumpVersion": "patch",
"configMigration": true,
"branchConcurrentLimit": 2,
"extends": [
"config:recommended"
]
Expand Down
16 changes: 6 additions & 10 deletions version/increment.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const fs = require('fs/promises');

const patchTypes = ['fix', 'chore', 'patch', 'build', 'ci', 'docs', 'style', 'refactor', 'perf', 'test'];
const minorTypes = ['feat'];
const allTypes = patchTypes.concat(minorTypes);

const increment = (version, target) => {
const [major, minor, patch] = version.split('.').map(Number);
Expand Down Expand Up @@ -34,21 +36,15 @@ const updateFiles = async (target) => {
}

const parseTarget = (message) => {
if (message.toLowerCase().includes('breaking change')) {
return 'major';
}
const [commitType] = message.split(/[^A-Za-z]/i);
if (patchTypes.includes(commitType)) {
return 'patch';
}
return 'minor';
if (!allTypes.includes(commitType)) throw new Error(`Invalid commit type, must be one of: ${allTypes.map(s => `"${s}"`).join(', ')}`)
if (message.toLowerCase().includes('breaking change')) return 'major';
if (minorTypes.includes(commitType)) return 'minor';
return 'patch';
};

(async () => {
const [_node, _file, commitMessage] = process.argv;
const target = parseTarget(commitMessage);
if (!['patch', 'major', 'minor'].includes(target)) {
throw new Error(`Invalid target: ${target}`);
}
await updateFiles(target);
})().catch(console.error);

0 comments on commit b0e4f6b

Please sign in to comment.