mirror of
https://github.com/Cockatrice/Magic-Token.git
synced 2026-03-21 17:46:06 -05:00
85 lines
3.0 KiB
YAML
85 lines
3.0 KiB
YAML
name: Update version on tokens.xml changes
|
|
|
|
on:
|
|
push:
|
|
branches: [ master ]
|
|
paths:
|
|
- 'tokens.xml'
|
|
- 'version.txt'
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: ${{ !contains(github.ref, '/master') }}
|
|
|
|
jobs:
|
|
update_version:
|
|
if: "!startsWith(github.event.head_commit.message, 'Update version to ')"
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v6
|
|
|
|
- name: Get previous version
|
|
id: get_versions
|
|
shell: bash
|
|
run: |
|
|
old_version="$(<version.txt)"
|
|
current_date="$(date --utc +%Y%m%d)"
|
|
echo "old_version=$old_version" >> $GITHUB_OUTPUT
|
|
echo "current_date=$current_date" >> $GITHUB_OUTPUT
|
|
|
|
- name: Compute new version
|
|
id: compute_version
|
|
shell: python
|
|
run: |
|
|
import os, re
|
|
old_version = "${{steps.get_versions.outputs.old_version}}"
|
|
current_date = "${{steps.get_versions.outputs.current_date}}"
|
|
new_version = current_date
|
|
if old_version.startswith(current_date):
|
|
match = re.search(r"[a-z]+", old_version)
|
|
if match is None:
|
|
suffix = "a" # the first a is actually hidden
|
|
else:
|
|
suffix = match[0]
|
|
charlist = []
|
|
rev = reversed(suffix)
|
|
for char in rev:
|
|
if char == "z":
|
|
charlist.append("a")
|
|
else:
|
|
nextchar = chr(ord(char) + 1)
|
|
charlist.append(nextchar)
|
|
charlist.extend(rev)
|
|
break
|
|
else:
|
|
charlist.append("a")
|
|
new_version += "".join(reversed(charlist))
|
|
with open(os.environ["GITHUB_OUTPUT"], "a") as envFile:
|
|
print(f"new_version={new_version}", file=envFile)
|
|
|
|
- name: Update version in files
|
|
shell: bash
|
|
env:
|
|
VERSION_OLD: ${{steps.get_versions.outputs.old_version}}
|
|
VERSION_NEW: ${{steps.compute_version.outputs.new_version}}
|
|
run: |
|
|
echo "Updating version from $VERSION_OLD to $VERSION_NEW"
|
|
tag="sourceVersion"
|
|
sed -i "s?<$tag>.*</$tag>?<$tag>$VERSION_NEW</$tag>?" tokens.xml
|
|
echo "$VERSION_NEW" >version.txt
|
|
|
|
- name: Commit and push changes
|
|
shell: bash
|
|
env:
|
|
VERSION_NEW: ${{steps.compute_version.outputs.new_version}}
|
|
run: |
|
|
echo "::notice::Triggering commit: https://github.com/${GITHUB_REPOSITORY}/commit/$GITHUB_SHA"
|
|
git config user.name github-actions
|
|
git config user.email github-actions@github.com
|
|
git add tokens.xml version.txt
|
|
git commit -m "Update version to $VERSION_NEW" -m "Bump triggered by commit $GITHUB_SHA"
|
|
git push
|
|
commit_hash="$(git rev-parse HEAD)"
|
|
echo "::notice::Pushed commit: https://github.com/${GITHUB_REPOSITORY}/commit/$commit_hash"
|