Skip to content

Commit a6e6df2

Browse files
committed
pr comment to use unique local branch
1 parent ec26c3d commit a6e6df2

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

.github/workflows/auto-update-Dockerfiles.yml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,27 +123,25 @@ jobs:
123123
if (git status --porcelain) {
124124
git config --global user.email "[email protected]"
125125
git config --global user.name "aws-sdk-dotnet-automation"
126-
$branch="chore/auto-update-Dockerfiles-daily"
127126
128-
# Check if the branch already exists remotely
129-
$branchExists = git ls-remote --heads origin $branch
130-
if ($branchExists) {
131-
# Branch exists, check it out and update it
132-
git fetch origin $branch
133-
git checkout -B $branch origin/$branch
134-
} else {
135-
# Branch doesn't exist, create it
136-
git checkout -b $branch
137-
}
127+
# Generate timestamp for unique local branch name
128+
$timestamp = Get-Date -Format "yyyyMMddHHmmss"
129+
$localBranch = "chore/auto-update-Dockerfiles-daily-$timestamp"
130+
$remoteBranch = "chore/auto-update-Dockerfiles-daily"
131+
132+
# Always create a new unique local branch
133+
git checkout -b $localBranch
138134
139135
git add "**/*Dockerfile"
140136
git commit -m "chore: Daily ASP.NET Core version update in Dockerfiles"
141-
git push --force-with-lease origin $branch
142137
143-
# Write the branch name to GITHUB_OUTPUT for use in the PR step
144-
Add-Content -Path $env:GITHUB_OUTPUT -Value "BRANCH=$branch"
138+
# Push local branch to remote branch (force push to consistent remote branch name)
139+
git push --force-with-lease origin "${localBranch}:${remoteBranch}"
140+
141+
# Write the remote branch name to GITHUB_OUTPUT for use in the PR step
142+
Add-Content -Path $env:GITHUB_OUTPUT -Value "BRANCH=$remoteBranch"
145143
Add-Content -Path $env:GITHUB_OUTPUT -Value "CHANGES_MADE=true"
146-
echo "Changes committed and pushed to branch $branch"
144+
echo "Changes committed to local branch $localBranch and pushed to remote branch $remoteBranch"
147145
} else {
148146
echo "No changes detected in Dockerfiles, skipping PR creation"
149147
}

0 commit comments

Comments
 (0)