Skip to content

Commit 3d0b04a

Browse files
Fix retarget workflow: avoid rebase, fix token scope, add PR comment
- Remove auth header from upstream API check (public repo, cross-org token causes 403) - Replace git rebase with reset+save/restore (rebase fails in CI with conflicts and no interactive mode) - Set git identity before any git operations - Use git apply --3way with fallback instead of blind file copy - Fix commit message indentation (was baking YAML whitespace) - Add PR comment step so retarget is visible without checking Actions - Handle alternate What's New section headers (Updated cmdlets) - Warn when What's New 7.7 is missing instead of silently skipping - Stage specific files instead of git add -A
1 parent 29d47cc commit 3d0b04a

File tree

1 file changed

+94
-48
lines changed

1 file changed

+94
-48
lines changed

.github/workflows/retarget-7.7.yml

Lines changed: 94 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
permissions:
1010
contents: write
11+
pull-requests: write
1112

1213
jobs:
1314
check-and-retarget:
@@ -17,26 +18,30 @@ jobs:
1718
- name: Check if 7.7 folder exists upstream
1819
id: check
1920
run: |
21+
# Public repo — no auth needed (avoids cross-org token scope issues)
2022
STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
21-
"https://api.github.com/repos/MicrosoftDocs/PowerShell-Docs/contents/reference/7.7/Microsoft.PowerShell.Utility" \
22-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}")
23+
"https://api.github.com/repos/MicrosoftDocs/PowerShell-Docs/contents/reference/7.7/Microsoft.PowerShell.Utility")
24+
echo "status=$STATUS" >> "$GITHUB_OUTPUT"
2325
if [ "$STATUS" = "200" ]; then
2426
echo "exists=true" >> "$GITHUB_OUTPUT"
2527
else
2628
echo "exists=false" >> "$GITHUB_OUTPUT"
29+
echo "::notice::reference/7.7/ not found upstream (HTTP $STATUS). Will check again tomorrow."
2730
fi
2831
29-
- name: Exit early if 7.7 not ready
30-
if: steps.check.outputs.exists != 'true'
31-
run: echo "reference/7.7/ not found upstream yet. Will check again tomorrow."
32-
3332
- name: Checkout fork
3433
if: steps.check.outputs.exists == 'true'
3534
uses: actions/checkout@v4
3635
with:
3736
ref: doc/new-guid-uuid-v7
3837
fetch-depth: 0
3938

