|
62 | 62 | URL: ${{ steps.ver.outputs.url }} |
63 | 63 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
64 | 64 | run: | |
65 | | - git config user.name "github-actions[bot]" |
66 | | - git config user.email "github-actions[bot]@users.noreply.github.com" |
67 | | -
|
68 | | - # Sanitize version for use in a branch name (e.g. v0.14 -> 0-14) |
69 | 65 | VERSION_SLUG=$(echo "$VERSION" | sed 's/^v//;s/\./-/g') |
| 66 | + REPO="${GITHUB_REPOSITORY}" |
70 | 67 |
|
71 | 68 | # Find all versioned release branches (release/0.x), skip preview branches |
72 | 69 | for branch in $(git branch -r | grep -E 'origin/release/[0-9]' | sed 's|.*origin/||'); do |
|
82 | 79 | PR_ACTION="create" |
83 | 80 | fi |
84 | 81 |
|
85 | | - # Create or reset the work branch to the current release branch HEAD |
86 | | - git checkout -B "$WORK_BRANCH" |
87 | | -
|
88 | 82 | python3 - <<'PYEOF' |
89 | 83 | import os, re |
90 | 84 |
|
@@ -122,28 +116,69 @@ jobs: |
122 | 116 | f.write(content) |
123 | 117 | PYEOF |
124 | 118 |
|
125 | | - git add config/_default/params.yaml |
126 | | - if git diff --cached --quiet; then |
127 | | - echo "Already in desired state, skipping" |
128 | | - git checkout "$branch" |
| 119 | + # Check if there are actual changes vs the release branch HEAD |
| 120 | + if git diff --quiet HEAD -- config/_default/params.yaml; then |
| 121 | + echo "Already in desired state, skipping ${branch}" |
| 122 | + git restore config/_default/params.yaml |
129 | 123 | echo "::endgroup::" |
130 | 124 | continue |
131 | 125 | fi |
132 | 126 |
|
133 | | - git commit -m "chore: add ${VERSION} to version switcher" |
134 | | - git push --force-with-lease origin "$WORK_BRANCH" |
135 | | -
|
136 | | - if [ "$PR_ACTION" = "create" ]; then |
| 127 | + # Save desired content to a temp file (preserves trailing newline) |
| 128 | + DESIRED_FILE=$(mktemp) |
| 129 | + cat config/_default/params.yaml > "$DESIRED_FILE" |
| 130 | + git restore config/_default/params.yaml |
| 131 | +
|
| 132 | + # --- API-based commit (GitHub auto-verifies; no GPG key needed) --- |
| 133 | +
|
| 134 | + # Get the release branch HEAD and its tree |
| 135 | + BASE_SHA=$(gh api "repos/${REPO}/branches/${branch}" --jq '.commit.sha') |
| 136 | + BASE_TREE_SHA=$(gh api "repos/${REPO}/git/commits/${BASE_SHA}" --jq '.tree.sha') |
| 137 | +
|
| 138 | + # Upload the modified file as a blob |
| 139 | + CONTENT_B64=$(base64 -w 0 < "$DESIRED_FILE") |
| 140 | + rm -f "$DESIRED_FILE" |
| 141 | + BLOB_SHA=$(gh api "repos/${REPO}/git/blobs" \ |
| 142 | + -f content="$CONTENT_B64" \ |
| 143 | + -f encoding="base64" \ |
| 144 | + --jq '.sha') |
| 145 | +
|
| 146 | + # Create a new tree with the updated file |
| 147 | + NEW_TREE_SHA=$(jq -n \ |
| 148 | + --arg base_tree "$BASE_TREE_SHA" \ |
| 149 | + --arg blob "$BLOB_SHA" \ |
| 150 | + '{base_tree:$base_tree,tree:[{path:"config/_default/params.yaml",mode:"100644",type:"blob",sha:$blob}]}' | \ |
| 151 | + gh api "repos/${REPO}/git/trees" --input - --jq '.sha') |
| 152 | +
|
| 153 | + # Build commit message with Signed-off-by for DCO |
| 154 | + COMMIT_MSG=$(printf 'chore: add %s to version switcher in release %s\n\nSigned-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>' \ |
| 155 | + "$VERSION" "$branch") |
| 156 | +
|
| 157 | + # Create the commit (GitHub signs API commits automatically → Verified) |
| 158 | + NEW_COMMIT_SHA=$(jq -n \ |
| 159 | + --arg msg "$COMMIT_MSG" \ |
| 160 | + --arg tree "$NEW_TREE_SHA" \ |
| 161 | + --arg parent "$BASE_SHA" \ |
| 162 | + '{message:$msg,tree:$tree,parents:[$parent]}' | \ |
| 163 | + gh api "repos/${REPO}/git/commits" --input - --jq '.sha') |
| 164 | +
|
| 165 | + # Create or force-update the work branch ref |
| 166 | + if [ "$PR_ACTION" = "update" ]; then |
| 167 | + gh api "repos/${REPO}/git/refs/heads/${WORK_BRANCH}" \ |
| 168 | + -X PATCH -f sha="$NEW_COMMIT_SHA" -F force=true |
| 169 | + echo "Updated PR branch: ${WORK_BRANCH}" |
| 170 | + else |
| 171 | + gh api "repos/${REPO}/git/refs" \ |
| 172 | + -f ref="refs/heads/${WORK_BRANCH}" \ |
| 173 | + -f sha="$NEW_COMMIT_SHA" |
137 | 174 | gh pr create \ |
| 175 | + --repo "$REPO" \ |
138 | 176 | --base "$branch" \ |
139 | 177 | --head "$WORK_BRANCH" \ |
140 | | - --title "chore: add ${VERSION} to version switcher" \ |
| 178 | + --title "chore: add ${VERSION} to version switcher in release ${branch}" \ |
141 | 179 | --body "Automated PR: adds \`${VERSION}\` to the version switcher in the \`${branch}\` release docs. Triggered by: ${{ github.event_name }} (${{ github.sha }})" |
142 | 180 | echo "Opened PR: ${WORK_BRANCH} -> ${branch}" |
143 | | - else |
144 | | - echo "Updated PR branch: ${WORK_BRANCH}" |
145 | 181 | fi |
146 | 182 |
|
147 | | - git checkout "$branch" |
148 | 183 | echo "::endgroup::" |
149 | 184 | done |
0 commit comments