Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Add automated release workflow #1449

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Release

permissions:
contents: write
pull-requests: write

env:
PANDOC_VERSION: 3.1.1.0

on:
pull_request:
types:
- closed
ZenBre4ker marked this conversation as resolved.
Show resolved Hide resolved
branches:
- release

jobs:
release-pr:
# guard against running on forks
if: github.repository == 'TTT-2/TTT2'
ZenBre4ker marked this conversation as resolved.
Show resolved Hide resolved

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 }}
ZenBre4ker marked this conversation as resolved.
Show resolved Hide resolved

- 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'
ZenBre4ker marked this conversation as resolved.
Show resolved Hide resolved
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)
ZenBre4ker marked this conversation as resolved.
Show resolved Hide resolved

- 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 }}
8 changes: 5 additions & 3 deletions RELEASE_PROCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 `<version>`.
1. Copy applicable entries from the `CHANGELOG.md` to the `Describe this release` textarea.
1. Press `Publish release`.
Expand Down
2 changes: 2 additions & 0 deletions gamemodes/terrortown/gamemode/client/cl_changes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading