GitHub release #72
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
# This workflow will create the release artifact and a release on GitHub | |
name: GitHub release | |
on: | |
# allows job to be run manually from actions tab | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: 'Version' | |
jobs: | |
build_artefact: | |
runs-on: ubuntu-latest | |
steps: | |
# checks out main into $GITHUB_WORKSPACE | |
- name: checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: '${{ github.event.inputs.tag }}' | |
path: 'TravelWindowII' | |
# create a zip as a release archive | |
- name: create release archive | |
uses: thedoctor0/zip-release@master | |
with: | |
filename: 'TravelWindowII-${{ github.event.inputs.tag }}.zip' | |
exclusions: '*.git* *.github* *.vscode* *.gitignore* /*doc/* /*screenshots/*' | |
# parse changelog to set release description | |
- name: extract latest changelog entry | |
id: changelog | |
run: | | |
# Find the line number of the latest version header | |
LATEST_VERSION_LINE=$(grep -n "^## v" CHANGELOG.md | head -n1 | cut -d: -f1) | |
# Find the line number of the next version header or EOF | |
NEXT_VERSION_LINE=$(tail -n +$((LATEST_VERSION_LINE + 1)) CHANGELOG.md | grep -n "^## v" | head -n1 | cut -d: -f1) | |
if [ -z "$NEXT_VERSION_LINE" ]; then | |
NEXT_VERSION_LINE=$(wc -l < CHANGELOG.md) | |
else | |
NEXT_VERSION_LINE=$((LATEST_VERSION_LINE + NEXT_VERSION_LINE - 1)) | |
fi | |
# Extract the content between these line numbers | |
CHANGELOG_CONTENT=$(sed -n "${LATEST_VERSION_LINE},${NEXT_VERSION_LINE}p" CHANGELOG.md) | |
# Escape newlines and quote special characters for GitHub Actions | |
CHANGELOG_CONTENT="${CHANGELOG_CONTENT//'%'/'%25'}" | |
CHANGELOG_CONTENT="${CHANGELOG_CONTENT//$'\n'/'%0A'}" | |
CHANGELOG_CONTENT="${CHANGELOG_CONTENT//$'\r'/'%0D'}" | |
# Set output for use in subsequent steps | |
echo "::set-output name=content::$CHANGELOG_CONTENT" | |
# create the GitHub release | |
- name: create github release | |
uses: softprops/action-gh-release@v2 | |
with: | |
draft: true | |
prerelease: false | |
name: ${{ github.event.inputs.tag }} | |
tag_name: ${{ github.event.inputs.tag }} | |
body: ${{ steps.changelog.outputs.content }} | |
files: 'TravelWindowII-${{ github.event.inputs.tag }}.zip' |