Release #216
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 | |
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 }} |