From 1d463bf56f691b3f504beaf25b515b78ebe9c5c2 Mon Sep 17 00:00:00 2001 From: Histalek <16392835+Histalek@users.noreply.github.com> Date: Sun, 3 Mar 2024 11:50:13 +0100 Subject: [PATCH] ci: Add automated release workflow This is a first draft (with an absolutely horrendous implementation) of automating our release steps after a PR with a `release/*` label has been merged to the `release` branch. Outstanding TODOs: - I 100% need to implement this with some proper file templating and double check all if-conditions. This is a garbled mess (but probably somehow functional ...) - add the actual release tagging to this as well - document the new release process --- .github/workflows/release.yml | 107 ++++++++++++++++++ RELEASE_PROCESS.md | 8 +- .../terrortown/gamemode/client/cl_changes.lua | 2 + 3 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..ca366e8f42 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,107 @@ +name: Release + +permissions: + contents: write + pull-requests: write + +env: + PANDOC_VERSION: 3.1.1.0 + +on: + pull_request: + types: + - closed + branches: + - release + +jobs: + release-pr: + # guard against running on forks + if: github.repository == 'TTT-2/TTT2' + + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Check if PR was merged + uses: actions-ecosystem/action-release-label@v1 + id: release-label + if: ${{ github.event.pull_request.merged == true }} + + - name: Get latest tag if a release label exists on last merged PR + uses: actions-ecosystem/action-get-latest-tag@v1 + id: get-latest-tag + if: ${{ steps.release-label.outputs.level != null }} + + - name: Bump semver tag according to detected release label + uses: actions-ecosystem/action-bump-semver@v1 + id: bump-semver + if: ${{ steps.release-label.outputs.level != null }} + with: + current_version: ${{ steps.get-latest-tag.outputs.tag }} + level: ${{ steps.release-label.outputs.level }} + + - name: Generate app token + uses: actions/create-github-app-token@v1 + id: generate-token + if: ${{ steps.release-label.outputs.level != null }} + with: + app-id: ${{ secrets.APP_ID }} + private-key: ${{ secrets.APP_PRIVATE_KEY }} + + - name: Add release heading (version, tag link and date) to CHANGELOG.md + run: 'sed -i "/^## Unreleased$/a\\\n## [v${TTT2_VERSION}](https://github.com/TTT-2/TTT2/tree/v${TTT2_VERSION}) ($(date +%Y-%m-%d))" CHANGELOG.md' + if: ${{ steps.release-label.outputs.level != null }} + env: + TTT2_VERSION: ${{ steps.bump-semver.outputs.new_version }} + + - name: Generate html from changelog for cl_changes.lua + uses: "docker://docker.io/pandoc/core:${PANDOC_VERSION}" + if: ${{ steps.release-label.outputs.level != null }} + with: + args: >- + --output=output.html + --read=markdown_strict + <(sed -e '1,/^## \[/d' -e '/^## \[/,$d' CHANGELOG.md) + + - name: Stuff lua stuff around html changes + run: | + sed -i + -e "1i \\AddChange(\n"TTT2 Base - ${TTT2_VERSION}",\n[[" + -e "\$a\\\\n]],\nos.time({ year = $(date +%Y), month = $(date +%m), day = $(date +%d) })\n)\n" + output.html + env: + TTT2_VERSION: ${{ steps.bump-semver.outputs.new_version }} + + - name: Update cl_changes.lua + run: "sed -i '/--#endofchanges/e cat output.html' gamemodes/terrortown/gamemode/client/cl_changes.lua" + if: ${{ steps.release-label.outputs.level != null }} + env: + TTT2_VERSION: ${{ steps.bump-semver.outputs.new_version }} + + - name: Update GM.Version in sh_init.lua + run: 'sed -i "s/^GM\.Version = \".*\"$/GM\.Version = \"${TTT2_VERSION}\"/" gamemodes/terrortown/gamemode/shared/sh_init.lua' + if: ${{ steps.release-label.outputs.level != null }} + env: + TTT2_VERSION: ${{ steps.bump-semver.outputs.new_version }} + + - name: Create Pull Request + id: ci-release + uses: peter-evans/create-pull-request@v6 + if: ${{ steps.release-label.outputs.level != null }} + with: + token: ${{ steps.generate-token.outputs.token }} + add-paths: | + "CHANGELOG.md" + "gamemodes/terrortown/gamemode/client/cl_changes.lua" + "gamemodes/terrortown/gamemode/shared/sh_init.lua" + commit-message: "Release ${TTT2_VERSION}" + branch: ci-automated-release + title: "[Release] ${TTT2_VERSION}" + body: | + Auto-generated by github actions. + Please do not add a `release/*` label to this PR. + env: + TTT2_VERSION: ${{ steps.bump-semver.outputs.new_version }} diff --git a/RELEASE_PROCESS.md b/RELEASE_PROCESS.md index 164549ade9..15a6b3c776 100644 --- a/RELEASE_PROCESS.md +++ b/RELEASE_PROCESS.md @@ -5,8 +5,10 @@ TTT2 versioning is based on semantic-versioning. Prefixing versions with a `v` to indicate it is a version number and appending a `b` to indicate its beta status. -The latest release will be published to the Steam Workshop in form of an [addon](https://steamcommunity.com/sharedfiles/filedetails/?id=1357204556). -The latest development will be accessible on this repository's master branch. +- The latest release will be published to the Steam Workshop in form of an [addon](https://steamcommunity.com/sharedfiles/filedetails/?id=1357204556). +- The latest release should be represented by the state in the release branch. + - The release tag points to the respective commit. +- The latest development will be accessible on this repository's default branch. ## Release steps @@ -48,7 +50,7 @@ The following steps will document our release process to prevent mistakes and co 1. Draft a new Github release. - 1. Target the `master` branch. + 1. Target the `release` branch. 1. Supply both `Tag version` and `Release title` with ``. 1. Copy applicable entries from the `CHANGELOG.md` to the `Describe this release` textarea. 1. Press `Publish release`. diff --git a/gamemodes/terrortown/gamemode/client/cl_changes.lua b/gamemodes/terrortown/gamemode/client/cl_changes.lua index f3bf934ed1..f0f0b0bfa2 100644 --- a/gamemodes/terrortown/gamemode/client/cl_changes.lua +++ b/gamemodes/terrortown/gamemode/client/cl_changes.lua @@ -2024,6 +2024,8 @@ function CreateChanges() os.time({ year = 2024, month = 02, day = 27 }) ) + --#endofchanges + --- -- run hook for other addons to add their changelog as well -- @realm client