Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GH Action for bumping package versions. #153

Merged
merged 5 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ jobs:
build:
name: Build
runs-on: ubuntu-latest
permissions:
id-token: write
strategy:
matrix:
node: ["18", "20", "22"]
Expand Down Expand Up @@ -39,3 +41,9 @@ jobs:

- name: Run CI with turbo
run: pnpm run ci

- name: Publish to npm if needed
if: github.ref == 'refs/heads/main'
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm publish -r --no-git-checks --dry-run
45 changes: 45 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Version
on:
workflow_dispatch:
inputs:
version:
description: "Semver version bump"
required: true
type: choice
options: [patch, minor, major]
jobs:
version:
name: Version
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Install node
uses: actions/setup-node@v4
with:
node-version: "22"
cache: "pnpm"

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Bump version
run: pnpm run version -- ${{ inputs.version }}

- name: Create PR with new versions
uses: peter-evans/create-pull-request@v6
with:
branch: "gh-action-version"
delete-branch: true
title: "Update package versions"
body: "Merging this PR will publish packages to npm at the new version."
- name: Push tags
run: |
git switch gh-action-version
git push origin --tags
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"name": "eslint-plugin-solid-monorepo",
"private": true,
"license": "MIT",
"type": "module",
"workspaces": [
"packages/*"
],
"scripts": {
"build": "turbo run turbo:build",
"ci": "PARSER=all turbo run turbo:build turbo:test turbo:docs turbo:lint turbo:tsc",
Expand All @@ -12,7 +16,8 @@
"tsc": "turbo run turbo:tsc",
"turbo:docs": "cp packages/eslint-plugin-solid/README.md README.md",
"turbo:lint": "eslint --max-warnings=0",
"turbo:tsc": "tsc"
"turbo:tsc": "tsc",
"version": "node scripts/version.js"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand All @@ -37,6 +42,7 @@
"lint-staged": "^13.3.0",
"prettier": "^2.8.8",
"prettier-plugin-packagejson": "^2.5.1",
"semver": "^7.6.0",
"turbo": "^2.0.14",
"typescript": "^5.5.4",
"typescript-eslint": "^8.1.0"
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions scripts/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import fs from "node:fs/promises";
import path from "node:path";
import inc from "semver/functions/inc.js";
import { exec } from "node:child_process";

const pluginPackageJsonPath = path.resolve("packages", "eslint-plugin-solid", "package.json");
const standalonePackageJsonPath = path.resolve(
"packages",
"eslint-solid-standalone",
"package.json"
);

const pluginPackageJson = JSON.parse(await fs.readFile(pluginPackageJsonPath, "utf-8"));
const standalonePackageJson = JSON.parse(await fs.readFile(standalonePackageJsonPath, "utf-8"));

const version = pluginPackageJson.version;
const increment = process.argv[2];
const newVersion = inc(version, increment);

if (newVersion == null || !/^\d+\.\d+\.\d+$/.test(newVersion)) {
console.error("Usage: node scripts/version.js [increment]");
process.exit(1);
}

pluginPackageJson.version = newVersion;
standalonePackageJson.version = newVersion;

await Promise.all([
fs.writeFile(pluginPackageJsonPath, JSON.stringify(pluginPackageJson, null, 2), "utf-8"),
fs.writeFile(standalonePackageJsonPath, JSON.stringify(standalonePackageJson, null, 2), "utf-8"),
]);
await new Promise((resolve, reject) => {
exec(
`git commit --all --message="v${newVersion}"; git tag "v${newVersion}";`,
(error, stdout) => {
if (error) {
reject(error);
} else {
console.log(stdout);
resolve(stdout);
}
}
);
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"resolveJsonModule": true,
"allowImportingTsExtensions": true
},
"include": ["packages/eslint-plugin-solid", "packages/eslint-solid-standalone", "test"],
"include": ["packages/eslint-plugin-solid", "packages/eslint-solid-standalone", "test", "scripts"],
"exclude": ["**/dist", "**/dist.*"]
}