39+
- name: Configure git identity
40+
if: steps.check.outputs.exists == 'true'
41+
run: |
42+
git config user.name "github-actions[bot]"
43+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
44+
4045
- name: Add upstream remote
4146
if: steps.check.outputs.exists == 'true'
4247
run: |
@@ -49,94 +54,135 @@ jobs:
4954
run: |
5055
if [ -f "reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md" ]; then
5156
echo "done=true" >> "$GITHUB_OUTPUT"
57+
echo "::notice::Already retargeted — nothing to do."
5258
else
5359
echo "done=false" >> "$GITHUB_OUTPUT"
5460
fi
5561
5662
- name: Retarget docs from 7.6 to 7.7
5763
if: steps.check.outputs.exists == 'true' && steps.already.outputs.done != 'true'
5864
run: |
59-
# Rebase onto latest upstream main
60-
git rebase upstream/main
65+
set -euo pipefail
66+
67+
# ── 1. Reset branch to upstream main (clean slate, avoids rebase conflicts) ──
68+
# Save our modified files first
69+
cp reference/7.6/Microsoft.PowerShell.Utility/New-Guid.md /tmp/New-Guid-ours.md
70+
git diff upstream/main -- reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-76.md \
71+
> /tmp/whats-new-76.patch || true
72+
73+
git reset --hard upstream/main
6174
62-
# Get the upstream 7.7 New-Guid.md as base (if it exists), otherwise copy from 7.6
75+
# ── 2. Create 7.7 New-Guid.md from our modified version ──
76+
mkdir -p reference/7.7/Microsoft.PowerShell.Utility
77+
78+
# Start with upstream's 7.7 base if it exists, otherwise use our modified file
6379
if git show upstream/main:reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md > /dev/null 2>&1; then
64-
mkdir -p reference/7.7/Microsoft.PowerShell.Utility
80+
# Upstream has a 7.7 base — use it and apply our changes on top
6581
git show upstream/main:reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md \
6682
> reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md
67-
fi
6883
69-
# Apply our New-Guid changes to the 7.7 version
70-
# Copy our modified 7.6 file as the 7.7 version
71-
mkdir -p reference/7.7/Microsoft.PowerShell.Utility
72-
cp reference/7.6/Microsoft.PowerShell.Utility/New-Guid.md \
73-
reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md
84+
# Generate a patch from upstream 7.6 → our 7.6 and apply to 7.7
85+
git diff upstream/main -- reference/7.6/Microsoft.PowerShell.Utility/New-Guid.md \
86+
< /dev/null > /tmp/new-guid.patch || true
87+
if [ -s /tmp/new-guid.patch ]; then
88+
# Repath the patch from 7.6 to 7.7
89+
sed -i 's|reference/7.6/|reference/7.7/|g' /tmp/new-guid.patch
90+
git apply --3way /tmp/new-guid.patch || {
91+
echo "::warning::Patch apply failed — falling back to direct copy"
92+
cp /tmp/New-Guid-ours.md reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md
93+
}
94+
fi
95+
else
96+
# No upstream 7.7 base — copy our modified 7.6 file directly
97+
cp /tmp/New-Guid-ours.md reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md
98+
fi
7499
75-
# Update the online version URL from 7.6 to 7.7
100+
# Update version URL: 7.6 7.7
76101
sed -i 's/view=powershell-7\.6/view=powershell-7.7/g' \
77102
reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md
78103
79-
# Revert the 7.6 file back to upstream state
80-
git checkout upstream/main -- reference/7.6/Microsoft.PowerShell.Utility/New-Guid.md
81-
82-
# Handle What's New: revert 7.6 file, create 7.7 entry if it exists
83-
git checkout upstream/main -- reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-76.md
84-
85-
# If What's New 7.7 file exists upstream, add our entries there
104+
# ── 3. Handle What's New ──
105+
# The 7.6 file is already at upstream state (we did reset --hard).
106+
# Check if a 7.7 What's New file exists.
86107
WHATS_NEW_77="reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-77.md"
87108
if [ -f "$WHATS_NEW_77" ]; then
88-
# Add breaking change entry if not already present
89-
if ! grep -q "New-Guid.*Version 7" "$WHATS_NEW_77"; then
90-
# Insert after "## Breaking changes" or "## Cmdlet improvements" headers
91-
python3 - "$WHATS_NEW_77" <<'PYEOF'
109+
if ! grep -q "New-Guid" "$WHATS_NEW_77"; then
110+
python3 <<'PYEOF'
92111
import sys
93-
path = sys.argv[1]
112+
113+
path = "reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-77.md"
94114
with open(path, 'r') as f:
95115
content = f.read()
96116

97-
breaking_entry = """- `New-Guid` now generates Version 7 (time-sortable) UUIDs by default instead of Version 4
98-
(random). The output format is unchanged. Scripts that depend on fully random GUIDs should use
99-
`[guid]::NewGuid()` directly. ([#27033][27033])"""
117+
breaking_entry = ("- `New-Guid` now generates Version 7 (time-sortable) UUIDs by default instead of Version 4\n"
118+
" (random). The output format is unchanged. Scripts that depend on fully random GUIDs should use\n"
119+
" `[guid]::NewGuid()` directly. ([#27033][27033])")
100120

101-
cmdlet_entry = """- Change `New-Guid` to generate UUID v7 by default using `Guid.CreateVersion7()`
102-
([#27033][27033])"""
121+
cmdlet_entry = ("- Change `New-Guid` to generate UUID v7 by default using `Guid.CreateVersion7()`\n"
122+
" ([#27033][27033])")
103123

104124
link_entry = "[27033]: https://github.com/PowerShell/PowerShell/pull/27033"
105125

