From 79707380a9755cd05dd85a8489b9174f50581dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E8=B6=85=E8=B6=8A?= <993921@qq.com> Date: Sat, 16 Mar 2024 15:19:59 +0800 Subject: [PATCH] wip --- .github/workflows/release.yml | 13 +++++++---- common/scripts/release.js | 41 +++++++++++++++++++++++++++++++++++ package.json | 3 ++- 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 common/scripts/release.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 218e085..6609864 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,15 +15,20 @@ jobs: - name: Checkout Repo uses: actions/checkout@v3 - - name: Setup Node.js 20 + - name: Setup Node.js 20.x uses: actions/setup-node@v3 with: - node-version: 20 + node-version: 20.x - name: Install Dependencies run: yarn - - name: Create Release Pull Request + - name: Create Release Pull Request or Publish to npm + id: changesets uses: changesets/action@v1 + with: + # This expects you to have a script called release which does a build for your packages and calls changeset publish + publish: yarn release env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} \ No newline at end of file diff --git a/common/scripts/release.js b/common/scripts/release.js new file mode 100644 index 0000000..2e49467 --- /dev/null +++ b/common/scripts/release.js @@ -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}`, + ]); +})(); \ No newline at end of file diff --git a/package.json b/package.json index c4491ef..d8cb769 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "EthPaymaster typescript Sdk", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "release": "node ./scripts/release.js" }, "keywords": [], "author": "",