@@ -55,121 +55,130 @@ jobs:
5555 else
5656 {
5757 echo "Update required"
58-
59- # Configure git
60- git config user.name "github-actions[bot]"
61- git config user.email "github-actions[bot]@users.noreply.github.com"
62-
63- # Remove old branch if exist and make new one
64- git branch -D ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }}
65- git checkout -b ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }}
66-
67- # Delete old binaries, unpack archive, remove archive
68- rm -r -fo "$clientDir\Resources\Binaries"
69- rm -r -fo "$clientDir\Resources\BinariesNET8"
70- 7z x xna-cncnet-client-*.7z -y -oTEMPORARY
71- cp -r -fo "TEMPORARY\Resources\*" "$clientDir\Resources\"
72- rm -r -fo TEMPORARY
73- rm xna-cncnet-client-*.7z
74-
75- # Commit changes
76- git commit -am "${{ env.COMMIT_MESSAGE }}"
77-
78- # Path to the updateexec file
79- $updateExecPath = "$clientDir\updateexec"
80-
81- # Check if the updateexec file exists
82- if (-Not (Test-Path -Path $updateExecPath))
58+
59+ # Check if branch exist
60+ $branch_exist = 'false'
61+ gh pr list | Where-Object {$_.Contains('${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }}')} | ForEach-Object { $branch_exist = 'true' }
62+ if ($branch_exist -eq 'true')
8363 {
84- echo "The file 'updateexec' does not exist. Skip updating [Delete] section ."
64+ echo "Branch ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }} already exist. Skip updating."
8565 }
8666 else
8767 {
88- # Get the deleted and moved files from git diff
89- $deletedFiles = git diff --diff-filter=D --name-status HEAD~1 HEAD | Where-Object { $_.StartsWith('D') } | ForEach-Object { $_.Substring(1).Trim().Replace('/', '\') }
90- $deletedFiles += [Environment]::NewLine
91- $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('/', '\') }
92-
93- # If exclude is empty, ignore
94- if ($exclude.Length -ne 0)
68+ # Configure git
69+ git config user.name "github-actions[bot]"
70+ git config user.email "github-actions[bot]@users.noreply.github.com"
71+
72+ # Make update branch
73+ git checkout -b ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }}
74+
75+ # Delete old binaries, unpack archive, remove archive
76+ rm -r -fo "$clientDir\Resources\Binaries"
77+ rm -r -fo "$clientDir\Resources\BinariesNET8"
78+ 7z x xna-cncnet-client-*.7z -y -oTEMPORARY
79+ cp -r -fo "TEMPORARY\Resources\*" "$clientDir\Resources\"
80+ rm -r -fo TEMPORARY
81+ rm xna-cncnet-client-*.7z
82+
83+ # Commit changes
84+ git commit -am "${{ env.COMMIT_MESSAGE }}"
85+
86+ # Path to the updateexec file
87+ $updateExecPath = "$clientDir\updateexec"
88+
89+ # Check if the updateexec file exists
90+ if (-Not (Test-Path -Path $updateExecPath))
9591 {
96- # Clearing delete files from exclude path
97- $tmp = ""
98- foreach($delete_file in $deletedFiles)
99- {
100- if ($delete_file.StartsWith($exclude + '\'))
101- {
102- $tmp += ($delete_file.Remove(0, ($exclude.Length + 1)))
103- $tmp += [Environment]::NewLine
104- }
105- else
106- {
107- $tmp += $delete_file
108- $tmp += [Environment]::NewLine
109- }
110- }
111- $deletedFiles = $tmp
112- }
113-
114- # Check if there are any deleted files
115- if ($deletedFiles.Count -eq 0)
116- {
117- echo "No deleted files found in the git diff. Skip updating [Delete] section."
92+ echo "The file 'updateexec' does not exist. Skip updating [Delete] section."
11893 }
11994 else
12095 {
121- # Read the content of the updateexec file
122- $updateexecContent_old = Get-Content -Path $updateExecPath
123- $updateexecContent_new = ""
96+ # Get the deleted and moved files from git diff
97+ $deletedFiles = git diff --diff-filter=D --name-status HEAD~1 HEAD | Where-Object { $_.StartsWith('D') } | ForEach-Object { $_.Substring(1).Trim().Replace('/', '\') }
98+ $deletedFiles += [Environment]::NewLine
99+ $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('/', '\') }
124100
125- # Find the [Delete] section and its position
126- $deleteSectionIndex = $updateexecContent_old.IndexOf("[Delete]")
101+ # If exclude is empty, ignore
102+ if ($exclude.Length -ne 0)
103+ {
104+ # Clearing delete files from exclude path
105+ $tmp = ""
106+ foreach($delete_file in $deletedFiles)
107+ {
108+ if ($delete_file.StartsWith($exclude + '\'))
109+ {
110+ $tmp += ($delete_file.Remove(0, ($exclude.Length + 1)))
111+ $tmp += [Environment]::NewLine
112+ }
113+ else
114+ {
115+ $tmp += $delete_file
116+ $tmp += [Environment]::NewLine
117+ }
118+ }
119+ $deletedFiles = $tmp
120+ }
127121
128- # If not exist, create
129- if ($deleteSectionIndex -eq -1 )
122+ # Check if there are any deleted files
123+ if ($deletedFiles.Count -eq 0 )
130124 {
131- $updateexecContent_old += [Environment]::NewLine
132- $updateexecContent_old += "[Delete]"
133- $deleteSectionIndex = $updateexecContent_old.IndexOf("[Delete]")
125+ echo "No deleted files found in the git diff. Skip updating [Delete] section."
134126 }
127+ else
128+ {
129+ # Read the content of the updateexec file
130+ $updateexecContent_old = Get-Content -Path $updateExecPath
131+ $updateexecContent_new = ""
135132
136- # Exclude path from string for config
137- $exclude = "${{ env.CLIENT_PATH }}"
133+ # Find the [Delete] section and its position
134+ $deleteSectionIndex = $updateexecContent_old.IndexOf("[Delete]")
138135
139- # Iterate all content of old updateexec
140- foreach($old_line in $updateexecContent_old)
141- {
142- $index = $updateexecContent_old.IndexOf($old_line)
143- $updateexecContent_new += $old_line + [Environment]::NewLine
136+ # If not exist, create
137+ if ($deleteSectionIndex -eq -1)
138+ {
139+ $updateexecContent_old += [Environment]::NewLine
140+ $updateexecContent_old += "[Delete]"
141+ $deleteSectionIndex = $updateexecContent_old.IndexOf("[Delete]")
142+ }
143+
144+ # Exclude path from string for config
145+ $exclude = "${{ env.CLIENT_PATH }}"
144146
145- # If we find section [Delete], add new deleted files
146- if ($deleteSectionIndex -eq $index )
147+ # Iterate all content of old updateexec
148+ foreach($old_line in $updateexecContent_old )
147149 {
148- $updateexecContent_new += "; ${{ steps.download.outputs.tag_name }} (auto-generated entries for removed/renamed files)" + [Environment]::NewLine
149-
150- foreach($new_delete in $deletedFiles)
150+ $index = $updateexecContent_old.IndexOf($old_line)
151+ $updateexecContent_new += $old_line + [Environment]::NewLine
152+
153+ # If we find section [Delete], add new deleted files
154+ if ($deleteSectionIndex -eq $index)
151155 {
152- $updateexecContent_new += $new_delete + [Environment]::NewLine
156+ $updateexecContent_new += "; ${{ steps.download.outputs.tag_name }} (auto-generated entries for removed/renamed files)" + [Environment]::NewLine
157+
158+ foreach($new_delete in $deletedFiles)
159+ {
160+ $updateexecContent_new += $new_delete + [Environment]::NewLine
161+ }
162+
163+ $updateexecContent_new += "; end entries" + [Environment]::NewLine + [Environment]::NewLine
153164 }
154-
155- $updateexecContent_new += "; end entries" + [Environment]::NewLine + [Environment]::NewLine
156165 }
157- }
158166
159- # Save the modified content back to the file
160- $updateexecContent_new | Set-Content -Path $updateExecPath
167+ # Save the modified content back to the file
168+ $updateexecContent_new | Set-Content -Path $updateExecPath
169+ }
161170 }
162- }
163171
164- # Commit changes if there exist updateexec and client binaries have new deleted files
165- git commit --amend -am "${{ env.COMMIT_MESSAGE }}"
172+ # Commit changes if there exist updateexec and client binaries have new deleted files
173+ git commit --amend -am "${{ env.COMMIT_MESSAGE }}"
166174
167- # Push changes
168- git push --force origin ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }}
175+ # Push changes
176+ git push --force origin ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }}
169177
170- # This timeout is for the remote server to index received content
171- timeout /t 10 > nul
178+ # This timeout is for the remote server to index received content
179+ timeout /t 10 > nul
172180
173- # Open a PR
174- gh pr create -B main -H ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }} --title '${{ env.PR_TITLE }} ${{ steps.download.outputs.tag_name }}' --body '${{ env.PR_BODY }}'
181+ # Open a PR
182+ gh pr create -B main -H ${{ env.UPDATE_BRANCH_NAME }}-${{ steps.download.outputs.tag_name }} --title '${{ env.PR_TITLE }} ${{ steps.download.outputs.tag_name }}' --body '${{ env.PR_BODY }}'
183+ }
175184 }
0 commit comments