106-
# Add entries (simple append approach - manual placement may be needed)
126+
modified = False
127+
107128
if '## Breaking changes' in content:
108-
content = content.replace('## Breaking changes\n', f'## Breaking changes\n\n{breaking_entry}\n')
129+
content = content.replace('## Breaking changes\n', '## Breaking changes\n\n' + breaking_entry + '\n', 1)
130+
modified = True
131+
109132
if '## Cmdlet improvements' in content:
110-
content = content.replace('## Cmdlet improvements\n', f'## Cmdlet improvements\n\n{cmdlet_entry}\n')
133+
content = content.replace('## Cmdlet improvements\n', '## Cmdlet improvements\n\n' + cmdlet_entry + '\n', 1)
134+
modified = True
135+
elif '## Updated cmdlets' in content:
136+
content = content.replace('## Updated cmdlets\n', '## Updated cmdlets\n\n' + cmdlet_entry + '\n', 1)
137+
modified = True
138+
111139
if link_entry not in content:
112140
content = content.rstrip() + '\n' + link_entry + '\n'
141+
modified = True
142+
143+
if not modified:
144+
print("::warning::What's New 7.7 exists but has no recognized section headers. Manual edit needed.")
145+
sys.exit(0)
113146

114147
with open(path, 'w') as f:
115148
f.write(content)
149+
print("Updated What's New 7.7 with New-Guid entries.")
116150
PYEOF
117151
fi
152+
else
153+
echo "::notice::What-s-New-in-PowerShell-77.md does not exist yet. Only New-Guid.md will be included."
118154
fi
119155

120-
# Stage and commit
121-
git add -A
122-
git config user.name "github-actions[bot]"
123-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
124-
git commit -m "Retarget New-Guid UUID v7 docs from 7.6 to 7.7
156+
# ── 4. Stage and commit ──
157+
git add reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md
158+
if [ -f "$WHATS_NEW_77" ]; then
159+
git add "$WHATS_NEW_77"
160+
fi
125161

126-
The 7.7 reference folder is now available upstream.
127-
Moved New-Guid changes to reference/7.7/ and reverted
128-
reference/7.6/ to upstream state.
162+
git commit -m "Retarget New-Guid UUID v7 docs from 7.6 to 7.7
129163

130-
Co-Authored-By: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
164+
The 7.7 reference folder is now available upstream.
165+
Moved New-Guid changes to reference/7.7/ and reverted
166+
reference/7.6/ to upstream state."
131167

132168
- name: Push changes
133169
if: steps.check.outputs.exists == 'true' && steps.already.outputs.done != 'true'
134170
run: git push origin doc/new-guid-uuid-v7 --force-with-lease
135171

172+
- name: Comment on PR
173+
if: steps.check.outputs.exists == 'true' && steps.already.outputs.done != 'true'
174+
env:
175+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176+
run: |
177+
gh pr comment 12888 --repo MicrosoftDocs/PowerShell-Docs --body \
178+
"The \`reference/7.7/\` folder is now available upstream. I've retargeted this PR — \`New-Guid.md\` changes now live under \`reference/7.7/\` and the 7.6 file has been reverted to upstream state. Ready for review when convenient."
179+
136180
- name: Post summary
137181
if: steps.check.outputs.exists == 'true' && steps.already.outputs.done != 'true'
138182
run: |
139183
echo "## Retarget complete" >> "$GITHUB_STEP_SUMMARY"
140184
echo "" >> "$GITHUB_STEP_SUMMARY"
141-
echo "Moved New-Guid UUID v7 docs from \`reference/7.6/\` to \`reference/7.7/\`." >> "$GITHUB_STEP_SUMMARY"
142-
echo "PR #12888 branch has been updated." >> "$GITHUB_STEP_SUMMARY"
185+
echo "- Moved \`New-Guid.md\` from \`reference/7.6/\` → \`reference/7.7/\`" >> "$GITHUB_STEP_SUMMARY"
186+
echo "- Reverted \`reference/7.6/\` to upstream state" >> "$GITHUB_STEP_SUMMARY"
187+
echo "- Updated PR branch \`doc/new-guid-uuid-v7\`" >> "$GITHUB_STEP_SUMMARY"
188+
echo "- Posted comment on PR #12888" >> "$GITHUB_STEP_SUMMARY"

0 commit comments

Comments
 (0)