From 248088b3ee0fdc502e719dabbc3f497ee4e36b3b Mon Sep 17 00:00:00 2001 From: SegaraRai Date: Mon, 1 Jul 2024 00:20:15 +0900 Subject: [PATCH] ci: add version number to release PR and commit title --- .github/workflows/publish.yaml | 9 ++++++++- .gitignore | 2 ++ package.json | 3 ++- scripts/gitTag.ts | 4 ++-- scripts/nextVersion.ts | 18 ++++++++++++++++++ 5 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 scripts/nextVersion.ts diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 7f0f94e..9184be0 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -51,10 +51,17 @@ jobs: pnpm test:container docker compose down + - name: Get Next Package Version + id: version + run: | + echo "PACKAGE_RELEASE_VERSION=$(pnpm --silent next-version)" >> "$GITHUB_OUTPUT" + - name: Create Release Pull Request or Publish to npm uses: changesets/action@v1 with: - publish: pnpm tag-and-publish --provenance + title: "Release v${{ steps.version.outputs.PACKAGE_RELEASE_VERSION }}" + commit: "release: v${{ steps.version.outputs.PACKAGE_RELEASE_VERSION }}" + publish: pnpm tag-and-publish env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index eca9732..57f90a8 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,8 @@ dist-ssr test-results +changeset-status.json + # Editor directories and files .idea .DS_Store diff --git a/package.json b/package.json index 6581068..ed97ca7 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,8 @@ "lint": "eslint . && prettier -c .", "test": "vitest", "tag": "tsx scripts/gitTag.ts", - "tag-and-publish": "pnpm tag && pnpm publish -r" + "tag-and-publish": "pnpm tag && pnpm publish -r", + "next-version": "tsx scripts/nextVersion.ts" }, "devDependencies": { "@changesets/cli": "^2.27.6", diff --git a/scripts/gitTag.ts b/scripts/gitTag.ts index aab03a7..073c55e 100644 --- a/scripts/gitTag.ts +++ b/scripts/gitTag.ts @@ -10,8 +10,8 @@ async function gitTagExists(tag: string, remote: boolean): Promise { return !!stdout.toString().trim(); } -const packageJson = JSON.parse(await readFile("package.json", "utf8")); -const tagName = `v${packageJson.version}`; +const pkg = JSON.parse(await readFile("package.json", "utf8")); +const tagName = `v${pkg.version}`; if ( (await gitTagExists(tagName, false)) || diff --git a/scripts/nextVersion.ts b/scripts/nextVersion.ts new file mode 100644 index 0000000..18457f9 --- /dev/null +++ b/scripts/nextVersion.ts @@ -0,0 +1,18 @@ +import { spawnSync } from "node:child_process"; +import { readFile } from "node:fs/promises"; + +spawnSync("pnpm", ["changeset", "status", "--output", "changeset-status.json"]); + +const changesetStatus = JSON.parse( + await readFile("changeset-status.json", "utf8") +) as { releases: { name: string; newVersion: string }[] }; +const release = changesetStatus.releases.find( + (release) => release.name === "vite-plugin-modular-tailwindcss" +); + +if (!release) { + console.error("Release not found in changeset status"); + process.exit(1); +} + +console.log(release.newVersion);