1616 PUSH_IMAGE : " True"
1717
1818jobs :
19+ check-allow-merge :
20+ runs-on : ubuntu-latest
21+ steps :
22+ # Labels in the context don't get updated so they are stuck at what's set during creation
23+ # We need this action to get current labels
24+ - name : Get current labels
25+ uses : snnaplab/get-labels-action@v1
26+ - name : Check if merge is allowed
27+ if : github.base_ref == 'master' && github.head_ref != 'develop'
28+ run : |
29+ ${{ contains(fromJSON(env.LABELS), 'hotfix') }} && exit 0
30+ echo "ERROR: You can only merge to master from develop or hotfixes."
31+ exit 1
1932 check-labels :
2033 # Act doesn't set a pull request number by default, so we skip if it's 0
2134 if : github.event.pull_request.number != 0
3144 runs-on : ubuntu-latest
3245 steps :
3346 - uses : actions/checkout@v4
47+ with :
48+ ref : ${{ github.event.pull_request.head.sha }}
3449
3550 - name : Determine Go version from go.mod
3651 run : echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
@@ -78,15 +93,18 @@ jobs:
7893 if : env.PUSH_UPBOUND == 'true' && env.PUSH_PACKAGE == 'true'
7994 run : make package-push-branchtag -e IMG_TAG="${{ steps.extract_branch.outputs.branch }}" -e IMG_REPO=xpkg.upbound.io
8095
81- open-pr-component :
82- if : github.event.action == 'opened'
96+ open-or-update-pr-component :
8397 runs-on : ubuntu-latest
8498 steps :
99+ - name : Get current labels
100+ uses : snnaplab/get-labels-action@v1
101+
85102 - name : Checkout code
86103 uses : actions/checkout@v4
87104 with :
88105 repository : ${{ env.COMPONENT_REPO }}
89106 token : ${{ secrets.GITHUB_TOKEN }}
107+ fetch-depth : 0
90108
91109 - name : Extract branch name
92110 shell : bash
@@ -102,21 +120,37 @@ jobs:
102120 - name : Generate new golden
103121 # Act uses the host's docker to run containers, but then
104122 # they can't access the files that were previously cloned.
105- if : github.event.pull_request.number != 0
123+ if : github.event.pull_request.number != 0 && github.event.action == 'opened'
106124 run : |
107125 make gen-golden-all
108126
127+ - name : Check if it's a hotfix
128+ id : hotfix_check
129+ run : |
130+ ${{ contains(fromJSON(env.LABELS), 'hotfix') }} && echo "base=master" >> $GITHUB_OUTPUT || echo "base=develop" >> $GITHUB_OUTPUT
131+
109132 - name : Create Pull Request
110- uses : peter-evans/create-pull-request@v6
133+ uses : peter-evans/create-pull-request@v7
134+ id : cpr
111135 with :
112136 token : ${{ secrets.COMPONENT_ACCESS_TOKEN }}
113- title : ' PR for ${{ env.APP_NAME }} on ${{ steps.extract_branch.outputs.branch }}'
114- body : " ${{ github.event.pull_request.body}}\n Link: ${{ github.event.pull_request.url }}"
137+ title : ${{ github.event.pull_request.title }}
138+ body : " ${{ github.event.pull_request.body}}\n Link: ${{ github.event.pull_request.html_url }}"
115139 branch : " ${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}"
116- base : master
140+ base : ${{ steps.hotfix_check.outputs.base }}
117141 draft : false
142+
143+ - name : Add link to component PR
144+ uses : tzkhan/pr-update-action@v2
145+ with :
146+ repo-token : " ${{ secrets.GITHUB_TOKEN }}"
147+ head-branch-regex : " ${{ steps.extract_branch.outputs.branch }}"
148+ body-template : |
149+ Component PR: ${{ steps.cpr.outputs.pull-request-url }}
150+ body-update-action : ' suffix'
151+ body-uppercase-base-match : false
118152 create-release :
119- if : github.event.pull_request.merged
153+ if : github.event.pull_request.merged && github.base_ref == 'master'
120154 runs-on : ubuntu-latest
121155 steps :
122156 - name : Check for patch label
@@ -201,6 +235,7 @@ jobs:
201235 repository : ${{ env.COMPONENT_REPO }}
202236 token : ${{ secrets.COMPONENT_ACCESS_TOKEN }}
203237 ref : " ${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}"
238+ fetch-depth : 0
204239
205240 - name : Update tag and run golden
206241 run : |
0 commit comments