-
Notifications
You must be signed in to change notification settings - Fork 4
215 lines (191 loc) · 8.22 KB
/
build-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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
name: Release
on:
workflow_dispatch:
inputs:
tag:
description: "Tag / Release name (leave empty for dry-run)"
required: false
env:
python-version: "3.10"
modimporter-version: "1.6.1"
name: hephaistos
data: hephaistos-data
changelog: CHANGELOG.md
config: hephaistos/config.py
windows-version-info: windows_version_info.py
artifacts-content-type: application/zip
jobs:
tag-and-release:
name: Rotate changelog, tag, and create release
runs-on: ubuntu-latest
env:
release-notes: release-notes.md
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
steps:
- name: Checkout files
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
- name: Set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d
with:
python-version: ${{ env.python-version }}
- name: Build release notes
env:
prog: |
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)
if found:
print(found.group('notes'))
run: |
python -c "${{ env.prog }}" > ${{ env.release-notes }}
- name: Rotate unreleased section in changelog
if: github.event.inputs.tag
uses: thomaseizinger/keep-a-changelog-new-release@77ac767b2f7f6edf2ee72ab3364ed26667086f96
with:
tag: ${{ github.event.inputs.tag }}
- name: Rotate version in Hephaistos config and Windows executable version info
if: github.event.inputs.tag
run: |
sed -i "s/VERSION = '.*'/VERSION = '${{ github.event.inputs.tag }}'/" ${{ env.config }}
TAG=${{ github.event.inputs.tag }}
TAG_WITHOUT_V=${TAG:1}
WINDOWS_TAG=${TAG_WITHOUT_V//./, }
sed -i "s/filevers=(.*)/filevers=(${WINDOWS_TAG}, 0)/" ${{ env.windows-version-info }}
sed -i "s/prodvers=(.*)/prodvers=(${WINDOWS_TAG}, 0)/" ${{ env.windows-version-info }}
sed -i "s/u'FileVersion', u'.*'/u'FileVersion', u'${TAG_WITHOUT_V}'/" ${{ env.windows-version-info }}
sed -i "s/u'ProductVersion', u'.*'/u'ProductVersion', u'${TAG_WITHOUT_V}'/" ${{ env.windows-version-info }}
- name: Push updated changelog and files to repository
if: github.event.inputs.tag
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.config }} ${{ env.windows-version-info }}
git commit --message "Release ${{ github.event.inputs.tag }}"
git push origin HEAD:main
- name: Tag
if: github.event.inputs.tag
run: |
git tag ${{ github.event.inputs.tag }}
git push origin --tags
- name: Create release
if: github.event.inputs.tag
id: release
uses: actions/create-release@0cb9c9b65d5d1901c1f53e5e66eaf4afd303e70e
with:
release_name: ${{ github.event.inputs.tag }}
tag_name: ${{ github.event.inputs.tag }}
body_path: ${{ env.release-notes }}
commitish: main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
archive-and-upload-python-artifacts:
name: Archive and upload Python artifacts
needs: tag-and-release
runs-on: ubuntu-latest
env:
artifacts-name: hephaistos-python.zip
files-bundled: "LICENSE README.md"
sjson: sjson
steps:
- name: Checkout files
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
ref: ${{ github.event.inputs.tag || github.sha }}
submodules: true
- name: Consolidate Python artifacts in a zip
run: |
rm -r ${{ env.sjson }}/.git
mv ${{ env.files-bundled }} ${{ env.name }}
zip ${{ env.artifacts-name }} -r ${{ env.name }} ${{ env.data }} ${{ env.sjson }}
- name: Upload artifacts to workflow
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808
with:
name: ${{ env.artifacts-name }}
path: ${{ env.artifacts-name }}
retention-days: 1
- name: Upload artifacts to release
if: needs.tag-and-release.outputs.upload_url
uses: actions/upload-release-asset@e8f9f06c4b078e705bd2ea027f0926603fc9b4d5
with:
upload_url: ${{ needs.tag-and-release.outputs.upload_url }}
asset_path: ${{ env.artifacts-name }}
asset_name: ${{ env.artifacts-name }}
asset_content_type: ${{ env.artifacts-content-type }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-upload-binaries:
name: Build and upload binaries
needs: tag-and-release
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-20.04]
include:
- os: windows-latest
pip-cache-path: ~\AppData\Local\pip\Cache
artifacts-name: hephaistos-windows.zip
pyinstaller-version: "4.6"
pyinstaller-extra-args: --add-data "hephaistos-data;hephaistos-data" --version-file windows_version_info.py
- os: macos-latest
pip-cache-path: ~/Library/Caches/pip
artifacts-name: hephaistos-macos.zip
pyinstaller-version: "5.3"
pyinstaller-extra-args: --add-data "hephaistos-data:hephaistos-data"
- os: ubuntu-20.04
pip-cache-path: ~/.cache/pip
artifacts-name: hephaistos-linux.zip
pyinstaller-version: "5.3"
pyinstaller-extra-args: --add-data "hephaistos-data:hephaistos-data"
steps:
- name: Checkout files
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
with:
ref: ${{ github.event.inputs.tag || github.sha }}
submodules: true
- name: Set up Python
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d
with:
python-version: ${{ env.python-version }}
- name: Retrieve pip dependencies from cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
with:
path: |
${{ env.pythonLocation }}\lib\site-packages
${{ matrix.pip-cache-path }}
key: ${{ runner.os }}-pip-cache-${{ matrix.pyinstaller-version }}
- name: Install pip dependencies
run: pip install pyinstaller==${{ matrix.pyinstaller-version }}
- name: Download modimporter dependency
run: |
curl -LO https://github.com/SGG-Modding/sgg-mod-modimporter/releases/download/${{ env.modimporter-version }}/modimporter-python.zip
7z x modimporter-python.zip modimporter.py
- name: Build binaries with PyInstaller
run: python -m PyInstaller --onefile ${{ env.name }}/__main__.py --name ${{ env.name }} --hidden-import "modimporter" ${{ matrix.pyinstaller-extra-args }}
- name: Consolidate artifacts in a zip
if: startsWith(runner.os, 'Windows')
run: Compress-Archive dist/${{ env.name }}.exe ${{ matrix.artifacts-name }}
- name: Consolidate artifacts in a zip
if: startsWith(runner.os, 'macOS') || startsWith(runner.os, 'Linux')
run: |
mv ${{ env.name }} ${{ env.name }}-dir
mv dist/${{ env.name }} .
zip ${{ matrix.artifacts-name }} -r ${{ env.name }}
- name: Upload artifacts to workflow
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808
with:
name: ${{ matrix.artifacts-name }}
path: ${{ matrix.artifacts-name }}
retention-days: 1
- name: Upload artifacts to release
if: needs.tag-and-release.outputs.upload_url
uses: actions/upload-release-asset@e8f9f06c4b078e705bd2ea027f0926603fc9b4d5
with:
upload_url: ${{ needs.tag-and-release.outputs.upload_url }}
asset_path: ${{ matrix.artifacts-name }}
asset_name: ${{ matrix.artifacts-name }}
asset_content_type: ${{ env.artifacts-content-type }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}