Skip to content

Create Releases

Create Releases #170

# creates a new release for LIVE and PTU channel every day at 4am when the corresponding global.ini
# was changed in the last 24 hours
#
# steps:
# 1. checkout the code
# 2. count the commits for the global.ini in the last 24 hours
# 3. get the current date
# - the following steps are only run then the commit count is > 0
# 4. create a release name with the correct version in it
# 5. create the zip
# 6. create the release
name: Create Releases
on:
workflow_dispatch: # used only to manually trigger the workflow from the GitHub website
inputs:
tag:
description: "Release Tag"
type: string
schedule:
- cron: "0 3 * * *"
jobs:
get_context_info:
name: Get Context Info
runs-on: ubuntu-latest
outputs:
DATE: ${{ steps.date.outputs.DATE }}
DATE_REV: ${{ steps.date_rev.outputs.DATE_REV }}
TIME: ${{ steps.time.outputs.TIME }}
NEW_COMMIT_COUNT_PTU: ${{ steps.new_commits_ptu.outputs.NEW_COMMIT_COUNT_PTU }}
NEW_COMMIT_COUNT_LIVE: ${{ steps.new_commits_live.outputs.NEW_COMMIT_COUNT_LIVE }}
COMMIT_PTU: ${{ steps.commit_ptu.outputs.COMMIT_PTU }}
COMMIT_LIVE: ${{ steps.commit_live.outputs.COMMIT_LIVE }}
RELEASE_TITLE_PTU: ${{ steps.title_ptu.outputs.RELEASE_TITLE_PTU }}
RELEASE_TITLE_LIVE: ${{ steps.title_live.outputs.RELEASE_TITLE_LIVE }}
LINK_PTU: ${{ steps.link_ptu.outputs.LINK_PTU }}
LINK_LIVE: ${{ steps.link_live.outputs.LINK_LIVE }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set Timezone
id: timezone
run: sudo timedatectl set-timezone Europe/Berlin
- name: Get Date
id: date
run: echo "DATE=$(date '+%d.%m.%y')" >> $GITHUB_OUTPUT
- name: Get Date Reverse
id: date_rev
run: echo "DATE_REV=$(date '+%y.%m.%d')" >> $GITHUB_OUTPUT
- name: Get Time
id: time
run: echo "TIME=$(date '+%H:%M')" >> $GITHUB_OUTPUT
- name: Count New Commits On PTU # counts the commits to ptu/global.ini during the last 24 hours
id: new_commits_ptu
run: echo "NEW_COMMIT_COUNT_PTU=$(git log --oneline --since '24 hours ago' -- ptu/global.ini | wc -l)" >> $GITHUB_OUTPUT
- name: Count New Commits On LIVE # counts the commits to live/global.ini during the last 24 hours
id: new_commits_live
run: echo "NEW_COMMIT_COUNT_LIVE=$(git log --oneline --since '24 hours ago' -- live/global.ini | wc -l)" >> $GITHUB_OUTPUT
- name: Get Commit On PTU
id: commit_ptu
run: echo "COMMIT_PTU=$(git log --pretty=format:'%H' -n 1 --since '24 hours ago' -- ptu/global.ini)" >> $GITHUB_OUTPUT
- name: Get Commit On LIVE
id: commit_live
run: echo "COMMIT_LIVE=$(git log --pretty=format:'%H' -n 1 --since '24 hours ago' -- live/global.ini)" >> $GITHUB_OUTPUT
- name: Create Release Title For PTU
id: title_ptu # creates a title for the release that shows the version number used in the title of the last commit that changed the ptu/global.ini
if: steps.new_commits_ptu.outputs.NEW_COMMIT_COUNT_PTU > 0
# run: echo "RELEASE_TITLE_PTU=$(cat 'en/ptu/build.ptu')" >> $GITHUB_OUTPUT
run: |
if [$(git log -1 --pretty=%s -- ptu/global.ini | grep "|") == ""]
then
echo "RELEASE_TITLE_PTU=${{ vars.RELEASE_TITLE_PTU }}" >> $GITHUB_OUTPUT
else
echo "RELEASE_TITLE_PTU=$(git log -1 --pretty=%s -- ptu/global.ini | cut -s -d'|' -f1 | rev | cut -c 2- | rev)" >> $GITHUB_OUTPUT
fi
- name: Create Release Title For LIVE
id: title_live # creates a title for the release that shows the version number used in the title of the last commit that changed the live/global.ini
if: steps.new_commits_live.outputs.NEW_COMMIT_COUNT_LIVE > 0
# run: echo "RELEASE_TITLE_LIVE=$(cat 'en/live/build.live')" >> $GITHUB_OUTPUT
run: |
if [$(git log -1 --pretty=%s -- live/global.ini | grep "|") == ""]
then
echo "RELEASE_TITLE_LIVE=${{ vars.RELEASE_TITLE_LIVE }}" >> $GITHUB_OUTPUT
else
echo "RELEASE_TITLE_LIVE=$(git log -1 --pretty=%s -- live/global.ini | cut -s -d'|' -f1 | rev | cut -c 2- | rev)" >> $GITHUB_OUTPUT
fi
- name: Get Last Tag On PTU
id: tag_PTU
run: echo "TAG_PTU=$(git tag --sort=creatordate --list '*-PTU' | tail -1)" >> $GITHUB_OUTPUT
- name: Get Last Tag On LIVE
id: tag_live
run: echo "TAG_LIVE=$(git tag --sort=creatordate --list '*-LIVE' | tail -1)" >> $GITHUB_OUTPUT
- name: Create Compare Link For PTU
id: link_ptu
run: echo "LINK_PTU=https://github.com/${{ github.repository }}/compare/${{ steps.tag_PTU.outputs.TAG_PTU }}...${{ steps.date_rev.outputs.DATE_REV }}-PTU" >> $GITHUB_OUTPUT
- name: Create Compare Link For LIVE
id: link_live
run: echo "LINK_LIVE=https://github.com/${{ github.repository }}/compare/${{ steps.tag_live.outputs.TAG_LIVE }}...${{ steps.date_rev.outputs.DATE_REV }}-LIVE" >> $GITHUB_OUTPUT
- name: Show Variables
id: show_variable
run: |
echo "Date: ${{ steps.date.outputs.DATE }}"
echo "Date Reverse: ${{ steps.date_rev.outputs.DATE_REV }}"
echo "Time: ${{ steps.time.outputs.TIME }}"
echo "New Commits On PTU: ${{ steps.new_commits_ptu.outputs.NEW_COMMIT_COUNT_PTU }}"
echo "New Commits On LIVE: ${{ steps.new_commits_live.outputs.NEW_COMMIT_COUNT_LIVE }}"
echo "Commit On PTU: ${{ steps.commit_ptu.outputs.COMMIT_PTU }}"
echo "Commit On LIVE: ${{ steps.commit_live.outputs.COMMIT_LIVE }}"
echo "Release Title PTU: ${{ steps.title_ptu.outputs.RELEASE_TITLE_PTU }}"
echo "Release Title LIVE: ${{ steps.title_live.outputs.RELEASE_TITLE_LIVE }}"
echo "Last Tag on PTU: ${{ steps.tag_PTU.outputs.TAG_PTU }}"
echo "Last Tag on LIVE: ${{ steps.tag_live.outputs.TAG_LIVE }}"
echo "Changelog Link for PTU: ${{ steps.link_ptu.outputs.LINK_PTU }}"
echo "Changelog Link for LIVE: ${{ steps.link_live.outputs.LINK_LIVE }}"
ptu_release: # runs only when ptu/global.ini was changed in the last 24 hours
name: Create PTU Release
runs-on: ubuntu-latest
needs: get_context_info
if: (vars.TRIGGER_PTU_RELEASE == 1) && (needs.get_context_info.outputs.NEW_COMMIT_COUNT_PTU > 0)
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ needs.get_context_info.outputs.COMMIT_PTU }}
- name: Create ZIP For PTU
run: |
sudo timedatectl set-timezone Europe/Berlin
mkdir release
cp "ptu/user.cfg" "release"
mkdir -p "release/data/Localization/german_(germany)"
cp "ptu/global.ini" "release/data/Localization/german_(germany)/"
cd release
echo "${{ vars.VERSION_FILE_TEXT_PTU }} ${{ needs.get_context_info.outputs.RELEASE_TITLE_PTU }} ${{ needs.get_context_info.outputs.DATE }} - ${{ needs.get_context_info.outputs.TIME }} Uhr" >> Version.txt
zip -r -9 "../${{ vars.ZIP_NAME_PTU }}" *
- name: Create Release For PTU
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.WORKFLOW_TOKEN }}
tag: ${{ inputs.tag || needs.get_context_info.outputs.DATE_REV }}-PTU
commit: ${{ needs.get_context_info.outputs.COMMIT_PTU }}
name: ${{ needs.get_context_info.outputs.RELEASE_TITLE_PTU }}
body: ${{ vars.RELEASE_BODY_PTU }}(${{ needs.get_context_info.outputs.LINK_PTU }})
artifacts: ${{ vars.ZIP_NAME_PTU }}
live_release: # runs only when live/global.ini was changed in the last 24 hours
name: Create LIVE Release
runs-on: ubuntu-latest
needs: [get_context_info, ptu_release]
if: always() && (needs.get_context_info.outputs.NEW_COMMIT_COUNT_LIVE > 0)
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
ref: ${{ needs.get_context_info.outputs.COMMIT_LIVE }}
- name: Create ZIP For LIVE
run: |
sudo timedatectl set-timezone Europe/Berlin
mkdir release
cp "live/user.cfg" "release"
mkdir -p "release/data/Localization/german_(germany)"
cp "live/global.ini" "release/data/Localization/german_(germany)/"
cd release
echo "${{ vars.VERSION_FILE_TEXT_LIVE }} ${{ needs.get_context_info.outputs.RELEASE_TITLE_LIVE }} ${{ needs.get_context_info.outputs.DATE }} - ${{ needs.get_context_info.outputs.TIME }} Uhr" >> Version.txt
zip -r -9 "../${{ vars.ZIP_NAME_LIVE }}" *
- name: Create Release For LIVE
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.WORKFLOW_TOKEN }}
tag: ${{ inputs.tag || needs.get_context_info.outputs.DATE_REV }}-LIVE
commit: ${{ needs.get_context_info.outputs.COMMIT_LIVE }}
name: ${{ needs.get_context_info.outputs.RELEASE_TITLE_LIVE }}
body: ${{ vars.RELEASE_BODY_LIVE }}(${{ needs.get_context_info.outputs.LINK_LIVE }})
artifacts: ${{ vars.ZIP_NAME_LIVE }}
makeLatest: true