Skip to content

Commit 88ab608

Browse files
authored
Merge pull request #153 from solidjs-community/ci-version-publish
Add GH Action for bumping package versions.
2 parents 0380b51 + 4aa6f2b commit 88ab608

File tree

6 files changed

+108
-2
lines changed

6 files changed

+108
-2
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ jobs:
88
build:
99
name: Build
1010
runs-on: ubuntu-latest
11+
permissions:
12+
id-token: write
1113
strategy:
1214
matrix:
1315
node: ["18", "20", "22"]
@@ -39,3 +41,9 @@ jobs:
3941
4042
- name: Run CI with turbo
4143
run: pnpm run ci
44+
45+
- name: Publish to npm if needed
46+
if: github.ref == 'refs/heads/main'
47+
env:
48+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
49+
run: pnpm publish -r --no-git-checks --dry-run

.github/workflows/version.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Version
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
version:
6+
description: "Semver version bump"
7+
required: true
8+
type: choice
9+
options: [patch, minor, major]
10+
jobs:
11+
version:
12+
name: Version
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
18+
- name: Setup pnpm
19+
uses: pnpm/action-setup@v4
20+
with:
21+
run_install: false
22+
23+
- name: Install node
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: "22"
27+
cache: "pnpm"
28+
29+
- name: Install dependencies
30+
run: pnpm install --frozen-lockfile
31+
32+
- name: Bump version
33+
run: pnpm run version -- ${{ inputs.version }}
34+
35+
- name: Create PR with new versions
36+
uses: peter-evans/create-pull-request@v6
37+
with:
38+
branch: "gh-action-version"
39+
delete-branch: true
40+
title: "Update package versions"
41+
body: "Merging this PR will publish packages to npm at the new version."
42+
- name: Push tags
43+
run: |
44+
git switch gh-action-version
45+
git push origin --tags

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"name": "eslint-plugin-solid-monorepo",
33
"private": true,
44
"license": "MIT",
5+
"type": "module",
6+
"workspaces": [
7+
"packages/*"
8+
],
59
"scripts": {
610
"build": "turbo run turbo:build",
711
"ci": "PARSER=all turbo run turbo:build turbo:test turbo:docs turbo:lint turbo:tsc",
@@ -12,7 +16,8 @@
1216
"tsc": "turbo run turbo:tsc",
1317
"turbo:docs": "cp packages/eslint-plugin-solid/README.md README.md",
1418
"turbo:lint": "eslint --max-warnings=0",
15-
"turbo:tsc": "tsc"
19+
"turbo:tsc": "tsc",
20+
"version": "node scripts/version.js"
1621
},
1722
"lint-staged": {
1823
"*.{js,jsx,ts,tsx}": [
@@ -37,6 +42,7 @@
3742
"lint-staged": "^13.3.0",
3843
"prettier": "^2.8.8",
3944
"prettier-plugin-packagejson": "^2.5.1",
45+
"semver": "^7.6.0",
4046
"turbo": "^2.0.14",
4147
"typescript": "^5.5.4",
4248
"typescript-eslint": "^8.1.0"

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/version.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import fs from "node:fs/promises";
2+
import path from "node:path";
3+
import inc from "semver/functions/inc.js";
4+
import { exec } from "node:child_process";
5+
6+
const pluginPackageJsonPath = path.resolve("packages", "eslint-plugin-solid", "package.json");
7+
const standalonePackageJsonPath = path.resolve(
8+
"packages",
9+
"eslint-solid-standalone",
10+
"package.json"
11+
);
12+
13+
const pluginPackageJson = JSON.parse(await fs.readFile(pluginPackageJsonPath, "utf-8"));
14+
const standalonePackageJson = JSON.parse(await fs.readFile(standalonePackageJsonPath, "utf-8"));
15+
16+
const version = pluginPackageJson.version;
17+
const increment = process.argv[2];
18+
const newVersion = inc(version, increment);
19+
20+
if (newVersion == null || !/^\d+\.\d+\.\d+$/.test(newVersion)) {
21+
console.error("Usage: node scripts/version.js [increment]");
22+
process.exit(1);
23+
}
24+
25+
pluginPackageJson.version = newVersion;
26+
standalonePackageJson.version = newVersion;
27+
28+
await Promise.all([
29+
fs.writeFile(pluginPackageJsonPath, JSON.stringify(pluginPackageJson, null, 2), "utf-8"),
30+
fs.writeFile(standalonePackageJsonPath, JSON.stringify(standalonePackageJson, null, 2), "utf-8"),
31+
]);
32+
await new Promise((resolve, reject) => {
33+
exec(
34+
`git commit --all --message="v${newVersion}"; git tag "v${newVersion}";`,
35+
(error, stdout) => {
36+
if (error) {
37+
reject(error);
38+
} else {
39+
console.log(stdout);
40+
resolve(stdout);
41+
}
42+
}
43+
);
44+
});

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"resolveJsonModule": true,
99
"allowImportingTsExtensions": true
1010
},
11-
"include": ["packages/eslint-plugin-solid", "packages/eslint-solid-standalone", "test"],
11+
"include": ["packages/eslint-plugin-solid", "packages/eslint-solid-standalone", "test", "scripts"],
1212
"exclude": ["**/dist", "**/dist.*"]
1313
}

0 commit comments

Comments
 (0)