Release #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
workflow_dispatch: | |
inputs: | |
releaseVersion: | |
description: The new version to release, e.g. 1.0.0 | |
type: string | |
required: true | |
nextDevelopmentVersion: | |
description: > | |
The new version to use during development, e.g. 1.1.0-SNAPSHOT | |
type: string | |
required: true | |
dryRun: | |
description: Don't push commits or tags | |
type: boolean | |
default: true | |
draft: | |
description: Should the release be a draft? | |
type: boolean | |
default: false | |
concurrency: release | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 | |
- name: Set release version in package.json | |
uses: jacobtomlinson/gha-find-replace@a51bbcd94d000df9ca0fcb54ec8be69aad8374b0 # v3 | |
with: | |
find: '"version": "[0-9\.]+(-SNAPSHOT)?"' | |
replace: '"version": "${{ inputs.releaseVersion }}"' | |
include: package.json | |
regex: true | |
- name: Set release version in README example | |
uses: jacobtomlinson/gha-find-replace@a51bbcd94d000df9ca0fcb54ec8be69aad8374b0 # v3 | |
with: | |
find: 'infra-report-action@v[0-9\.]+' | |
replace: 'infra-report-action@v${{ inputs.releaseVersion }}' | |
include: README.md | |
regex: true | |
- name: Commit new release version | |
id: commit-new-release | |
uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9 | |
with: | |
commit: --signoff | |
default_author: github_actions | |
fetch: false | |
message: 'dist: release ${{ inputs.releaseVersion }}' | |
push: ${{ inputs.dryRun == false }} | |
tag: v${{ inputs.releaseVersion }} | |
- name: Print new release version commit | |
run: git show ${{ steps.commit-new-release.outputs.commit_sha }} | cat | |
- name: 'Create release' | |
if: inputs.dryRun == false | |
uses: 'actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea' # v7 | |
with: | |
github-token: '${{ secrets.GITHUB_TOKEN }}' | |
script: | | |
try { | |
const response = await github.rest.repos.createRelease({ | |
tag_name: "v${{ inputs.releaseVersion }}", | |
name: "Release ${{ inputs.releaseVersion }}", | |
draft: ${{ inputs.draft }}, | |
generate_release_notes: true, | |
prerelease: false, | |
repo: context.repo.repo, | |
owner: context.repo.owner, | |
}); | |
core.exportVariable('RELEASE_ID', response.data.id); | |
core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url); | |
} catch (error) { | |
core.setFailed(error.message); | |
} | |
- name: Set development version in package.json | |
uses: jacobtomlinson/gha-find-replace@a51bbcd94d000df9ca0fcb54ec8be69aad8374b0 # v3 | |
with: | |
find: '"version": "${{ inputs.releaseVersion }}"' | |
replace: '"version": "${{ inputs.nextDevelopmentVersion }}"' | |
include: 'package.json' | |
regex: false | |
- name: Extract semver release version components | |
uses: madhead/semver-utils@5532a76b34d90e0ea245292630e4d3af3d7fe75e # v3 | |
id: version | |
with: | |
version: ${{ inputs.releaseVersion }} | |
- name: Create and move major/minor tags | |
run: | | |
git tag v${{ steps.version.outputs.major }} --force | |
git tag v${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }} --force | |
- name: Push major/minor tags | |
if: ${{ inputs.dryRun == false }} | |
run: | | |
git push origin v${{ steps.version.outputs.major }} --force | |
git push origin v${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }} --force | |
- name: Commit next development version | |
id: commit-next-dev | |
uses: EndBug/add-and-commit@a94899bca583c204427a224a7af87c02f9b325d5 # v9 | |
with: | |
commit: --signoff | |
default_author: github_actions | |
fetch: false | |
message: 'dist: release ${{ inputs.nextDevelopmentVersion }}' | |
push: ${{ inputs.dryRun == false }} | |
- name: Print next development version commit | |
run: git show ${{ steps.commit-next-dev.outputs.commit_sha }} | cat |