Skip to content

Commit

Permalink
chore: add changesets
Browse files Browse the repository at this point in the history
  • Loading branch information
kotarella1110 committed Aug 7, 2023
1 parent 50400c2 commit 6401cd9
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/version-or-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Version or Publish

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
changesets:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16]
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-pnpm
with:
node-version: ${{ matrix.node-version }}
- id: changesets
uses: changesets/action@v1
with:
version: pnpm bump
publish: pnpm release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
run: pnpm build

- name: Publish to npm
uses: kotarella1110/pr-voyager
uses: kotarella1110/pr-voyager@0
with:
publish: pnpm publish -r
env:
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"check:tsc": "tsc --noEmit",
"check:prettier": "prettier . --ignore-path .gitignore --ignore-path .prettierignore --check",
"fix": "run-s fix:*",
"fix:prettier": "prettier . --ignore-path .gitignore --ignore-path .prettierignore --write --cache"
"fix:prettier": "prettier . --ignore-path .gitignore --ignore-path .prettierignore --write --cache",
"changeset": "changeset",
"bump": "node ./scripts/bump.js",
"release": "node ./scripts/release.js"
},
"author": "kotarella1110",
"license": "MIT",
Expand All @@ -23,6 +26,7 @@
"@types/fs-extra": "^11.0.1",
"@types/node": "^18.16.3",
"@vercel/ncc": "^0.36.1",
"changesets": "^1.0.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.0.1",
"rimraf": "^5.0.1",
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

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

19 changes: 19 additions & 0 deletions scripts/bump.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require("fs");
const path = require("path");
const { exec } = require("@actions/exec");

process.chdir(path.join(__dirname, ".."));

(async () => {
await exec("changeset", ["version"]);

const releaseLine = `v${require("../package.json").version.split(".")[0]}`;

const readmePath = path.join(__dirname, "..", "README.md");
const content = fs.readFileSync(readmePath, "utf8");
const updatedContent = content.replace(
/kotarella1110\/pr-voyager@[^\s]+/g,
`kotarella1110/pr-voyager@${releaseLine}`,
);
fs.writeFileSync(readmePath, updatedContent);
})();
41 changes: 41 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const path = require("path");
const { exec, getExecOutput } = require("@actions/exec");

const { version } = require("../package.json");
const tag = `v${version}`;
const releaseLine = `v${version.split(".")[0]}`;

process.chdir(path.join(__dirname, ".."));

(async () => {
const { exitCode, stderr } = await getExecOutput(
`git`,
["ls-remote", "--exit-code", "origin", "--tags", `refs/tags/${tag}`],
{
ignoreReturnCode: true,
},
);
if (exitCode === 0) {
console.log(
`Action is not being published because version ${tag} is already published`,
);
return;
}
if (exitCode !== 2) {
throw new Error(`git ls-remote exited with ${exitCode}:\n${stderr}`);
}

await exec("git", ["checkout", "--detach"]);
await exec("git", ["add", "--force", "dist"]);
await exec("git", ["commit", "-m", tag]);

await exec("changeset", ["tag"]);

await exec("git", [
"push",
"--force",
"--follow-tags",
"origin",
`HEAD:refs/heads/${releaseLine}`,
]);
})();

0 comments on commit 6401cd9

Please sign in to comment.