Skip to content

Commit 49615e6

Browse files
committed
[wip]: switch to ephemeral branches
1 parent 2afbf21 commit 49615e6

1 file changed

Lines changed: 43 additions & 60 deletions

File tree

.github/workflows/release-proposal-dispatch.yml

Lines changed: 43 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ concurrency:
3030

3131
env:
3232
MAIN_BRANCH: main
33-
RELEASE_BRANCH: release
3433
PROPOSAL_BRANCH_PREFIX: release-proposal
3534
GIT_USER_NAME: "dd-octo-sts[bot]"
3635
GIT_USER_EMAIL: "200755185+dd-octo-sts[bot]@users.noreply.github.com"
@@ -45,8 +44,8 @@ jobs:
4544
fetch-tags: true
4645
- name: Check if a release proposal is ongoing
4746
run: |
48-
# Check if there are any branches with the prefix "${{ env.PROPOSAL_BRANCH_PREFIX }}"
49-
EXISTING_BRANCHES=$(git branch -r --list "origin/${{ env.PROPOSAL_BRANCH_PREFIX }}/*")
47+
# Check if there are any proposal branches or ephemeral release branches (release/*/*)
48+
EXISTING_BRANCHES=$(git branch -r --list "origin/${{ env.PROPOSAL_BRANCH_PREFIX }}/*" "origin/release/*/*")
5049
if [ -n "$EXISTING_BRANCHES" ]; then
5150
echo "Error: A release proposal is ongoing. Please cancel it or wait for it to be merged." >&2
5251
echo "Existing branches:"
@@ -84,59 +83,17 @@ jobs:
8483
exit 1
8584
fi
8685
87-
update-release-branch:
88-
permissions:
89-
id-token: write # Enable OIDC
90-
contents: write
91-
runs-on: ubuntu-latest
92-
needs: check-membership
93-
steps:
94-
- uses: DataDog/dd-octo-sts-action@acaa02eee7e3bb0839e4272dacb37b8f3b58ba80 # v1.0.3
95-
id: octo-sts
96-
with:
97-
scope: DataDog/libdatadog
98-
policy: self.write.pr
99-
100-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
101-
with:
102-
token: ${{ steps.octo-sts.outputs.token }}
103-
fetch-depth: 0
104-
fetch-tags: true
105-
106-
- name: Configure Git identity for dd-octo-sts GitHub App
107-
env:
108-
GH_TOKEN: ${{ steps.octo-sts.outputs.token }}
109-
run: |
110-
111-
git config --global user.name "$GIT_USER_NAME"
112-
git config --global user.email "$GIT_USER_EMAIL"
113-
114-
- name: Merge the main branch into the release branch
115-
run: |
116-
git fetch origin "${{ env.MAIN_BRANCH }}" "${{ env.RELEASE_BRANCH }}" --tags
117-
git checkout "${{ env.RELEASE_BRANCH }}"
118-
119-
if ! git merge origin/"${{ env.MAIN_BRANCH }}"; then
120-
echo "Error: Cannot merge ${{ env.MAIN_BRANCH }} into ${{ env.RELEASE_BRANCH }}" >&2
121-
echo "There are merge conflicts or the branches have diverged." >&2
122-
echo "If you have recently launched another release, it is possible that ${{ env.MAIN_BRANCH }} branch is not yet updated with the ${{ env.RELEASE_BRANCH }} changes." >&2
123-
echo "Please try again later." >&2
124-
exit 1
125-
fi
126-
127-
git push origin "${{ env.RELEASE_BRANCH }}" --tags
128-
12986
cargo-release:
13087
permissions:
13188
id-token: write # Enable OIDC
13289
pull-requests: write
13390
contents: write
134-
needs: update-release-branch
91+
needs: check-membership
13592
runs-on: ubuntu-latest
13693
steps:
13794
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
13895
with:
139-
ref: ${{ env.RELEASE_BRANCH }}
96+
ref: ${{ env.MAIN_BRANCH }}
14097
fetch-depth: 0
14198
fetch-tags: true
14299
- uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # v2.8.1
@@ -168,6 +125,17 @@ jobs:
168125
git config --global user.name "${{ env.GIT_USER_NAME }}"
169126
git config --global user.email "${{ env.GIT_USER_EMAIL }}"
170127
128+
- name: Create ephemeral release branch
129+
id: ephemeral-branch
130+
run: |
131+
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
132+
EPHEMERAL_BRANCH="release/${{ inputs.crate }}/$TIMESTAMP"
133+
git checkout -b "$EPHEMERAL_BRANCH"
134+
git push origin "$EPHEMERAL_BRANCH"
135+
echo "Ephemeral release branch created: $EPHEMERAL_BRANCH from ${{ env.MAIN_BRANCH }} branch"
136+
echo "ephemeral_branch=$EPHEMERAL_BRANCH" >> "$GITHUB_OUTPUT"
137+
echo "timestamp=$TIMESTAMP" >> "$GITHUB_OUTPUT"
138+
171139
- name: Get publication order for crate and dependencies
172140
run: |
173141
echo "Getting publication order for ${{ inputs.crate }}..."
@@ -182,7 +150,7 @@ jobs:
182150
# Get commits since release for each crate and save to file
183151
./scripts/commits-since-release.sh "$(cat /tmp/crates.json)" > /tmp/commits-by-crate.json
184152
185-
# Capture release branch tip now (while HEAD=release). Use this in Release version bumps
153+
# Capture ephemeral release branch tip now. Use this in Release version bumps
186154
# so tag/merge-base resolution uses the same ref the script used.
187155
git rev-parse HEAD > /tmp/release_head_sha
188156
echo "Release branch HEAD (saved for later): $(cat /tmp/release_head_sha)"
@@ -202,14 +170,14 @@ jobs:
202170
# previous steps.
203171
# Assure we have the full history, 2147483647 is the highest integer number that
204172
# git accepts.
205-
git fetch --depth=2147483647 --tags origin "${{ env.MAIN_BRANCH }}" "${{ env.RELEASE_BRANCH }}"
173+
git fetch --depth=2147483647 --tags origin "${{ env.MAIN_BRANCH }}" "${{ steps.ephemeral-branch.outputs.ephemeral_branch }}"
206174
207-
git checkout "${{ env.RELEASE_BRANCH }}"
208-
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
175+
git checkout "${{ steps.ephemeral-branch.outputs.ephemeral_branch }}"
176+
TIMESTAMP="${{ steps.ephemeral-branch.outputs.timestamp }}"
209177
BRANCH_NAME="${{ env.PROPOSAL_BRANCH_PREFIX }}/${{ inputs.crate }}/$TIMESTAMP"
210178
git checkout -b "$BRANCH_NAME"
211179
git push origin "$BRANCH_NAME" --tags
212-
echo "Branch created: $BRANCH_NAME from ${{ env.RELEASE_BRANCH }} branch"
180+
echo "Branch created: $BRANCH_NAME from ${{ steps.ephemeral-branch.outputs.ephemeral_branch }} branch"
213181
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
214182
215183
- name: Release version bumps
@@ -387,7 +355,7 @@ jobs:
387355
done
388356
389357
# Check if there are commits to push
390-
if git diff --quiet "${{ env.RELEASE_BRANCH }}"; then
358+
if git diff --quiet "${{ steps.ephemeral-branch.outputs.ephemeral_branch }}"; then
391359
echo "No changes to push. Cancelling the workflow."
392360
exit 1
393361
fi
@@ -409,14 +377,22 @@ jobs:
409377
retention-days: 1
410378

