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
2235 name : Check labels
2336 runs-on : ubuntu-latest
2437 steps :
38+ - name : Ignore from Changelog if merge to master
39+ uses : actions-ecosystem/action-add-labels@v1
40+ if : github.base_ref == 'master'
41+ with :
42+ labels : ignoreChangelog
43+
2544 - uses : docker://agilepathway/pull-request-label-checker:v1.6.51
2645 with :
2746 one_of : major,minor,patch,documentation,dependency
3150 runs-on : ubuntu-latest
3251 steps :
3352 - uses : actions/checkout@v4
53+ with :
54+ ref : ${{ github.event.pull_request.head.sha }}
3455
3556 - name : Determine Go version from go.mod
3657 run : echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
@@ -79,14 +100,18 @@ jobs:
79100 run : make package-push-branchtag -e IMG_TAG="${{ steps.extract_branch.outputs.branch }}" -e IMG_REPO=xpkg.upbound.io
80101
81102 open-pr-component :
82- if : github.event.action == 'opened'
83103 runs-on : ubuntu-latest
104+ if : github.event.pull_request.number != 0 && github.event.action == 'opened'
84105 steps :
106+ - name : Get current labels
107+ uses : snnaplab/get-labels-action@v1
108+
85109 - name : Checkout code
86110 uses : actions/checkout@v4
87111 with :
88112 repository : ${{ env.COMPONENT_REPO }}
89113 token : ${{ secrets.GITHUB_TOKEN }}
114+ fetch-depth : 0
90115
91116 - name : Extract branch name
92117 shell : bash
@@ -102,21 +127,44 @@ jobs:
102127 - name : Generate new golden
103128 # Act uses the host's docker to run containers, but then
104129 # they can't access the files that were previously cloned.
105- if : github.event.pull_request.number != 0
130+ if : github.event.pull_request.number != 0 && github.event.action == 'opened'
106131 run : |
107132 make gen-golden-all
108133
134+ - name : Check if it's a hotfix
135+ id : hotfix_check
136+ run : |
137+ ${{ contains(fromJSON(env.LABELS), 'hotfix') }} && echo "base=master" >> $GITHUB_OUTPUT || echo "base=develop" >> $GITHUB_OUTPUT
138+
109139 - name : Create Pull Request
110- uses : peter-evans/create-pull-request@v6
140+ uses : peter-evans/create-pull-request@v7
141+ id : cpr
111142 with :
112143 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 }}"
144+ title : ${{ github.event.pull_request.title }}
145+ body : " ${{ github.event.pull_request.body}}\n Link: ${{ github.event.pull_request.html_url }}"
115146 branch : " ${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}"
116- base : master
147+ base : ${{ steps.hotfix_check.outputs.base }}
117148 draft : false
149+
150+ - name : Add link to component PR
151+ uses : tzkhan/pr-update-action@v2
152+ with :
153+ repo-token : " ${{ secrets.GITHUB_TOKEN }}"
154+ head-branch-regex : " ${{ steps.extract_branch.outputs.branch }}"
155+ body-template : |
156+ Component PR: ${{ steps.cpr.outputs.pull-request-url }}
157+ body-update-action : ' suffix'
158+ body-uppercase-base-match : false
159+
160+ - name : Ignore from Changelog if merge to master
161+ uses : actions-ecosystem/action-add-labels@v1
162+ if : github.base_ref == 'master' && github.event.action == 'opened'
163+ with :
164+ labels : ignoreChangelog
165+
118166 create-release :
119- if : github.event.pull_request.merged
167+ if : github.event.pull_request.merged && github.base_ref == 'master'
120168 runs-on : ubuntu-latest
121169 steps :
122170 - name : Check for patch label
@@ -201,6 +249,7 @@ jobs:
201249 repository : ${{ env.COMPONENT_REPO }}
202250 token : ${{ secrets.COMPONENT_ACCESS_TOKEN }}
203251 ref : " ${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}"
252+ fetch-depth : 0
204253
205254 - name : Update tag and run golden
206255 run : |
0 commit comments