Skip to content

Update XNA CnCNet Client Launcher #310

Update XNA CnCNet Client Launcher

Update XNA CnCNet Client Launcher #310

# To be able use this workflow you must ensure that your repository have enable write and right access for GitHub Actions.
#
# GUI Reference to enable access:
# Repository --> Actions --> General --> Workflow permissions --> Read and write permissions
# \--> Allow Github Actions to create and approve pull requests
name: Update XNA CnCNet Client Launcher
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # Starts everyday at 00:00 UTC+0
permissions:
contents: write
pull-requests: write
env:
CLIENT_PATH: ClientFiles # Do not add trailing slash
LAUNCHER_NAME: YRLauncher.exe # Full launcher filename
ICON_NAME: clienticon.ico # Full icon filename in the Resources folder
UPDATE_BRANCH_NAME: update-client-launcher # The workflow adds the release tag after this value, i.e. "update-client-launcher-2.12.13"
TARGET_BRANCH: master # Into this branch workflow should create pull request for merge
COMMIT_MESSAGE: Update client launcher to the version
PR_TITLE: Update client launcher to the version # The workflow adds the release tag after this value, i.e. "Update client binaries to the launcher 2.12.13"
PR_BODY: This is an automatic pull request to update client launcher to the latest release published in [CnCNet/xna-cncnet-client-launcher](https://github.com/CnCNet/xna-cncnet-client-launcher/releases/tag/@) repository.
jobs:
publish-update-pr:
runs-on: windows-2022
steps:
- name: Checkout Repo
uses: actions/checkout@v7
with:
ref: ${{ env.TARGET_BRANCH }}
fetch-depth: 0
lfs: true
- name: Download Latest Release
id: download
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$tag_name = (gh release list --repo CnCNet/xna-cncnet-client-launcher --exclude-drafts --limit 1 --json tagName --jq '.[0].tagName')
gh release download $tag_name --repo CnCNet/xna-cncnet-client-launcher --pattern "CnCNet*"
7z x CnCNet*.zip -y -oTEMPORARY
$product_version = (Get-Item -Path "TEMPORARY\CnCNet.LauncherStub.exe").VersionInfo.ProductVersion
rm CnCNet*.zip
"product_version=$product_version" >> $env:GITHUB_OUTPUT
"tag_name=$tag_name" >> $env:GITHUB_OUTPUT
- name: Download Icon Changer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release download v1.1.0 --repo stefanGaina/icon-changer --pattern "icon-changer*"
7z x icon-changer*.zip
rm icon-changer*.zip
- name: Open PR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$repoDir = (Get-Location).Path
$clientDir = $repoDir + "\${{ env.CLIENT_PATH }}"
$launcher = "${{ env.LAUNCHER_NAME }}"
$currentVersion = (Test-Path "$clientDir\$launcher") ? (Get-Item -Path "$clientDir\$launcher").VersionInfo.ProductVersion : ""
$downloadVersion = '${{ steps.download.outputs.product_version }}'
echo "Current launcher version: '$currentVersion'"
echo "Downloaded launcher version: '$downloadVersion'"
if ($currentVersion -eq $downloadVersion)
{
echo "Update is not required"
exit
}
echo "Update required"
# Check if branch exist
$branch_exist = 'false'
gh pr list | Where-Object {$_.Contains('${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }}')} | ForEach-Object { $branch_exist = 'true' }
if ($branch_exist -eq 'true')
{
echo "Branch ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }} already exist. Skip updating."
exit
}
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Make update branch
git checkout -b ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }}
# Replace old binaries, remove unpacked folder
mv -Force "TEMPORARY\CnCNet.LauncherStub.exe" "${{ env.CLIENT_PATH }}\${{ env.LAUNCHER_NAME }}"
mv -Force "TEMPORARY\CnCNet.LauncherStub.exe.config" "${{ env.CLIENT_PATH }}\${{ env.LAUNCHER_NAME }}.config"
rm -r -fo TEMPORARY
# Patch the client's launcher icon and remove the icon-changer
& ./icon-changer.exe "${{ env.CLIENT_PATH }}\Resources\${{ env.ICON_NAME }}" "${{ env.CLIENT_PATH }}\${{ env.LAUNCHER_NAME }}"
rm icon-changer.exe
# Commit changes
git add *
git commit -m "${{ env.COMMIT_MESSAGE }} ${{ steps.download.outputs.tag_name }}"
# Push changes
git push --force origin ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }}
# This timeout is for the remote server to index received content
# https://stackoverflow.com/questions/74842935/powershell-batch-script-timeout-error-input-redirection-is-not-supported-exiti
Start-Job {
# Simulate calling a batch file (cmd /c)
# inside of which the `start` call is made,
# waiting for 5 seconds in this example.
cmd /c start /min timeout.exe 10
} | Receive-Job -Wait -AutoRemoveJob
# Open a PR
gh pr create -B ${{ env.TARGET_BRANCH }} -H ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }} --title '${{ env.PR_TITLE }} ${{ steps.download.outputs.tag_name }}' --body "${{ env.PR_BODY }}".Replace("@", "${{ steps.download.outputs.tag_name }}")