File tree Expand file tree Collapse file tree 3 files changed +61
-3
lines changed Expand file tree Collapse file tree 3 files changed +61
-3
lines changed Original file line number Diff line number Diff line change 1+ name : Create a hotfix branch
2+
3+ on :
4+ workflow_dispatch # manually triggered workflow on Actions
5+
6+ permissions :
7+ contents : write # Used to push hotfix branch
8+
9+ jobs :
10+ setup :
11+ runs-on : ubuntu-latest
12+ steps :
13+ - name : Checkout repo
14+ uses : actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62 # v4.1.3 https://github.com/actions/checkout/commit/cd7d8d697e10461458bc61a30d094dc601a8b017
15+ with :
16+ # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
17+ fetch-depth : 0
18+
19+ - name : Create hotfix branch
20+ env :
21+ HOTFIX_BRANCH : hotfix
22+ run : |
23+ # create hotfix branch from commit hash of the latest 'Version Packages'
24+ git checkout -b $HOTFIX_BRANCH $(git log origin/main -1 --grep='^Version Packages' --author='github-actions\[bot\]' --pretty=format:"%H")
25+ git push origin $HOTFIX_BRANCH
Original file line number Diff line number Diff line change @@ -97,11 +97,40 @@ jobs:
9797 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
9898 NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
9999
100+ create-pr-to-main :
101+ needs : setup
102+ if : ${{ needs.setup.outputs.has-changesets != 'true' }}
103+ runs-on : ubuntu-latest
104+ permissions :
105+ pull-requests : write
106+ env :
107+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
108+ BASE_BRANCH : " main"
109+ HEAD_BRANCH : " hotfix"
110+ steps :
111+ - name : Checkout repo
112+ uses : actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62 # v4.1.3 https://github.com/actions/checkout/commit/cd7d8d697e10461458bc61a30d094dc601a8b017
113+ # Check if hotfix -> main PR already exists
114+ - name : Check for existing PR
115+ id : check-pr
116+ run : |
117+ PR_EXISTS=$(gh pr list --base $BASE_BRANCH --head $HEAD_BRANCH --json number --jq 'length > 0')
118+ echo "exists=$PR_EXISTS" >> $GITHUB_OUTPUT
119+ # Create a new PR if one doesn't exist
120+ - name : Create PR to main
121+ if : steps.check-pr.outputs.exists == 'false'
122+ run : |
123+ gh pr create \
124+ --base $BASE_BRANCH \
125+ --head $HEAD_BRANCH \
126+ --title "chore: Merge hotfix into main" \
127+ --body "Merge the recently completed hotfix back into the main development branch. Generated by the publish-hotfix workflow."
128+
100129 log-failure-metric :
101130 # Send a failure data point to metric PublishLatestFailure in github-workflows@ us-east-2
102131 runs-on : ubuntu-latest
103132 environment : ci
104- needs : publish
133+ needs : create-pr-to-main
105134 if : ${{ failure() }}
106135 steps :
107136 - name : Log failure data point to metric PublishLatestFailure
@@ -116,7 +145,7 @@ jobs:
116145 # Send a success data point to metric PublishLatestFailure in github-workflows@ us-east-2
117146 runs-on : ubuntu-latest
118147 environment : ci
119- needs : publish
148+ needs : create-pr-to-main
120149 if : ${{ success() }}
121150 steps :
122151 - name : Log success data point to metric PublishLatestFailure
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ name: Version Packages
77
88on :
99 push :
10- branches : [main]
10+ branches : [main, hotfix ]
1111
1212permissions :
1313 contents : write # Used to commit to "Version Packages" PR
4242 uses : changesets/action@b98cec97583b917ff1dc6179dd4d230d3e439894
4343 with :
4444 version : yarn bumpVersions
45+ # Use the current branch as the base for the PR
46+ base : ${{ github.ref_name }}
47+ # Custom title based on branch
48+ title : ' Version Packages (${{ github.ref_name }})'
4549 env :
4650 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
You can’t perform that action at this time.
0 commit comments