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
@@ -78,15 +91,18 @@ jobs:
7891 if : env.PUSH_UPBOUND == 'true' && env.PUSH_PACKAGE == 'true'
7992 run : make package-push-branchtag -e IMG_TAG="${{ steps.extract_branch.outputs.branch }}" -e IMG_REPO=xpkg.upbound.io
8093
81- open-pr-component :
82- if : github.event.action == 'opened'
94+ open-or-update-pr-component :
8395 runs-on : ubuntu-latest
8496 steps :
97+ - name : Get current labels
98+ uses : snnaplab/get-labels-action@v1
99+
85100 - name : Checkout code
86101 uses : actions/checkout@v4
87102 with :
88103 repository : ${{ env.COMPONENT_REPO }}
89104 token : ${{ secrets.GITHUB_TOKEN }}
105+ history : 0
90106
91107 - name : Extract branch name
92108 shell : bash
@@ -102,19 +118,35 @@ jobs:
102118 - name : Generate new golden
103119 # Act uses the host's docker to run containers, but then
104120 # they can't access the files that were previously cloned.
105- if : github.event.pull_request.number != 0
121+ if : github.event.pull_request.number != 0 && github.event.action == 'opened'
106122 run : |
107123 make gen-golden-all
108124
125+ - name : Check if it's a hotfix
126+ id : hotfix_check
127+ run : |
128+ ${{ contains(fromJSON(env.LABELS), 'hotfix') }} && echo "base=master" >> $GITHUB_OUTPUT || echo "base=develop" >> $GITHUB_OUTPUT
129+
109130 - name : Create Pull Request
110- uses : peter-evans/create-pull-request@v6
131+ uses : peter-evans/create-pull-request@v7
132+ id : cpr
111133 with :
112134 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 }}"
135+ title : ${{ github.event.pull_request.title }}
136+ body : " ${{ github.event.pull_request.body}}\n Link: ${{ github.event.pull_request.html_url }}"
115137 branch : " ${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}"
116- base : master
138+ base : ${{ steps.hotfix_check.outputs.base }}
117139 draft : false
140+
141+ - name : Add link to component PR
142+ uses : tzkhan/pr-update-action@v2
143+ with :
144+ repo-token : " ${{ secrets.GITHUB_TOKEN }}"
145+ head-branch-regex : " ${{ steps.extract_branch.outputs.branch }}"
146+ body-template : |
147+ Component PR: ${{ steps.cpr.outputs.pull-request-url }}
148+ body-update-action : ' suffix'
149+ body-uppercase-base-match : false
118150 create-release :
119151 if : github.event.pull_request.merged
120152 runs-on : ubuntu-latest
0 commit comments