Skip to content

Commit fc92619

Browse files
Fix workflow be able work with existing updateexec and zero deleted files (#62)
1 parent ea5a4c7 commit fc92619

File tree

1 file changed

+61
-52
lines changed

1 file changed

+61
-52
lines changed

.github/workflows/upd-xna-client.yml

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -98,75 +98,84 @@ jobs:
9898
$deletedFiles = git diff --diff-filter=D --name-status HEAD~1 HEAD | Where-Object { $_.StartsWith('D') } | ForEach-Object { $_.Substring(1).Trim().Replace('/', '\') }
9999
$deletedFiles += [Environment]::NewLine
100100
$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('/', '\') }
101+
$deletedFiles = $deletedFiles.Trim().Trim([Environment]::NewLine)
101102
102-
# If exclude is empty, ignore
103-
if ($exclude.Length -ne 0)
103+
# Skip update if there is no deleted files
104+
if ($deletedFiles -eq [String]::Empty)
104105
{
105-
# Clearing delete files from exclude path
106-
$tmp = ""
107-
foreach($delete_file in $deletedFiles)
106+
echo "Delete files list is empty. Skip updating 'updateexec'."
107+
}
108+
else
109+
{
110+
# If exclude is empty, ignore
111+
if ($exclude.Length -ne 0)
108112
{
109-
if ($delete_file.StartsWith($exclude + '\'))
113+
# Clearing delete files from exclude path
114+
$tmp = ""
115+
foreach($delete_file in $deletedFiles)
110116
{
111-
$tmp += ($delete_file.Remove(0, ($exclude.Length + 1)))
112-
$tmp += [Environment]::NewLine
113-
}
114-
else
115-
{
116-
$tmp += $delete_file
117-
$tmp += [Environment]::NewLine
117+
if ($delete_file.StartsWith($exclude + '\'))
118+
{
119+
$tmp += ($delete_file.Remove(0, ($exclude.Length + 1)))
120+
$tmp += [Environment]::NewLine
121+
}
122+
else
123+
{
124+
$tmp += $delete_file
125+
$tmp += [Environment]::NewLine
126+
}
118127
}
128+
$deletedFiles = $tmp
119129
}
120-
$deletedFiles = $tmp
121-
}
122130
123-
# Check if there are any deleted files
124-
if ($deletedFiles.Count -eq 0)
125-
{
126-
echo "No deleted files found in the git diff. Skip updating [Delete] section."
127-
}
128-
else
129-
{
130-
# Read the content of the updateexec file
131-
$updateexecContent_old = Get-Content -Path $updateExecPath
132-
$updateexecContent_new = ""
133-
134-
# Find the [Delete] section and its position
135-
$deleteSectionIndex = $updateexecContent_old.IndexOf("[Delete]")
136-
137-
# If not exist, create
138-
if ($deleteSectionIndex -eq -1)
131+
# Check if there are any deleted files
132+
if ($deletedFiles.Count -eq 0)
139133
{
140-
$updateexecContent_old += [Environment]::NewLine
141-
$updateexecContent_old += "[Delete]"
142-
$deleteSectionIndex = $updateexecContent_old.IndexOf("[Delete]")
134+
echo "No deleted files found in the git diff. Skip updating [Delete] section."
143135
}
136+
else
137+
{
138+
# Read the content of the updateexec file
139+
$updateexecContent_old = Get-Content -Path $updateExecPath
140+
$updateexecContent_new = ""
144141
145-
# Exclude path from string for config
146-
$exclude = "${{ env.CLIENT_PATH }}"
142+
# Find the [Delete] section and its position
143+
$deleteSectionIndex = $updateexecContent_old.IndexOf("[Delete]")
147144
148-
# Iterate all content of old updateexec
149-
foreach($old_line in $updateexecContent_old)
150-
{
151-
$index = $updateexecContent_old.IndexOf($old_line)
152-
$updateexecContent_new += $old_line + [Environment]::NewLine
145+
# If not exist, create
146+
if ($deleteSectionIndex -eq -1)
147+
{
148+
$updateexecContent_old += [Environment]::NewLine
149+
$updateexecContent_old += "[Delete]"
150+
$deleteSectionIndex = $updateexecContent_old.IndexOf("[Delete]")
151+
}
152+
153+
# Exclude path from string for config
154+
$exclude = "${{ env.CLIENT_PATH }}"
153155
154-
# If we find section [Delete], add new deleted files
155-
if ($deleteSectionIndex -eq $index)
156+
# Iterate all content of old updateexec
157+
foreach($old_line in $updateexecContent_old)
156158
{
157-
$updateexecContent_new += "; ${{ steps.download.outputs.tag_name }} (auto-generated entries for removed/renamed files)" + [Environment]::NewLine
158-
159-
foreach($new_delete in $deletedFiles)
159+
$index = $updateexecContent_old.IndexOf($old_line)
160+
$updateexecContent_new += $old_line + [Environment]::NewLine
161+
162+
# If we find section [Delete], add new deleted files
163+
if ($deleteSectionIndex -eq $index)
160164
{
161-
$updateexecContent_new += $new_delete + [Environment]::NewLine
165+
$updateexecContent_new += "; ${{ steps.download.outputs.tag_name }} (auto-generated entries for removed/renamed files)" + [Environment]::NewLine
166+
167+
foreach($new_delete in $deletedFiles)
168+
{
169+
$updateexecContent_new += $new_delete + [Environment]::NewLine
170+
}
171+
172+
$updateexecContent_new += "; end entries" + [Environment]::NewLine + [Environment]::NewLine
162173
}
163-
164-
$updateexecContent_new += "; end entries" + [Environment]::NewLine + [Environment]::NewLine
165174
}
166-
}
167175
168-
# Save the modified content back to the file
169-
$updateexecContent_new | Set-Content -Path $updateExecPath
176+
# Save the modified content back to the file
177+
$updateexecContent_new | Set-Content -Path $updateExecPath
178+
}
170179
}
171180
}
172181

0 commit comments

Comments
 (0)