Skip to content

Commit 72fec71

Browse files
Add workflow to automate client launcher update (#35)
* Add workflow to automate client launcher update * Update upd-client-launcher.yml
1 parent 9ac69f4 commit 72fec71

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# To be able use this workflow you must ensure that your repository have enable write and right access for GitHub Actions.
2+
#
3+
# GUI Reference to enable access:
4+
# Repository --> Actions --> General --> Workflow permissions --> Read and write permissions
5+
# \--> Allow Github Actions to create and approve pull requests
6+
7+
name: Update XNA CnCNet Client Launcher
8+
9+
on:
10+
workflow_dispatch:
11+
schedule:
12+
- cron: "0 0 * * *" # Starts everyday at 00:00 UTC+0
13+
14+
env:
15+
CLIENT_PATH: ClientFiles # Do not add trailing slash
16+
LAUNCHER_NAME: YRLauncher.exe # Full launcher filename
17+
ICON_NAME: clienticon.ico # Full icon filename in the Resources folder
18+
UPDATE_BRANCH_NAME: update-client-launcher # The workflow adds the release tag after this value, i.e. "update-client-launcher-2.12.13"
19+
TARGET_BRANCH: master # Into this branch workflow should create pull request for merge
20+
COMMIT_MESSAGE: Update client launcher to the latest version
21+
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"
22+
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) repository.
23+
24+
jobs:
25+
publish-update-pr:
26+
runs-on: windows-2022
27+
28+
steps:
29+
- name: Checkout Repo
30+
uses: actions/checkout@v3
31+
with:
32+
lfs: true
33+
34+
- name: Download Latest Release
35+
id: download
36+
uses: robinraju/release-downloader@v1
37+
with:
38+
repository: CnCNet/xna-cncnet-client-launcher
39+
latest: true
40+
fileName: CnCNet*
41+
42+
- name: Download Icon Changer
43+
uses: robinraju/release-downloader@v1
44+
with:
45+
repository: stefanGaina/icon-changer
46+
tag: 'v1.1.0'
47+
fileName: icon-changer*
48+
49+
- name: Open PR
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
run: |
53+
$repoDir = (Get-Location).Path
54+
$clientDir = $repoDir + "\${{ env.CLIENT_PATH }}"
55+
$launcher = "${{ env.LAUNCHER_NAME }}"
56+
$currentVersion = ((Get-Item -Path "$clientDir\$launcher").VersionInfo.ProductVersion).Split("+")[0] -Replace "\.0$", ""
57+
$downloadVersion = '${{ steps.download.outputs.tag_name }}'.Trim("v")
58+
59+
echo "Current launcher version: '$currentVersion'"
60+
echo "Downloaded launcher version: '$downloadVersion'"
61+
62+
if ($currentVersion -eq $downloadVersion)
63+
{
64+
echo "Update is not required"
65+
exit
66+
}
67+
68+
echo "Update required"
69+
70+
# Check if branch exist
71+
$branch_exist = 'false'
72+
gh pr list | Where-Object {$_.Contains('${{ env.UPDATE_BRANCH_NAME }}-$downloadVersion')} | ForEach-Object { $branch_exist = 'true' }
73+
if ($branch_exist -eq 'true')
74+
{
75+
echo "Branch ${{ env.UPDATE_BRANCH_NAME }}-$downloadVersion already exist. Skip updating."
76+
exit
77+
}
78+
79+
# Configure git
80+
git config user.name "github-actions[bot]"
81+
git config user.email "github-actions[bot]@users.noreply.github.com"
82+
83+
# Make update branch
84+
git checkout -b ${{ env.UPDATE_BRANCH_NAME }}-$downloadVersion
85+
86+
# Delete old binaries, unpack archive, remove archive
87+
7z x CnCNet*.zip -y -oTEMPORARY
88+
mv -Force "TEMPORARY\CnCNet.LauncherStub.exe" "${{ env.CLIENT_PATH }}\${{ env.LAUNCHER_NAME }}"
89+
mv -Force "TEMPORARY\CnCNet.LauncherStub.exe.config" "${{ env.CLIENT_PATH }}\${{ env.LAUNCHER_NAME }}.config"
90+
rm -r -fo TEMPORARY
91+
rm CnCNet*.zip
92+
93+
7z x icon-changer*.zip
94+
& ./icon-changer.exe "${{ env.CLIENT_PATH }}\Resources\${{ env.ICON_NAME }}" "${{ env.CLIENT_PATH }}\${{ env.LAUNCHER_NAME }}"
95+
rm icon-changer.exe
96+
rm icon-changer*.zip
97+
98+
# Commit changes
99+
git add *
100+
git commit -m "${{ env.COMMIT_MESSAGE }}"
101+
102+
# Push changes
103+
git push --force origin ${{ env.UPDATE_BRANCH_NAME }}-$downloadVersion
104+
105+
# This timeout is for the remote server to index received content
106+
# https://stackoverflow.com/questions/74842935/powershell-batch-script-timeout-error-input-redirection-is-not-supported-exiti
107+
Start-Job {
108+
# Simulate calling a batch file (cmd /c)
109+
# inside of which the `start` call is made,
110+
# waiting for 5 seconds in this example.
111+
cmd /c start /min timeout.exe 10
112+
} | Receive-Job -Wait -AutoRemoveJob
113+
114+
# Open a PR
115+
gh pr create -B ${{ env.TARGET_BRANCH }} -H ${{ env.UPDATE_BRANCH_NAME }}-$downloadVersion --title '${{ env.PR_TITLE }} ${{ steps.download.outputs.tag_name }}' --body '${{ env.PR_BODY }}'

0 commit comments

Comments
 (0)