-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (76 loc) · 3.16 KB
/
release.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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 }}