From 3a4db7fb5c45e2a6126fbd7b8881bd4831985cee Mon Sep 17 00:00:00 2001 From: neverland <chenjiahan.jait@bytedance.com> Date: Mon, 4 Nov 2024 18:59:32 +0800 Subject: [PATCH] chore: update release workflow --- .github/workflows/release.yml | 69 ++++++++---------------------- package.json | 2 +- scripts/release.mjs | 80 ----------------------------------- 3 files changed, 19 insertions(+), 132 deletions(-) delete mode 100644 scripts/release.mjs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e67fafc..6963ef9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,53 +1,21 @@ -name: Release Full +# This action will publish the package to npm and create a GitHub release. +name: Release on: - workflow_dispatch: - inputs: - version: - type: choice - description: "Release Version Type" - required: true - default: "patch" - options: - - major - - premajor - - minor - - preminor - - patch - - prepatch - - prerelease - - tag: - type: choice - description: "Release Npm Tag" - required: true - default: "latest" - options: - - canary - - nightly - - latest - - beta - - alpha + # Run `npm run bump` to bump the version and create a git tag. + push: + tags: + - "v*" - dry_run: - type: boolean - description: "DryRun release" - required: true - default: false + workflow_dispatch: permissions: - # To publish packages with provenance + contents: write id-token: write jobs: - release: - name: Release - permissions: - contents: write - # To publish packages with provenance - id-token: write + publish: runs-on: ubuntu-latest - steps: - name: Checkout uses: actions/checkout@v4 @@ -58,19 +26,18 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 22 cache: "pnpm" - name: Install Dependencies run: pnpm install - # - name: Run Test - # run: pnpm run test + - name: Publish + uses: JS-DevTools/npm-publish@v3 + with: + token: ${{ secrets.RSBUILD_PLUGIN_NPM_TOKEN }} - - name: Try release to npm - run: pnpm run release - env: - DRY_RUN: ${{ inputs.dry_run }} - TAG: ${{ inputs.tag }} - VERSION: ${{ inputs.version }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + - name: Create GitHub Release + uses: ncipollo/release-action@v1 + with: + generateReleaseNotes: "true" diff --git a/package.json b/package.json index 28831a2..a6980fc 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "build:watch": "modern build -w", "lint": "biome check", "lint:fix": "biome check --write --unsafe", - "release": "node ./scripts/release.mjs" + "bump": "npx bumpp" }, "dependencies": { "framer-motion": "^11.3.4" diff --git a/scripts/release.mjs b/scripts/release.mjs deleted file mode 100644 index 7c9e24c..0000000 --- a/scripts/release.mjs +++ /dev/null @@ -1,80 +0,0 @@ -import path from 'node:path'; -import * as url from 'node:url'; -import { $ } from 'execa'; -import fs from 'fs-extra'; -import { inc } from 'semver'; - -const RELEASE_TAG = process.env.TAG || 'beta'; -const RELEASE_DRY_RUN = process.env.DRY_RUN || 'true'; -const RELEASE_VERSION_TYPE = process.env.VERSION || 'prerelease'; -const RELEASE_NPM_TOKEN = process.env.NPM_TOKEN || ''; - -const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); -const PKG_PATH = path.resolve(__dirname, '../package.json'); -const pkg = fs.readJsonSync(PKG_PATH); -const currentVersion = pkg.version; -const nextVersion = inc(currentVersion, RELEASE_VERSION_TYPE); -if (!nextVersion) { - throw new Error( - `Failed to generate next version from "${currentVersion}" with type "${RELEASE_VERSION_TYPE}"`, - ); -} - -console.info(`Release ${RELEASE_TAG} version ${nextVersion}`); - -// Update pkg version -console.info(`Updating version from ${currentVersion} to ${nextVersion}`); -pkg.version = nextVersion; -fs.writeJsonSync(PKG_PATH, pkg, { spaces: 2 }); - -// Write npmrc -const npmrcPath = `${process.env.HOME}/.npmrc`; -console.info(`Writing npmrc to ${npmrcPath}`); -fs.writeFileSync( - npmrcPath, - `//registry.npmjs.org/:_authToken=${RELEASE_NPM_TOKEN}`, -); - -// Publish to npm -console.info(`Publishing to npm with tag ${RELEASE_TAG}`); -const dryRun = RELEASE_DRY_RUN === 'true' ? ['--dry-run'] : []; -try { - await $`pnpm publish ${dryRun} --tag ${RELEASE_TAG} --no-git-checks --provenance`; - console.info('Published successfully'); -} catch (e) { - console.error(`Publish failed: ${e.message}`); - process.exit(1); -} finally { - fs.removeSync(npmrcPath); -} - -// Push tag to github -if (RELEASE_DRY_RUN !== 'true') { - console.info('Pushing tag to github'); - const tagName = `v${nextVersion}`; - try { - await $`git config --global --add safe.directory /github/workspace`; - await $`git config --global user.name "github-actions[bot]"`; - await $`git config --global user.email "github-actions[bot]@users.noreply.github.com"`; - await $`git status`; - await $`git tag ${tagName}`; - await $`git push origin ${tagName}`; - console.info('Pushed tag successfully'); - } catch (e) { - console.error(`Push tag failed: ${e.message}`); - process.exit(1); - } - - try { - await $`git add --all`; - const commitMsg = `release ${tagName}`; - await $`git commit -m ${commitMsg}`; - await $`git push`; - console.info('Pushed branch successfully'); - } catch (e) { - console.error(`Update branch failed: ${e.message}`); - process.exit(1); - } -} - -console.info('Release completed');