Skip to content

Commit

Permalink
workflow: adjust release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Aug 8, 2024
1 parent 32a1433 commit 47cdf24
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/canary-minor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ jobs:

- run: pnpm install

- run: pnpm release --canary
- run: pnpm release --canary --publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
28 changes: 0 additions & 28 deletions .github/workflows/release-gh.yml

This file was deleted.

60 changes: 8 additions & 52 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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 "<[email protected]>"
- 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.
172 changes: 103 additions & 69 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ const { values: args, positionals } = parseArgs({
skipPrompts: {
type: 'boolean',
},
publish: {
type: 'boolean',
default: false,
},
publishOnly: {
type: 'boolean',
},
},
})

Expand Down Expand Up @@ -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...')
Expand All @@ -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'])
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 47cdf24

Please sign in to comment.