-
Notifications
You must be signed in to change notification settings - Fork 4
214 lines (182 loc) · 7.7 KB
/
pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: PR Automation
on:
pull_request: {}
pull_request_target:
types:
- closed
branches:
- master
env:
APP_NAME: provider-minio
COMPONENT_REPO: vshn/component-appcat
UPBOUND_PUSH: True
jobs:
check-labels:
# Act doesn't set a pull request number by default, so we skip if it's 0
if: github.event.pull_request.number != 0
name: Check labels
runs-on: ubuntu-latest
steps:
- uses: docker://agilepathway/pull-request-label-checker:v1.6.51
with:
one_of: major,minor,patch,documentation,dependency
repo_token: ${{ secrets.GITHUB_TOKEN }}
publish-branch-images:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Determine Go version from go.mod
run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Extract escaped branch name
shell: bash
run: echo "branch=$(echo ${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}} | sed 's/\//_/g' )" >> $GITHUB_OUTPUT
id: extract_branch
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build branch and push AppCat
if: ${{ env.UPBOUND_PUSH }} == "False"
run: make docker-push-branchtag -e IMG_TAG="${{ steps.extract_branch.outputs.branch }}"
- name: Build branch and push package
run: make package-push-branchtag -e IMG_TAG="${{ steps.extract_branch.outputs.branch }}"
- name: Login to Upbound
if: ${{ env.UPBOUND_PUSH }} == "True"
uses: docker/login-action@v1
with:
registry: xpkg.upbound.io
username: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }}
password: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW }}
- name: Build branch and push package to upbound
if: ${{ env.UPBOUND_PUSH }} == "True"
run: make package-push-upbound-branchtag -e IMG_TAG="${{ steps.extract_branch.outputs.branch }}"
open-pr-component:
if: github.event.action == 'opened'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
repository: ${{ env.COMPONENT_REPO }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Update defaults.yml and create branch
run: |
yq e '.parameters.appcat.images.${{ env.APP_NAME }}.tag="${{ steps.extract_branch.outputs.branch }}"' class/defaults.yml | diff -B class/defaults.yml - | patch class/defaults.yml - || true
git --no-pager diff
- name: Generate new golden
# Act uses the host's docker to run containers, but then
# they can't access the files that were previously cloned.
if: github.event.pull_request.number != 0
run: |
make gen-golden-all
- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.COMPONENT_ACCESS_TOKEN }}
title: 'PR for ${{ env.APP_NAME }} on ${{ steps.extract_branch.outputs.branch }}'
body: "${{ github.event.pull_request.body}}\nLink: ${{ github.event.pull_request.url }}"
branch: "${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}"
base: master
draft: false
create-release:
if: github.event.pull_request.merged
runs-on: ubuntu-latest
steps:
- name: Check for patch label
if: contains(github.event.pull_request.labels.*.name, 'patch') || contains(github.event.pull_request.labels.*.name, 'dependencies') || contains(github.event.pull_request.labels.*.name, 'documentation')
id: patch
run: |
echo "set=true" >> $GITHUB_OUTPUT
- name: Check for minor label
if: contains(github.event.pull_request.labels.*.name, 'minor')
id: minor
run: |
echo "set=true" >> $GITHUB_OUTPUT
- name: Check for major label
if: contains(github.event.pull_request.labels.*.name, 'major')
id: major
run: |
echo "set=true" >> $GITHUB_OUTPUT
- uses: actions/checkout@v4
with:
# Make sure we use the right commit to tag
ref: ${{ github.event.pull_request.merge_commit_sha }}
# We also need to use the personal access token here. As subsequent
# actions will not trigger by tags/pushes that use `GITHUB_TOKEN`
# https://github.com/orgs/community/discussions/25702#discussioncomment-3248819
token: ${{ secrets.COMPONENT_ACCESS_TOKEN }}
# This is broken in checkout@v4...
# https://github.com/actions/checkout/issues/1781
fetch-tags: true
- name: fetch tags
run: |
git fetch --tags
echo "latest tag: $(git describe --tags "$(git rev-list --tags --max-count=1)")"
echo "TAG_VERSION=$(git describe --tags "$(git rev-list --tags --max-count=1)")" >> $GITHUB_ENV
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
# We only run this if any of the release tags is set.
# For docs and deps we don't do automagic releases
- name: Increase Tag
id: tag
run: |
patch=${{ steps.patch.outputs.set }}
minor=${{ steps.minor.outputs.set }}
major=${{ steps.major.outputs.set }}
major_ver=$(echo '${{ env.TAG_VERSION }}' | cut -d "." -f1)
minor_ver=$(echo '${{ env.TAG_VERSION }}' | cut -d "." -f2)
patch_ver=$(echo '${{ env.TAG_VERSION }}' | cut -d "." -f3)
major_ver="${major_ver:1}"
# Check for patch label
[ ! -z "$bug" ] && [ -z "$minor" ] && [ -z "$major" ] && ((patch_ver++)) || true
# check for minor label
if [ ! -z "$minor" ] && [ -z "$major" ]; then
((minor_ver++))
patch_ver=0
fi
# Check for major label
if [ ! -z "$major" ]; then
((major_ver++))
minor_ver=0
patch_ver=0
fi
tag="v$major_ver.$minor_ver.$patch_ver"
echo "new tag $tag"
git tag $tag
git push --tags
echo tag=$tag >> $GITHUB_OUTPUT
- name: Checkout component
uses: actions/checkout@v4
with:
repository: ${{ env.COMPONENT_REPO }}
token: ${{ secrets.COMPONENT_ACCESS_TOKEN }}
ref: "${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}"
- name: Update tag and run golden
run: |
yq e '.parameters.appcat.images.${{ env.APP_NAME }}.tag="${{ steps.tag.outputs.tag }}"' class/defaults.yml | diff -B class/defaults.yml - | patch class/defaults.yml - || true
make gen-golden-all
- name: Commit & Push changes
uses: actions-js/push@master
with:
github_token: ${{ secrets.COMPONENT_ACCESS_TOKEN }}
branch: "${{ env.APP_NAME }}/${{ github.event.pull_request.number }}/${{ steps.extract_branch.outputs.branch }}"
message: "Update tag"
repository: ${{ env.COMPONENT_REPO }}