Skip to content

Commit

Permalink
ci: add version number to release PR and commit title
Browse files Browse the repository at this point in the history
  • Loading branch information
SegaraRai committed Jun 30, 2024
1 parent 4aa33f2 commit 248088b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ dist-ssr

test-results

changeset-status.json

# Editor directories and files
.idea
.DS_Store
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions scripts/gitTag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ async function gitTagExists(tag: string, remote: boolean): Promise<boolean> {
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)) ||
Expand Down
18 changes: 18 additions & 0 deletions scripts/nextVersion.ts
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 248088b

Please sign in to comment.