Release #73
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 | |
permissions: | |
contents: write | |
on: | |
workflow_dispatch: | |
inputs: | |
dryRun: | |
description: 'Dry Run' | |
required: true | |
type: boolean | |
default: true | |
releaseVersion: | |
description: 'Custom Version (major.minor.patch; leave empty for automatic determination)' | |
required: true | |
type: choice | |
default: 'auto' | |
options: | |
- 'auto' | |
# - 'major' | |
# - 'minor' | |
# - 'patch' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
jobs: | |
summary: | |
runs-on: ubuntu-latest | |
steps: | |
- run: | | |
echo "DryRun: ${{ inputs.dryRun }}" >> $GITHUB_STEP_SUMMARY | |
echo "ReleaseVersion: ${{ inputs.releaseVersion }}" >> $GITHUB_STEP_SUMMARY | |
echo "Branch: ${{ github.ref }}" >> $GITHUB_STEP_SUMMARY | |
analyse-changed-services: | |
uses: ./.github/workflows/get-changed-services.yaml | |
release: | |
needs: [analyse-changed-services] | |
runs-on: ubuntu-latest | |
if: ${{ needs.analyse-changed-services.outputs.CHANGED_PACKAGES != '[]' && needs.analyse-changed-services.outputs.CHANGED_PACKAGES != ''}} | |
strategy: | |
fail-fast: false | |
max-parallel: 1 | |
matrix: | |
package: ${{fromJson(needs.analyse-changed-services.outputs.CHANGED_PACKAGES)}} | |
steps: | |
- name: Checkout Repo | |
uses: actions/checkout@v4 | |
with: | |
ref: | |
fetch-depth: 0 | |
token: ${{ secrets.PAT }} # use PAT to being able to push to protected branch later on | |
- name: Checkout latest default branch | |
run: | | |
git checkout ${{ github.event.repository.default_branch }} | |
git pull origin ${{ github.event.repository.default_branch }} | |
if: ${{ contains(github.ref, github.event.repository.default_branch) }} | |
- uses: pnpm/action-setup@v2 | |
with: | |
version: 8 | |
run_install: false | |
- run: echo "package=${{ matrix.package }}" | |
- name: Get pnpm store directory | |
id: pnpm-store | |
run: | | |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT | |
- uses: actions/cache@v3 | |
name: Setup pnpm cache | |
with: | |
path: ${{ steps.pnpm-store.outputs.STORE_PATH }} | |
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} | |
restore-keys: | | |
${{ runner.os }}-pnpm-store- | |
- name: get directory for package | |
id: get-directory | |
run: | | |
directory=$(pnpm ls -r --json --filter $MATRIX_PACKAGE | jq -r '.[0] | .path') | |
directory="${directory##*/democracy-development/}" | |
# Ausgabe | |
echo "directory=$directory" >> $GITHUB_OUTPUT | |
echo "directory=$directory" | |
env: | |
MATRIX_PACKAGE: ${{ matrix.package }} | |
- name: Fetch tags | |
run: git fetch --tags | |
- name: Configure CI Git User | |
run: | | |
git config user.name "Manuel Ruck" | |
git config user.email "[email protected]" | |
git config push.followTags true | |
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/$GITHUB_REPOSITORY | |
env: | |
GITHUB_TOKEN: ${{ secrets.PAT }} | |
- name: Get changelog | |
id: get_changelog | |
run: | | |
changelog='' | |
if ( ${{ inputs.releaseVersion == 'auto' }} ); then | |
changelog=`pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --dry-run | sed -n '/^---$/,/^---$/p' | grep -v '^---$'` | |
else | |
changelog=`pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --release-as '${{ inputs.releaseVersion }}' --dry-run | sed -n '/^---$/,/^---$/p' | grep -v '^---$'` | |
fi | |
echo "$changelog" | |
echo "$changelog" >> $GITHUB_STEP_SUMMARY | |
echo "$changelog" >> /tmp/CHANGELOG.md | |
{ | |
echo 'CHANGELOG<<EOF' | |
echo $changelog | |
echo EOF | |
} >> "$GITHUB_ENV" | |
echo 'CHANGELOG<<EOF' >> $GITHUB_ENV | |
echo $changelog >> $GITHUB_ENV | |
echo 'EOF' >> $GITHUB_ENV | |
working-directory: ${{ steps.get-directory.outputs.directory }} | |
env: | |
MATRIX_PACKAGE: ${{ matrix.package }} | |
- name: Determine next version number | |
if: inputs.releaseVersion == 'auto' | |
id: determine_next_version | |
run: | | |
nextVersion=`pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --dry-run | sed -n '/^---$/,/^---$/p' | grep -P -o '(\d+\.)(\d+\.)(\d+)' | head -n 1` | |
echo "$nextVersion" | |
echo "NEXT_VERSION=$nextVersion" >> $GITHUB_OUTPUT | |
working-directory: ${{ steps.get-directory.outputs.directory }} | |
env: | |
MATRIX_PACKAGE: ${{ matrix.package }} | |
# - name: Manually next version number | |
# if: inputs.releaseVersion != 'auto' | |
# run: | | |
# echo "NEXT_VERSION=${{ inputs.releaseVersion }}" >> $GITHUB_ENV | |
# echo "$NEXT_VERSION" | |
- name: bump version - DRY RUN | |
if: inputs.dryRun == true | |
run: | | |
if ( ${{ inputs.releaseVersion == 'auto' }} ); then | |
pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --dry-run | |
else | |
pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --release-as '${{ inputs.releaseVersion }}' --dry-run | |
fi | |
working-directory: ${{ steps.get-directory.outputs.directory }} | |
env: | |
MATRIX_PACKAGE: ${{ matrix.package }} | |
- name: bump version - AUTOMATIC | |
if: inputs.dryRun == false && inputs.releaseVersion == 'auto' | |
run: pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v | |
working-directory: ${{ steps.get-directory.outputs.directory }} | |
env: | |
MATRIX_PACKAGE: ${{ matrix.package }} | |
# - name: bump version - MANUAL VERSION NO. | |
# if: inputs.dryRun == false && inputs.releaseVersion != 'auto' | |
# run: pnpm dlx commit-and-tag-version --path . -t $MATRIX_PACKAGE@v --release-as '${{ inputs.releaseVersion }}' | |
# working-directory: ${{ steps.get-directory.outputs.directory }} | |
# env: | |
# MATRIX_PACKAGE: ${{ matrix.package }} | |
- name: Publish tag # only possible on default branch | |
if: inputs.dryRun == false | |
run: | | |
if ( ${{ contains(github.ref, github.event.repository.default_branch) }} ); then | |
git push --follow-tags origin ${{ github.event.repository.default_branch }} | |
else | |
exit 1 | |
fi | |
- name: Create release | |
uses: actions/github-script@v6 | |
if: inputs.dryRun == false | |
env: | |
TAG: ${{ matrix.package }}@v${{ steps.determine_next_version.outputs.NEXT_VERSION }} | |
with: | |
github-token: '${{ secrets.GITHUB_TOKEN }}' | |
script: | | |
const fs = require('fs'); | |
const { TAG } = process.env; | |
const body = fs.readFileSync('/tmp/CHANGELOG.md', 'utf8'); | |
try { | |
const response = await github.rest.repos.createRelease({ | |
draft: false, | |
generate_release_notes: false, | |
name: `${TAG}`, | |
owner: context.repo.owner, | |
prerelease: false, | |
repo: context.repo.repo, | |
tag_name: `${TAG}`, | |
body: body.replace('\n', '<br />'), | |
}); | |
} catch (error) { | |
core.setFailed(error.message); | |
} |