Skip to content

Release

Release #18

Workflow file for this run

name: Release
on:
workflow_dispatch:
inputs:
tag:
description: "Tag / Version number (leave empty for dry-run)"
required: true
env:
python-version: "3.12"
changelog: CHANGELOG.md
readme: README.md
config: thunderstore.toml
plugin: src/Plugin.cs
jobs:
tag-and-release:
name: Rotate changelog, version, tag, and create release
runs-on: ubuntu-latest
if: github.event.inputs.tag
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
steps:
- name: Checkout files
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- name: Set up Python
uses: actions/setup-python@13ae5bb136fac2878aff31522b9efb785519f984
with:
python-version: ${{ env.python-version }}
- name: Build release notes
shell: python
run: |
import os
from pathlib import Path
import re
regex = re.compile(r'## \[Unreleased\]\s+(?P<notes>.*?)\s+## ', re.DOTALL)
changelog = Path('${{ env.changelog }}').read_text()
found = regex.search(changelog)
def set_env(name, value):
with open(os.environ['GITHUB_ENV'], 'a') as f:
delimiter = "EOF"
print(f'{name}<<{delimiter}', file=f)
print(value, file=f)
print(delimiter, file=f)
if found:
notes = found.group('notes')
set_env("release-notes", notes)
- name: Rotate unreleased section in changelog
uses: thomaseizinger/keep-a-changelog-new-release@5bc232893483441c5d6cd6c9dcb1e48abf9a2bae
with:
tag: ${{ github.event.inputs.tag }}
- name: Rotate version
run: |
sed -i 's;nbusseneau/Better_Cartography_table/[0-9]\+.[0-9]\+.[0-9]\+;nbusseneau/Better_Cartography_table/${{ github.event.inputs.tag }}.zip;g' ${{ env.readme }}
sed -i 's/nbusseneau-Better_Cartography_Table-[0-9]\+.[0-9]\+.[0-9]\+.zip/nbusseneau-Better_Cartography_Table-${{ github.event.inputs.tag }}.zip/g' ${{ env.readme }}
sed -i 's/versionNumber = ".*"/versionNumber = "${{ github.event.inputs.tag }}"/' ${{ env.config }}
sed -i 's/ModVersion = ".*"/ModVersion = "${{ github.event.inputs.tag }}"/' ${{ env.plugin }}
- name: Push updated files to repository
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add ${{ env.changelog }} ${{ env.readme }} ${{ env.config }} ${{ env.plugin }}
git commit --message "Release ${{ github.event.inputs.tag }}"
git push origin HEAD:main
- name: Tag
run: |
git tag ${{ github.event.inputs.tag }}
git push origin --tags
- name: Create release
id: release
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e
with:
release_name: ${{ github.event.inputs.tag }}
tag_name: ${{ github.event.inputs.tag }}
body: ${{ env.release-notes }}
commitish: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}