Skip to content

Commit 046ac82

Browse files
authored
DOP-6147 base branch off of main with the new github action yml files (#14123)
1 parent ea87d78 commit 046ac82

File tree

3 files changed

+90
-7
lines changed

3 files changed

+90
-7
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Cleanup Temporary Branch
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
jobs:
9+
get-branch-name:
10+
uses: ./.github/workflows/generate-branch-name.yml
11+
with:
12+
pr_number: ${{ github.event.number }}
13+
14+
cleanup:
15+
needs: get-branch-name
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name:
22+
run: |
23+
BRANCH_NAME="${{ needs.get-branch-name.outputs.branch_name }}"
24+
echo "Looking for temp branch: $BRANCH_NAME"
25+
26+
# Check if branch exists and delete it
27+
if git ls-remote --heads origin $BRANCH_NAME | grep -q $BRANCH_NAME; then
28+
echo "Deleting temp branch: $BRANCH_NAME"
29+
git push origin --delete $BRANCH_NAME
30+
echo "Successfully deleted branch: $BRANCH_NAME"
31+
else
32+
echo "Branch $BRANCH_NAME not found, skipping cleanup"
33+
fi
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Generate Temp Branch Name
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
pr_number:
7+
required: true
8+
type: string
9+
outputs:
10+
branch_name:
11+
description: 'Generated temporary branch name'
12+
value: ${{ jobs.generate.outputs.branch_name }}
13+
14+
jobs:
15+
generate:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
branch_name: ${{ steps.name-gen.outputs.branch_name }}
19+
steps:
20+
- name: Generate branch name
21+
id: name-gen
22+
run: |
23+
git config --global user.name "GitHub Actions"
24+
git config --global user.email "[email protected]"
25+
BRANCH_NAME="temp-pr-${{ inputs.pr_number }}"
26+
echo "Generated branch name: $BRANCH_NAME"
27+
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,53 @@
11
name: Trigger branch builds on ToC Changes
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
branches:
66
- main
7-
- unified-toc-mvp
8-
- feat/unified-toc
7+
- 'feat/**'
98
paths:
109
- 'content/table-of-contents/**'
1110

11+
permissions:
12+
contents: write
13+
pull-requests: read
14+
1215
env:
1316
NETLIFY_ACCESS_TOKEN: ${{ secrets.NETLIFY_ACCESS_TOKEN }}
14-
PR_BRANCH: ${{ github.head_ref }}
17+
1518
jobs:
19+
get-branch-name:
20+
uses: ./.github/workflows/generate-branch-name.yml
21+
with:
22+
pr_number: ${{ github.event.number }}
23+
1624
trigger-branch-build:
25+
needs: get-branch-name
1726
runs-on: ubuntu-latest
1827
steps:
1928
- name: Checkout repository
2029
uses: actions/checkout@v4
30+
with:
31+
# This ensures we get the PR content for the path check
32+
ref: ${{ github.event.pull_request.head.sha }}
33+
34+
- name: Create temporary branch
35+
run: |
36+
BRANCH_NAME="${{ needs.get-branch-name.outputs.branch_name }}"
37+
echo "Retrieving temporary branch: $BRANCH_NAME"
38+
39+
# Push the current HEAD (with PR changes) to a new branch using full refspec
40+
git push origin HEAD:refs/heads/$BRANCH_NAME
41+
2142
- name: Install dependencies for table-of-contents
2243
run: npm install
2344
working-directory: ./content/table-of-contents
45+
2446
- name: Trigger Netlify Branch Build
2547
run: |
26-
echo "The PR branch is: $PR_BRANCH"
27-
# Triggering the branch deploy for $PR_BRANCH
28-
npm run api:build -- --branch=$PR_BRANCH
48+
BRANCH_NAME="${{ needs.get-branch-name.outputs.branch_name }}"
49+
echo "The temp branch is: $BRANCH_NAME"
50+
# Triggering the branch deploy for $BRANCH_NAME
51+
npm run api:build -- --branch=$BRANCH_NAME
2952
working-directory: ./content/table-of-contents
3053

0 commit comments

Comments
 (0)