]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
workflow: adjust release workflow
authorEvan You <evan@vuejs.org>
Thu, 8 Aug 2024 12:44:35 +0000 (20:44 +0800)
committerEvan You <evan@vuejs.org>
Thu, 8 Aug 2024 12:44:35 +0000 (20:44 +0800)
.github/workflows/canary-minor.yml
.github/workflows/canary.yml
.github/workflows/release-gh.yml [deleted file]
.github/workflows/release.yml
scripts/release.js

index ffb9b384d4e2111b28cc41fe836ab034e761e05c..b5d75b9cebb123cf57a9762750f08b3d93482853 100644 (file)
@@ -28,6 +28,6 @@ jobs:
 
       - run: pnpm install
 
-      - run: pnpm release --canary --tag minor
+      - run: pnpm release --canary --publish --tag minor
         env:
           NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
index a9432ced059541c048ead49d6c33a74c3a3d7d0f..bb622725aa8037339c5f062a8e7eda90191cc14f 100644 (file)
@@ -26,6 +26,6 @@ jobs:
 
       - run: pnpm install
 
-      - run: pnpm release --canary
+      - run: pnpm release --canary --publish
         env:
           NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
diff --git a/.github/workflows/release-gh.yml b/.github/workflows/release-gh.yml
deleted file mode 100644 (file)
index f0cc560..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-on:
-  push:
-    tags:
-      - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
-
-name: Create GH Release for Tag
-
-permissions: {}
-jobs:
-  build:
-    permissions:
-      contents: write # to create release (yyx990803/release-tag)
-
-    name: Create Release
-    runs-on: ubuntu-latest
-    steps:
-      - name: Checkout code
-        uses: actions/checkout@master
-      - name: Create Release for Tag
-        id: release_tag
-        uses: yyx990803/release-tag@master
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-        with:
-          tag_name: ${{ github.ref }}
-          body: |
-            For stable releases, please refer to [CHANGELOG.md](https://github.com/vuejs/core/blob/main/CHANGELOG.md) for details.
-            For pre-releases, please refer to [CHANGELOG.md](https://github.com/vuejs/core/blob/minor/CHANGELOG.md) of the `minor` branch.
index 350245d3b45e3850f2f70a0be91466cc152ebe56..d1ffa668d8c71ad76da33006a3eb5eb806c05098 100644 (file)
@@ -1,32 +1,9 @@
 name: Release
 
 on:
-  workflow_dispatch:
-    inputs:
-      branch:
-        description: 'Branch to publish'
-        required: true
-        default: 'main'
-        type: choice
-        options:
-          - main
-          - minor
-      bump:
-        description: 'Bump version'
-        required: true
-        default: 'patch'
-        type: choice
-        options:
-          - patch
-          - minor
-          - prepatch
-          - preminor
-          - custom
-      custom_version:
-        description: 'Custom version'
-        required: false
-        default: ''
-        type: string
+  push:
+    tags:
+      - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10
 
 jobs:
   release:
@@ -41,9 +18,6 @@ jobs:
     steps:
       - name: Checkout
         uses: actions/checkout@v4
-        with:
-          ref: ${{ inputs.branch }}
-          fetch-depth: 0 # need this to get tags for changelog generation
 
       - name: Install pnpm
         uses: pnpm/action-setup@v4
@@ -58,38 +32,20 @@ jobs:
       - name: Install deps
         run: pnpm install
 
-      - name: Configure git user as vue bot
-        run: |
-          git config user.name "vue-bot"
-          git config user.email "<bot@vuejs.org>"
-
-      - name: Import GPG key
-        uses: crazy-max/ghaction-import-gpg@v6
-        with:
-          gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
-          passphrase: ${{ secrets.GPG_PASSPHRASE }}
-          git_user_signingkey: true
-          git_commit_gpgsign: true
-
-      - name: Run release script
-        id: release
+      - name: Build and publish
+        id: publish
         run: |
-          pnpm release ${{ inputs.bump != 'custom' && inputs.bump || inputs.custom_version }} --skipPrompts
-          RELEASE_TAG=$(git describe --tags --abbrev=0)
-          echo "tag=$RELEASE_TAG" >> $GITHUB_OUTPUT
+          pnpm release --publishOnly
         env:
           NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
 
-      - name: Push tags
-        run: git push -u origin ${{ inputs.branch }} --follow-tags
-
-      - name: Create Release for Tag
+      - name: Create GitHub release
         id: release_tag
         uses: yyx990803/release-tag@master
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
         with:
-          tag_name: ${{ steps.release.outputs.tag }}
+          tag_name: ${{ github.ref }}
           body: |
             For stable releases, please refer to [CHANGELOG.md](https://github.com/vuejs/core/blob/main/CHANGELOG.md) for details.
             For pre-releases, please refer to [CHANGELOG.md](https://github.com/vuejs/core/blob/minor/CHANGELOG.md) of the `minor` branch.
index a85ee866ec37b79dbefd3f4fd6ac396c31932cf2..a3517c30728214008e5c8d0372308af04e172696 100644 (file)
@@ -51,6 +51,13 @@ const { values: args, positionals } = parseArgs({
     skipPrompts: {
       type: 'boolean',
     },
+    publish: {
+      type: 'boolean',
+      default: false,
+    },
+    publishOnly: {
+      type: 'boolean',
+    },
   },
 })
 
@@ -247,41 +254,7 @@ async function main() {
     }
   }
 
-  if (!skipTests) {
-    step('Checking CI status for HEAD...')
-    let isCIPassed = await getCIResult()
-    skipTests ||= isCIPassed
-
-    if (isCIPassed) {
-      if (!skipPrompts) {
-        /** @type {{ yes: boolean }} */
-        const { yes: promptSkipTests } = await prompt({
-          type: 'confirm',
-          name: 'yes',
-          message: `CI for this commit passed. Skip local tests?`,
-        })
-        skipTests = promptSkipTests
-      } else {
-        skipTests = true
-      }
-    } else if (skipPrompts) {
-      throw new Error(
-        'CI for the latest commit has not passed yet. ' +
-          'Only run the release workflow after the CI has passed.',
-      )
-    }
-  }
-
-  if (!skipTests) {
-    step('\nRunning tests...')
-    if (!isDryRun) {
-      await run('pnpm', ['run', 'test', '--run'])
-    } else {
-      console.log(`Skipped (dry run)`)
-    }
-  } else {
-    step('Tests skipped.')
-  }
+  await runTestsIfNeeded()
 
   // update all package versions and inter-dependencies
   step('\nUpdating cross dependencies...')
@@ -291,16 +264,6 @@ async function main() {
   )
   versionUpdated = true
 
-  // build all packages with types
-  step('\nBuilding all packages...')
-  if (!skipBuild && !isDryRun) {
-    await run('pnpm', ['run', 'build', '--withTypes'])
-    step('\nTesting built types...')
-    await run('pnpm', ['test-dts-only'])
-  } else {
-    console.log(`(skipped)`)
-  }
-
   // generate changelog
   step('\nGenerating changelog...')
   await run(`pnpm`, ['run', 'changelog'])
@@ -337,29 +300,15 @@ async function main() {
   }
 
   // publish packages
-  step('\nPublishing packages...')
-
-  const additionalPublishFlags = []
-  if (isDryRun) {
-    additionalPublishFlags.push('--dry-run')
-  }
-  if (isDryRun || skipGit) {
-    additionalPublishFlags.push('--no-git-checks')
-  }
-  // bypass the pnpm --publish-branch restriction which isn't too useful to us
-  // otherwise it leads to a prompt and blocks the release script
-  const branch = await getBranch()
-  if (branch !== 'main') {
-    additionalPublishFlags.push('--publish-branch', branch)
-  }
-  // add provenance metadata when releasing from CI
-  // canary release commits are not pushed therefore we don't need to add provenance
-  if (process.env.CI && !isCanary) {
-    additionalPublishFlags.push('--provenance')
-  }
-
-  for (const pkg of packages) {
-    await publishPackage(pkg, targetVersion, additionalPublishFlags)
+  if (args.publish) {
+    await buildPackages()
+    await publishPackages(targetVersion)
+  } else {
+    console.log(
+      pico.yellow(
+        '\nPublish step skipped (will be done in GitHub actions on successful push)',
+      ),
+    )
   }
 
   // push to GitHub
@@ -386,6 +335,44 @@ async function main() {
   console.log()
 }
 
+async function runTestsIfNeeded() {
+  if (!skipTests) {
+    step('Checking CI status for HEAD...')
+    let isCIPassed = await getCIResult()
+    skipTests ||= isCIPassed
+
+    if (isCIPassed) {
+      if (!skipPrompts) {
+        /** @type {{ yes: boolean }} */
+        const { yes: promptSkipTests } = await prompt({
+          type: 'confirm',
+          name: 'yes',
+          message: `CI for this commit passed. Skip local tests?`,
+        })
+        skipTests = promptSkipTests
+      } else {
+        skipTests = true
+      }
+    } else if (skipPrompts) {
+      throw new Error(
+        'CI for the latest commit has not passed yet. ' +
+          'Only run the release workflow after the CI has passed.',
+      )
+    }
+  }
+
+  if (!skipTests) {
+    step('\nRunning tests...')
+    if (!isDryRun) {
+      await run('pnpm', ['run', 'test', '--run'])
+    } else {
+      console.log(`Skipped (dry run)`)
+    }
+  } else {
+    step('Tests skipped.')
+  }
+}
+
 async function getCIResult() {
   try {
     const sha = await getSha()
@@ -492,6 +479,46 @@ function updateDeps(pkg, depType, version, getNewPackageName) {
   })
 }
 
+async function buildPackages() {
+  step('\nBuilding all packages...')
+  if (!skipBuild) {
+    await run('pnpm', ['run', 'build', '--withTypes'])
+  } else {
+    console.log(`(skipped)`)
+  }
+}
+
+/**
+ * @param {string} version
+ */
+async function publishPackages(version) {
+  // publish packages
+  step('\nPublishing packages...')
+
+  const additionalPublishFlags = []
+  if (isDryRun) {
+    additionalPublishFlags.push('--dry-run')
+  }
+  if (isDryRun || skipGit) {
+    additionalPublishFlags.push('--no-git-checks')
+  }
+  // bypass the pnpm --publish-branch restriction which isn't too useful to us
+  // otherwise it leads to a prompt and blocks the release script
+  const branch = await getBranch()
+  if (branch !== 'main') {
+    additionalPublishFlags.push('--publish-branch', branch)
+  }
+  // add provenance metadata when releasing from CI
+  // canary release commits are not pushed therefore we don't need to add provenance
+  if (process.env.CI && !isCanary) {
+    additionalPublishFlags.push('--provenance')
+  }
+
+  for (const pkg of packages) {
+    await publishPackage(pkg, version, additionalPublishFlags)
+  }
+}
+
 /**
  * @param {string} pkgName
  * @param {string} version
@@ -541,7 +568,14 @@ async function publishPackage(pkgName, version, additionalFlags) {
   }
 }
 
-main().catch(err => {
+async function publishOnly() {
+  await buildPackages()
+  await publishPackages(currentVersion)
+}
+
+const fnToRun = args.publishOnly ? publishOnly : main
+
+fnToRun().catch(err => {
   if (versionUpdated) {
     // revert to current version on failed releases
     updateVersions(currentVersion)