From c91130315d8e1933f3281c41f9723bebbdb74cc4 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Tue, 16 Jan 2024 22:28:56 +0800 Subject: [PATCH] Improve release scripts --- .github/workflows/release.yml | 2 ++ scripts/release.js | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b88eed9a2a..cf6fcba881 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,7 @@ on: dry-run: description: "Only create a tarball, do not publish to npm or create a release on GitHub." type: boolean + default: true required: true jobs: @@ -33,6 +34,7 @@ jobs: - run: ./scripts/release.js --version ${{ github.event.inputs.version }} ${{ github.event.inputs.dry-run == 'true' && '--dry-run' || '' }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Archive npm package tarball uses: actions/upload-artifact@v3 diff --git a/scripts/release.js b/scripts/release.js index 4c4e477a03..c676a9762e 100755 --- a/scripts/release.js +++ b/scripts/release.js @@ -28,6 +28,8 @@ if (!process.env.CI) { exitWithError("The script should only be run in CI"); } +exec('echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc'); + exec('git config --global user.name "Zihua Li"'); exec('git config --global user.email "635902+luin@users.noreply.github.com"'); @@ -97,7 +99,7 @@ if (index === -1) { } let nextVersionIndex = changelog.indexOf("\n# v", index); if (nextVersionIndex === -1) { - nextVersionIndex = change.length - 1; + nextVersionIndex = changelog.length - 1; } const releaseNots = changelog @@ -120,7 +122,7 @@ exec(`npm version ${version} --workspaces --force`); exec("git add **/package.json"); exec(`npm version ${version} --include-workspace-root --force`); -const pushCommand = "git push --tags"; +const pushCommand = `git push origin ${process.env.GITHUB_REF_NAME} --follow-tags`; if (dryRun) { console.log(`Skipping: "${pushCommand}" in dry-run mode`); } else {