Skip to content

Commit 1a504b4

Browse files
Add auto-bump workflow and version bump script
1 parent 8f5f6f5 commit 1a504b4

File tree

5 files changed

+103
-91
lines changed

5 files changed

+103
-91
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ root = true
66
indent_size = 4
77

88
[*.md]
9+
indent_size = 2
10+
11+
[*.yml]
912
indent_size = 2

.github/workflows/auto-bumper.yml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#file: noinspection GithubFunctionSignatureValidation
2+
name: Auto Bump
3+
on:
4+
issue_comment:
5+
types: [created]
6+
7+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
8+
permissions:
9+
contents: write
10+
id-token: write
11+
pull-requests: write
12+
13+
jobs:
14+
respond:
15+
runs-on: ubuntu-latest
16+
if: (contains( github.event.pull_request.labels.*.name, 'auto-bump') || (contains(github.event.comment.body, '@github-bot') && contains(github.event.comment.body, 'bump')))
17+
steps:
18+
19+
- name: Add comment to PR
20+
uses: actions/github-script@v7
21+
with:
22+
script: |
23+
const fs = require('fs');
24+
const pkg = JSON.parse(fs.readFileSync('./packages/surveyjs-builder/package.json', 'utf8'));
25+
github.rest.issues.createComment({
26+
issue_number: context.issue.number,
27+
owner: context.repo.owner,
28+
repo: context.repo.repo,
29+
body: `Okay boss, ⏳ Bumping version to ${pkg.version}...`
30+
})
31+
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
with:
35+
ref: ${{ github.event.pull_request.head.ref }}
36+
fetch-depth: 0
37+
token: ${{ secrets.GITHUB_TOKEN }}
38+
39+
40+
- name: Setup Node & pnpm
41+
uses: actions/setup-node@v3
42+
with:
43+
node-version: '23'
44+
45+
- name: Install pnpm
46+
run: npm install -g pnpm
47+
48+
- name: Install dependencies
49+
run: pnpm install
50+
51+
- name: Configure Git
52+
run: |
53+
git config --global user.name 'GitHub Action'
54+
git config --global user.email '[email protected]'
55+
56+
- name: Bump version
57+
run: |
58+
pnpm run bump
59+
git add package.json
60+
git commit -m "chore: bump version"
61+
git push
62+
63+
- name: Add comment to PR
64+
uses: actions/github-script@v7
65+
with:
66+
script: |
67+
const fs = require('fs');
68+
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
69+
github.rest.issues.createComment({
70+
issue_number: context.issue.number,
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
body: `✅ Version bumped to ${pkg.version}`
74+
})
75+

.github/workflows/bump_version.yml

Lines changed: 0 additions & 91 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"module": "dist/main.esm.js",
1717
"types": "dist/index.d.ts",
1818
"scripts": {
19+
"bump": "node scripts/bumper.js",
1920
"build": "vite build",
2021
"test": "vitest",
2122
"preview": "vite preview",

scripts/bumper.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import fs from 'fs';
2+
3+
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
4+
const version = packageJson.version;
5+
const [major, minor, patchWord] = version.split('.');
6+
let newPatch;
7+
if (patchWord.includes('-')) {
8+
// Handle pre-release versions by extracting the numeric part
9+
newPatch = parseInt(patchWord.split('-')[0], 10);
10+
newPatch += 1;
11+
// Reconstruct the pre-release version
12+
newPatch = `${newPatch}-${patchWord.split('-')[1]}`;
13+
}
14+
else{
15+
newPatch = parseInt(patchWord, 10) + 1;
16+
}
17+
18+
// Increment patch version
19+
packageJson.version = `${major}.${minor}.${newPatch}`;
20+
21+
// Write back to package.json with proper formatting
22+
fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2) + '\n');
23+
24+
console.log(`Version bumped from ${version} to ${packageJson.version}`);

0 commit comments

Comments
 (0)