generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: glitches in release workflow (#438)
setter for NEW_VERSION env variable was incorrect
- Loading branch information
Showing
2 changed files
with
144 additions
and
91 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
name: Prepare Next Version | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
increment: | ||
description: Increment version | ||
required: true | ||
default: patch | ||
type: choice | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: write | ||
|
||
env: | ||
INPUTS_INCREMENT: ${{ github.event.inputs.increment }} | ||
CHANGELOG_FILE: CHANGELOG.md | ||
|
||
|
||
jobs: | ||
create-pr: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
registry-url: https://registry.npmjs.org/ | ||
|
||
- name: Increment version | ||
id: increment-version | ||
run: | | ||
npm version $INPUTS_INCREMENT --no-git-tag-version | ||
echo "new-version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT | ||
# -i for in-place editing, -E for extended regex including \s for whitespace | ||
# double quotes needed for sed to work with variable replacement | ||
# double backslashes needed for sed to work with double quotes | ||
- name: Replace Unreleased entry in ${{ env.CHANGELOG_FILE }} | ||
env: | ||
NEW_VERSION: ${{ steps.increment-version.outputs.new-version }} | ||
run: | | ||
CURRENT_DATE=$(date +%Y-%m-%d) | ||
sed -i -E "0,/^##\s+.*\[Unreleased\].*$/s//## [Unreleased]\\ | ||
\\ | ||
### Added\\ | ||
### Changed\\ | ||
### Deprecated\\ | ||
### Removed\\ | ||
### Fixed\\ | ||
### Security\\ | ||
\\ | ||
## [${NEW_VERSION}] - ${CURRENT_DATE}/" $CHANGELOG_FILE | ||
head -n 20 $CHANGELOG_FILE | ||
- name: Create Pull Request | ||
uses: peter-evans/create-pull-request@v7 | ||
with: | ||
commit-message: chore/release-${{ steps.increment-version.outputs.new-version }} | ||
title: "chore(version): ${{ env.INPUTS_INCREMENT}} version ${{ steps.increment-version.outputs.new-version }}" | ||
body: Set version to ${{ steps.increment-version.outputs.new-version }} | ||
branch: chore/release-${{ steps.increment-version.outputs.new-version }} | ||
reviewers: ${{ github.actor }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,115 +4,98 @@ | |
name: Release | ||
|
||
on: | ||
push: | ||
branches: main | ||
|
||
workflow_dispatch: | ||
inputs: | ||
dry-run: | ||
description: Dry run | ||
required: false | ||
default: false | ||
type: boolean | ||
increment: | ||
description: Increment version | ||
required: true | ||
default: patch | ||
type: choice | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
|
||
permissions: | ||
contents: write | ||
|
||
env: | ||
INPUTS_DRY_RUN: ${{ github.event.inputs.dry-run }} | ||
INPUTS_INCREMENT: ${{ github.event.inputs.increment }} | ||
DRY_RUN_OPTION: ${{ github.event.inputs.dry-run == 'true' && '--dry-run' || '' }} | ||
|
||
|
||
jobs: | ||
check-versions: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
do-release: ${{ steps.check-versions.outputs.do-release }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
registry-url: https://registry.npmjs.org/ | ||
|
||
- name: Check Versions | ||
id: check-versions | ||
run: | | ||
if [ "$GITHUB_EVENT_NAME" == "workflow_dispatch" ]; then | ||
echo "Run as workflow_dispatch: run release" | ||
echo "do-release=true" >> $GITHUB_OUTPUT | ||
exit 0 | ||
fi | ||
local_version=$(npm pkg get version | tr -d '"')" | ||
npm_version=$(npm show $GITHUB_REPOSITORY version) | ||
npm install -g semver | ||
if semver -r ">${npm_version}" "${local_version}"; then | ||
echo "Local version is greater than npm version: run release" | ||
echo "do-release=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "Local version is not greater than npm version: nothing to do." | ||
echo "do-release=false" >> $GITHUB_OUTPUT | ||
fi | ||
publish-npm: | ||
runs-on: ubuntu-latest | ||
needs: check-versions | ||
if: ${{ needs.check-versions.outputs.do-release == 'true' }} | ||
environment: npm | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
registry-url: https://registry.npmjs.org/ | ||
|
||
- name: Run Unit Tests | ||
if: ${{ github.event.inputs.dry-run == 'false' }} | ||
run: | | ||
npm ci | ||
npm run test | ||
## - name: Run Integration Tests | ||
## run: | | ||
## npm install | ||
## npm run test:integration | ||
|
||
# requires npm which we get from setup-node | ||
- name: Increment version | ||
id: increment-version | ||
run: | | ||
npm version $INPUTS_INCREMENT --no-git-tag-version | ||
echo "new-version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT | ||
# replace placeholder with current values in CHANGELOG.md | ||
# -E extended mode for \s support, -i inplace | ||
# 0,: only operate on the first match. | ||
- name: Replace TBD entry in CHANGELOG.md | ||
env: | ||
NEW_VERSION: ${{ steps.get-version.outputs.new-version }} | ||
run: | | ||
CURRENT_DATE=$(date +%Y-%m-%d) | ||
sed -i -E "0,/^##\s+\[Unreleased\].*$/s//## [${NEW_VERSION}] - ${CURRENT_DATE}/" CHANGELOG.md | ||
- name: Publish to npm | ||
run: npm publish --access public $DRY_RUN_OPTION | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} | ||
|
||
- name: Parse changelog | ||
id: parse-changelog | ||
uses: schwma/[email protected] | ||
with: | ||
version: '${{ steps.increment-version.outputs.new-version }}' | ||
|
||
- name: Create a GitHub release | ||
if: ${{ github.event.inputs.dry-run == 'false' }} | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
tag: 'v${{ steps.increment-version.outputs.new-version }}' | ||
body: '${{ steps.parse-changelog.outputs.body }}' | ||
|
||
# add missing template to change log for new development | ||
# -E extended mode for \s support, -i inplace | ||
# 0,: only operate on the first match. | ||
# & is the matched string | ||
- name: Add version template to CHANGELOG.md | ||
run: | | ||
sed -i -E '0,/^##\s+.*$/s//## [Unreleased]\ | ||
\ | ||
### Added\ | ||
### Changed\ | ||
### Deprecated\ | ||
### Removed\ | ||
### Fixed\ | ||
### Security\ | ||
\ | ||
&/' CHANGELOG.md | ||
# prepare branch | ||
- name: Commit changes | ||
env: | ||
NEW_VERSION: ${{ steps.increment-version.outputs.new-version }} | ||
run: | | ||
git config --global user.name "${GITHUB_ACTOR}" | ||
git config --global user.email "[email protected]" | ||
git add -u . | ||
git commit -m "chore(version): $INPUTS_INCREMENT version $NEW_VERSION" | ||
git push origin $BRANCH $DRY_RUN_OPTION | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 22 | ||
registry-url: https://registry.npmjs.org/ | ||
|
||
- name: Run Unit Tests | ||
if: ${{ github.event.inputs.dry-run == 'false' }} | ||
run: | | ||
npm ci | ||
npm run test | ||
- name: Publish to npm | ||
run: npm publish --access public $DRY_RUN_OPTION | ||
env: | ||
NODE_AUTH_TOKEN: ${{secrets.npm_token}} | ||
|
||
- name: Get Version | ||
id: get-version | ||
run: | | ||
echo "version=$(npm pkg get version | tr -d '"')" >> $GITHUB_OUTPUT | ||
- name: Parse CHANGELOG.md | ||
id: parse-changelog | ||
uses: schwma/[email protected] | ||
with: | ||
version: '${{ steps.get-version.outputs.version }}' | ||
|
||
- name: Create a GitHub release | ||
if: ${{ github.event.inputs.dry-run == 'false' }} | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
tag: 'v${{ steps.get-version.outputs.version }}' | ||
body: '${{ steps.parse-changelog.outputs.body }}' |