16
16
PUSH_IMAGE : " True"
17
17
18
18
jobs :
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
19
32
check-labels :
20
33
# Act doesn't set a pull request number by default, so we skip if it's 0
21
34
if : github.event.pull_request.number != 0
31
44
runs-on : ubuntu-latest
32
45
steps :
33
46
- uses : actions/checkout@v4
47
+ with :
48
+ ref : ${{ github.event.pull_request.head.sha }}
34
49
35
50
- name : Determine Go version from go.mod
36
51
run : echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
@@ -78,15 +93,19 @@ jobs:
78
93
if : env.PUSH_UPBOUND == 'true' && env.PUSH_PACKAGE == 'true'
79
94
run : make package-push-branchtag -e IMG_TAG="${{ steps.extract_branch.outputs.branch }}" -e IMG_REPO=xpkg.upbound.io
80
95
81
- open-pr-component :
82
- if : github.event.action == 'opened'
96
+ open-or-update-pr-component :
83
97
runs-on : ubuntu-latest
98
+ if : github.base_ref == 'master'
84
99
steps :
100
+ - name : Get current labels
101
+ uses : snnaplab/get-labels-action@v1
102
+
85
103
- name : Checkout code
86
104
uses : actions/checkout@v4
87
105
with :
88
106
repository : ${{ env.COMPONENT_REPO }}
89
107
token : ${{ secrets.GITHUB_TOKEN }}
108
+ fetch-depth : 0
90
109
91
110
- name : Extract branch name
92
111
shell : bash
@@ -102,21 +121,37 @@ jobs:
102
121
- name : Generate new golden
103
122
# Act uses the host's docker to run containers, but then
104
123
# they can't access the files that were previously cloned.
105
- if : github.event.pull_request.number != 0
124
+ if : github.event.pull_request.number != 0 && github.event.action == 'opened'
106
125
run : |
107
126
make gen-golden-all
108
127
128
+ - name : Check if it's a hotfix
129
+ id : hotfix_check
130
+ run : |
131
+ ${{ contains(fromJSON(env.LABELS), 'hotfix') }} && echo "base=master" >> $GITHUB_OUTPUT || echo "base=develop" >> $GITHUB_OUTPUT
132
+
109
133
- name : Create Pull Request
110
- uses : peter-evans/create-pull-request@v6
134
+ uses : peter-evans/create-pull-request@v7
135
+ id : cpr
111
136
with :
112
137
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 }}"
138
+ title : ${{ github.event.pull_request.title }}
139
+ body : " ${{ github.event.pull_request.body}}\n Link: ${{ github.event.pull_request.html_url }}"
115
140
branch : " ${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}"
116
- base : master
141
+ base : ${{ steps.hotfix_check.outputs.base }}
117
142
draft : false
143
+
144
+ - name : Add link to component PR
145
+ uses : tzkhan/pr-update-action@v2
146
+ with :
147
+ repo-token : " ${{ secrets.GITHUB_TOKEN }}"
148
+ head-branch-regex : " ${{ steps.extract_branch.outputs.branch }}"
149
+ body-template : |
150
+ Component PR: ${{ steps.cpr.outputs.pull-request-url }}
151
+ body-update-action : ' suffix'
152
+ body-uppercase-base-match : false
118
153
create-release :
119
- if : github.event.pull_request.merged
154
+ if : github.event.pull_request.merged && github.base_ref == 'master'
120
155
runs-on : ubuntu-latest
121
156
steps :
122
157
- name : Check for patch label
@@ -201,6 +236,7 @@ jobs:
201
236
repository : ${{ env.COMPONENT_REPO }}
202
237
token : ${{ secrets.COMPONENT_ACCESS_TOKEN }}
203
238
ref : " ${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}"
239
+ fetch-depth : 0
204
240
205
241
- name : Update tag and run golden
206
242
run : |
0 commit comments