|
| 1 | +name: Retarget New-Guid docs to 7.7 |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Check daily at 08:00 UTC |
| 6 | + - cron: '0 8 * * *' |
| 7 | + workflow_dispatch: # Allow manual trigger |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +jobs: |
| 13 | + check-and-retarget: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Check if 7.7 folder exists upstream |
| 18 | + id: check |
| 19 | + run: | |
| 20 | + 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 | + if [ "$STATUS" = "200" ]; then |
| 24 | + echo "exists=true" >> "$GITHUB_OUTPUT" |
| 25 | + else |
| 26 | + echo "exists=false" >> "$GITHUB_OUTPUT" |
| 27 | + fi |
| 28 | +
|
| 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 | + |
| 33 | + - name: Checkout fork |
| 34 | + if: steps.check.outputs.exists == 'true' |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + ref: doc/new-guid-uuid-v7 |
| 38 | + fetch-depth: 0 |
| 39 | + |
| 40 | + - name: Add upstream remote |
| 41 | + if: steps.check.outputs.exists == 'true' |
| 42 | + run: | |
| 43 | + git remote add upstream https://github.com/MicrosoftDocs/PowerShell-Docs.git |
| 44 | + git fetch upstream main |
| 45 | +
|
| 46 | + - name: Check if already retargeted |
| 47 | + if: steps.check.outputs.exists == 'true' |
| 48 | + id: already |
| 49 | + run: | |
| 50 | + if [ -f "reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md" ]; then |
| 51 | + echo "done=true" >> "$GITHUB_OUTPUT" |
| 52 | + else |
| 53 | + echo "done=false" >> "$GITHUB_OUTPUT" |
| 54 | + fi |
| 55 | +
|
| 56 | + - name: Retarget docs from 7.6 to 7.7 |
| 57 | + if: steps.check.outputs.exists == 'true' && steps.already.outputs.done != 'true' |
| 58 | + run: | |
| 59 | + # Rebase onto latest upstream main |
| 60 | + git rebase upstream/main |
| 61 | +
|
| 62 | + # Get the upstream 7.7 New-Guid.md as base (if it exists), otherwise copy from 7.6 |
| 63 | + 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 |
| 65 | + git show upstream/main:reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md \ |
| 66 | + > reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md |
| 67 | + fi |
| 68 | +
|
| 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 |
| 74 | +
|
| 75 | + # Update the online version URL from 7.6 to 7.7 |
| 76 | + sed -i 's/view=powershell-7\.6/view=powershell-7.7/g' \ |
| 77 | + reference/7.7/Microsoft.PowerShell.Utility/New-Guid.md |
| 78 | +
|
| 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 |
| 86 | + WHATS_NEW_77="reference/docs-conceptual/whats-new/What-s-New-in-PowerShell-77.md" |
| 87 | + 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' |
| 92 | +import sys |
| 93 | +path = sys.argv[1] |
| 94 | +with open(path, 'r') as f: |
| 95 | + content = f.read() |
| 96 | + |
| 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])""" |
| 100 | + |
| 101 | +cmdlet_entry = """- Change `New-Guid` to generate UUID v7 by default using `Guid.CreateVersion7()` |
| 102 | + ([#27033][27033])""" |
| 103 | + |
| 104 | +link_entry = "[27033]: https://github.com/PowerShell/PowerShell/pull/27033" |
| 105 | + |
| 106 | +# Add entries (simple append approach - manual placement may be needed) |
| 107 | +if '## Breaking changes' in content: |
| 108 | + content = content.replace('## Breaking changes\n', f'## Breaking changes\n\n{breaking_entry}\n') |
| 109 | +if '## Cmdlet improvements' in content: |
| 110 | + content = content.replace('## Cmdlet improvements\n', f'## Cmdlet improvements\n\n{cmdlet_entry}\n') |
| 111 | +if link_entry not in content: |
| 112 | + content = content.rstrip() + '\n' + link_entry + '\n' |
| 113 | + |
| 114 | +with open(path, 'w') as f: |
| 115 | + f.write(content) |
| 116 | +PYEOF |
| 117 | + fi |
| 118 | + fi |
| 119 | + |
| 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 |
| 125 | + |
| 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. |
| 129 | + |
| 130 | + Co-Authored-By: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" |
| 131 | + |
| 132 | + - name: Push changes |
| 133 | + if: steps.check.outputs.exists == 'true' && steps.already.outputs.done != 'true' |
| 134 | + run: git push origin doc/new-guid-uuid-v7 --force-with-lease |
| 135 | + |
| 136 | + - name: Post summary |
| 137 | + if: steps.check.outputs.exists == 'true' && steps.already.outputs.done != 'true' |
| 138 | + run: | |
| 139 | + echo "## Retarget complete" >> "$GITHUB_STEP_SUMMARY" |
| 140 | + 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" |
0 commit comments