411379
- name: Cleanup on failure
412-
if: failure() && steps.proposal-branch.outputs.branch_name != ''
380+
if: failure() && (steps.proposal-branch.outputs.branch_name != '' || steps.ephemeral-branch.outputs.ephemeral_branch != '')
413381
run: |
414382
BRANCH_NAME="${{ steps.proposal-branch.outputs.branch_name }}"
415-
echo "Job failed, deleting branch $BRANCH_NAME..."
416-
git push origin --delete "$BRANCH_NAME" || echo "Failed to delete branch (may not exist on remote)"
383+
if [ -n "$BRANCH_NAME" ]; then
384+
echo "Job failed, deleting branch $BRANCH_NAME..."
385+
git push origin --delete "$BRANCH_NAME" || echo "Failed to delete branch (may not exist on remote)"
386+
fi
387+
EPHEMERAL_BRANCH="${{ steps.ephemeral-branch.outputs.ephemeral_branch }}"
388+
if [ -n "$EPHEMERAL_BRANCH" ]; then
389+
echo "Deleting ephemeral release branch $EPHEMERAL_BRANCH..."
390+
git push origin --delete "$EPHEMERAL_BRANCH" || echo "Failed to delete ephemeral branch (may not exist on remote)"
391+
fi
417392
418393
outputs:
419394
branch_name: ${{ steps.proposal-branch.outputs.branch_name }}
395+
ephemeral_branch: ${{ steps.ephemeral-branch.outputs.ephemeral_branch }}
420396

421397
create-pr:
422398
needs: cargo-release
@@ -486,11 +462,18 @@ jobs:
486462
--title "chore(release): proposal for ${{ inputs.crate }}" \
487463
--body "$PR_BODY" \
488464
--label "release-proposal" \
489-
--base "${{ env.RELEASE_BRANCH }}"
465+
--base "${{ needs.cargo-release.outputs.ephemeral_branch }}"
490466
491467
- name: Cleanup on failure
492-
if: failure() && needs.cargo-release.outputs.branch_name != ''
468+
if: failure() && (needs.cargo-release.outputs.branch_name != '' || needs.cargo-release.outputs.ephemeral_branch != '')
493469
run: |
494470
BRANCH_NAME="${{ needs.cargo-release.outputs.branch_name }}"
495-
echo "Job failed, deleting branch $BRANCH_NAME..."
496-
git push origin --delete "$BRANCH_NAME" || echo "Failed to delete branch (may not exist on remote)"
471+
if [ -n "$BRANCH_NAME" ]; then
472+
echo "Job failed, deleting branch $BRANCH_NAME..."
473+
git push origin --delete "$BRANCH_NAME" || echo "Failed to delete branch (may not exist on remote)"
474+
fi
475+
EPHEMERAL_BRANCH="${{ needs.cargo-release.outputs.ephemeral_branch }}"
476+
if [ -n "$EPHEMERAL_BRANCH" ]; then
477+
echo "Deleting ephemeral release branch $EPHEMERAL_BRANCH..."
478+
git push origin --delete "$EPHEMERAL_BRANCH" || echo "Failed to delete ephemeral branch (may not exist on remote)"
479+
fi

0 commit comments

Comments
 (0)