-
-
Notifications
You must be signed in to change notification settings - Fork 58
199 lines (168 loc) · 8.07 KB
/
Copy pathupd-xna-client.yml
File metadata and controls
199 lines (168 loc) · 8.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# 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
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # Starts everyday at 00:00 UTC+0
env:
CLIENT_PATH: package # Do not add trailing slash
UPDATE_BRANCH_NAME: update-client-binaries # The workflow adds the release tag after this value, i.e. "update-client-binaries-2.12.13"
TARGET_BRANCH: develop # Into this branch workflow should create pull request for merge
COMMIT_MESSAGE: Update client binaries to the latest version
PR_TITLE: Update client binaries to the version # The workflow adds the release tag after this value, i.e. "Update client binaries to the version 2.12.13"
PR_BODY: This is an automatic pull request to update client binaries to the latest release published in [CnCNet/xna-cncnet-client](https://github.com/CnCNet/xna-cncnet-client) repository.
jobs:
publish-update-pr:
runs-on: windows-2022
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
lfs: true
- name: Download Latest Release
id: download
uses: robinraju/release-downloader@v1
with:
repository: CnCNet/xna-cncnet-client
latest: true
fileName: xna-cncnet-client*
- name: Create Update Branch
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
$repoDir = (Get-Location).Path
$clientDir = $repoDir + "\${{ env.CLIENT_PATH }}"
$currentVersion = (Get-Item -Path "$clientDir\Resources\clientdx.exe").VersionInfo.FileVersion -Replace "\.0$", ""
$downloadVersion = '${{ steps.download.outputs.tag_name }}'
echo "Current client version: '$currentVersion'"
echo "Downloaded client 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 }}
# Delete old binaries, unpack archive, remove archive
rm -r -fo "$clientDir\Resources\Binaries"
rm -r -fo "$clientDir\Resources\BinariesNET8"
7z x xna-cncnet-client-*.7z -y -oTEMPORARY
cp -r -fo "TEMPORARY\Resources\*" "$clientDir\Resources\"
rm -r -fo TEMPORARY
rm xna-cncnet-client-*.7z
# Commit changes
git add -A
git commit -m "${{ env.COMMIT_MESSAGE }}"
# Path to the updateexec file
$updateExecPath = "$clientDir\updateexec"
# Check if the updateexec file exists
if (-Not (Test-Path -Path $updateExecPath))
{
echo "The file 'updateexec' does not exist. Skip updating [Delete] section."
}
else
{
# Get the deleted and moved files from git diff
$deletedFiles = git diff --diff-filter=D --name-status HEAD~1 HEAD | Where-Object { $_.StartsWith('D') } | ForEach-Object { $_.Substring(1).Trim().Replace('/', '\') }
$deletedFiles += [Environment]::NewLine
$deletedFiles += git diff --diff-filter=R --name-status --diff-filter=R HEAD~1 HEAD | Where-Object { $_.StartsWith('R100') } | ForEach-Object { $_.Substring(4).Trim().Split(' ')[0].Replace('/', '\') }
$deletedFiles = $deletedFiles.Trim().Trim([Environment]::NewLine)
# Skip update if there is no deleted files
if ($deletedFiles -eq [String]::Empty)
{
echo "Delete files list is empty. Skip updating 'updateexec'."
}
else
{
# If exclude is empty, ignore
if ($exclude.Length -ne 0)
{
# Clearing delete files from exclude path
$tmp = ""
foreach($delete_file in $deletedFiles)
{
if ($delete_file.StartsWith($exclude + '\'))
{
$tmp += ($delete_file.Remove(0, ($exclude.Length + 1)))
$tmp += [Environment]::NewLine
}
else
{
$tmp += $delete_file
$tmp += [Environment]::NewLine
}
}
$deletedFiles = $tmp
}
# Check if there are any deleted files
if ($deletedFiles.Count -eq 0)
{
echo "No deleted files found in the git diff. Skip updating [Delete] section."
}
else
{
# Read the content of the updateexec file
$updateexecContent_old = Get-Content -Path $updateExecPath
$updateexecContent_new = ""
# Find the [Delete] section and its position
$deleteSectionIndex = $updateexecContent_old.IndexOf("[Delete]")
# If not exist, create
if ($deleteSectionIndex -eq -1)
{
$updateexecContent_old += [Environment]::NewLine
$updateexecContent_old += "[Delete]"
$deleteSectionIndex = $updateexecContent_old.IndexOf("[Delete]")
}
# Exclude path from string for config
$exclude = "${{ env.CLIENT_PATH }}"
# Iterate all content of old updateexec
foreach($old_line in $updateexecContent_old)
{
$index = $updateexecContent_old.IndexOf($old_line)
$updateexecContent_new += $old_line + [Environment]::NewLine
# If we find section [Delete], add new deleted files
if ($deleteSectionIndex -eq $index)
{
$updateexecContent_new += "; ${{ steps.download.outputs.tag_name }} (auto-generated entries for removed/renamed files)" + [Environment]::NewLine
foreach($new_delete in $deletedFiles)
{
$updateexecContent_new += $new_delete + [Environment]::NewLine
}
$updateexecContent_new += "; end entries" + [Environment]::NewLine + [Environment]::NewLine
}
}
# Save the modified content back to the file
$updateexecContent_new | Set-Content -Path $updateExecPath
}
}
}
# Commit changes if there exist updateexec and client binaries have new deleted files
git commit --amend -am "${{ env.COMMIT_MESSAGE }}"
# 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 }}'