Skip to content

Commit

Permalink
ci: add dry-run flag to release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Dec 7, 2024
1 parent e295d25 commit 6349107
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ name: Release

# Workflow name based on selected inputs.
# Fallback to default GitHub naming when expression evaluates to empty string
run-name: >-
${{
inputs.release && 'Release ➤ Publish to NPM' ||
''
}}
run-name: >
${{ inputs.release && 'Release ➤ Publish to NPM' || inputs.dryrun && 'Release ➤ Dry-run' || '' }}
on:
pull_request:
push:
Expand All @@ -15,7 +12,10 @@ on:
inputs:
release:
description: 'Publish new release'
required: true
default: false
type: boolean
dryrun:
description: 'Dry run'
default: false
type: boolean

Expand All @@ -24,10 +24,30 @@ concurrency:
cancel-in-progress: true

jobs:
release:
dryrun:
# only run if opt-in during workflow_dispatch
name: 'Release: Dry-run release process'
if: always() && github.event.inputs.dryrun == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# Need to fetch entire commit history to
# analyze every commit since last release
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: lts/*
cache: npm
- run: npm ci
- run: npx semantic-release --dry-run
if: always()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
release:
name: 'Release: Publish to NPM'
if: always() && github.event.inputs.release == 'true'
if: always() && github.event.inputs.release == 'true' && github.event.inputs.dryrun == 'false'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -40,11 +60,10 @@ jobs:
node-version: lts/*
cache: npm
- run: npm ci
# Branches that will release new versions are defined in .releaserc.json
- run: npx semantic-release
# Don't allow interrupting the release step if the job is cancelled, as it can lead to an inconsistent state
# e.g. git tags were pushed but it exited before `npm publish`
if: always()
if: always() && github.event.inputs.release == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}

0 comments on commit 6349107

Please sign in to comment.