|
2 | 2 | # |
3 | 3 | # devctl |
4 | 4 | # |
5 | | -# https://github.com/giantswarm/devctl/blob/771e68c7deeda0e8cbd4af23d718a34e708822e4/pkg/gen/input/workflows/internal/file/create_release_pr.yaml.template |
| 5 | +# https://github.com/giantswarm/devctl/blob/366c1c3aad2b9b02850a54854aba8108db3ce052/pkg/gen/input/workflows/internal/file/create_release_pr.yaml.template |
6 | 6 | # |
7 | 7 | name: Create Release PR |
8 | 8 | on: |
|
29 | 29 | branch: |
30 | 30 | required: true |
31 | 31 | type: string |
32 | | -jobs: |
33 | | - debug_info: |
34 | | - name: Debug info |
35 | | - runs-on: ubuntu-22.04 |
36 | | - steps: |
37 | | - - name: Print github context JSON |
38 | | - run: | |
39 | | - cat <<EOF |
40 | | - ${{ toJson(github) }} |
41 | | - EOF |
42 | | - gather_facts: |
43 | | - name: Gather facts |
44 | | - runs-on: ubuntu-22.04 |
45 | | - outputs: |
46 | | - repo_name: ${{ steps.gather_facts.outputs.repo_name }} |
47 | | - branch: ${{ steps.gather_facts.outputs.branch }} |
48 | | - base: ${{ steps.gather_facts.outputs.base }} |
49 | | - needs_major_bump: ${{ steps.gather_facts.outputs.needs_major_bump }} |
50 | | - skip: ${{ steps.pr_exists.outputs.skip }} |
51 | | - version: ${{ steps.gather_facts.outputs.version }} |
52 | | - steps: |
53 | | - - name: Gather facts |
54 | | - id: gather_facts |
55 | | - run: | |
56 | | - head="${{ inputs.branch || github.event.ref }}" |
57 | | - echo "branch=${head}" >> $GITHUB_OUTPUT |
58 | | -
|
59 | | - head="${head#refs/heads/}" # Strip "refs/heads/" prefix. |
60 | | - if [[ $(echo "$head" | grep -o '#' | wc -l) -gt 1 ]]; then |
61 | | - base="$(echo $head | cut -d '#' -f 1)" |
62 | | - else |
63 | | - base="${{ github.event.base_ref }}" |
64 | | - fi |
65 | | -
|
66 | | - base="${base#refs/heads/}" # Strip "refs/heads/" prefix. |
67 | | -
|
68 | | - version="$(echo $head | awk -F# '{print $NF}')" |
69 | | - if [[ $version =~ ^major|minor|patch$ ]]; then |
70 | | - gh auth login --with-token <<<$(echo -n ${{ secrets.TAYLORBOT_GITHUB_ACTION }}) |
71 | | - gh_api_get_latest_release_version() |
72 | | - { |
73 | | - if ! version="$(gh api "repos/$1/releases/latest" --jq '.tag_name[1:] | split(".") | .[0], .[1], .[2]')" |
74 | | - then |
75 | | - case "$version" in |
76 | | - *Not\ Found*) echo Assuming v0.0.0, hooray first release! >&2 ; version="0 0 0" ;; |
77 | | - *) version="" ; return 1 ;; |
78 | | - esac |
79 | | - fi |
80 | | - echo "$version" |
81 | | - } |
82 | | -
|
83 | | - version_parts=($(gh_api_get_latest_release_version "${{ github.repository }}")) |
84 | | - version_major=${version_parts[0]} |
85 | | - version_minor=${version_parts[1]} |
86 | | - version_patch=${version_parts[2]} |
87 | | - case ${version} in |
88 | | - patch) |
89 | | - version_patch=$((version_patch+1)) |
90 | | - ;; |
91 | | - minor) |
92 | | - version_minor=$((version_minor+1)) |
93 | | - version_patch=0 |
94 | | - ;; |
95 | | - major) |
96 | | - version_major=$((version_major+1)) |
97 | | - version_minor=0 |
98 | | - version_patch=0 |
99 | | - if [[ "${version_major}" != "1" ]]; then |
100 | | - echo "needs_major_bump=true" >> $GITHUB_OUTPUT |
101 | | - fi |
102 | | - ;; |
103 | | - *) |
104 | | - echo "Unknown Semver level provided" |
105 | | - exit 1 |
106 | | - ;; |
107 | | - esac |
108 | | - version="${version_major}.${version_minor}.${version_patch}" |
109 | | - else |
110 | | - version="${version#v}" # Strip "v" prefix. |
111 | | - version_major=$(echo "${version}" | cut -d "." -f 1) |
112 | | - version_minor=$(echo "${version}" | cut -d "." -f 2) |
113 | | - version_patch=$(echo "${version}" | cut -d "." -f 3) |
114 | | - # This will help us detect versions with suffixes as majors, i.e 3.0.0-alpha1. |
115 | | - # Even though it's a pre-release, it's still a major. |
116 | | - if [[ $version_minor = 0 && $version_patch =~ ^0.* && $version_major != 1 ]]; then |
117 | | - echo "needs_major_bump=true" >> $GITHUB_OUTPUT |
118 | | - fi |
119 | | - fi |
120 | | - repo_name="$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" |
121 | | - echo "repo_name=\"$repo_name\" base=\"$base\" head=\"$head\" version=\"$version\"" |
122 | | - echo "repo_name=${repo_name}" >> $GITHUB_OUTPUT |
123 | | - echo "base=${base}" >> $GITHUB_OUTPUT |
124 | | - echo "head=${head}" >> $GITHUB_OUTPUT |
125 | | - echo "version=${version}" >> $GITHUB_OUTPUT |
126 | | - - name: Check if PR exists |
127 | | - id: pr_exists |
128 | | - env: |
129 | | - GITHUB_TOKEN: "${{ secrets.TAYLORBOT_GITHUB_ACTION }}" |
130 | | - run: | |
131 | | - head="${{ steps.gather_facts.outputs.branch }}" |
132 | | - branch="${head#refs/heads/}" # Strip "refs/heads/" prefix. |
133 | | - if gh pr view --repo "${{ github.repository }}" "${branch}" --json state --jq .state | grep -i 'open' > /dev/null; then |
134 | | - gh pr view --repo "${{ github.repository }}" "${branch}" |
135 | | - echo "skip=true" >> $GITHUB_OUTPUT |
136 | | - else |
137 | | - echo "skip=false" >> $GITHUB_OUTPUT |
138 | | - fi |
139 | | - prepare_release_pr: |
140 | | - name: Prepare release PR for Backstage project |
141 | | - runs-on: ubuntu-22.04 |
142 | | - needs: |
143 | | - - gather_facts |
144 | | - if: ${{ needs.gather_facts.outputs.skip != 'true' && github.repository == 'giantswarm/backstage' }} |
145 | | - steps: |
146 | | - - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
147 | | - with: |
148 | | - ref: ${{ needs.gather_facts.outputs.branch }} |
149 | | - - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
150 | | - with: |
151 | | - node-version: '20' |
152 | | - - uses: borales/actions-yarn@3766bb1335b98fb13c60eaf358fe20811b730a88 # v5.0.0 |
153 | | - with: |
154 | | - cmd: install |
155 | | - - name: Prepare release PR |
156 | | - uses: borales/actions-yarn@3766bb1335b98fb13c60eaf358fe20811b730a88 # v5.0.0 |
157 | | - with: |
158 | | - cmd: release |
159 | | - env: |
160 | | - RELEASE_VERSION: ${{ needs.gather_facts.outputs.version }} |
161 | | - - name: Set up git identity |
162 | | - run: | |
163 | | - git config --local user.email "[email protected]" |
164 | | - git config --local user.name "taylorbot" |
165 | | - - name: Create commit |
166 | | - env: |
167 | | - version: "${{ needs.gather_facts.outputs.version }}" |
168 | | - run: | |
169 | | - git add -A |
170 | | - git commit -m "Prepare release v${{ env.version }}" |
171 | | - - name: Push changes |
172 | | - env: |
173 | | - remote_repo: "https://${{ github.actor }}:${{ secrets.TAYLORBOT_GITHUB_ACTION }}@github.com/${{ github.repository }}.git" |
174 | | - run: | |
175 | | - git push "${remote_repo}" HEAD:${{ needs.gather_facts.outputs.branch }} |
176 | | - create_release_pr: |
177 | | - name: Create release PR |
178 | | - runs-on: ubuntu-22.04 |
179 | | - needs: |
180 | | - - gather_facts |
181 | | - - prepare_release_pr |
182 | | - if: ${{ always() && needs.gather_facts.outputs.skip != 'true' }} |
183 | | - env: |
184 | | - architect_flags: "--organisation ${{ github.repository_owner }} --project ${{ needs.gather_facts.outputs.repo_name }}" |
185 | | - steps: |
186 | | - - uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0 |
187 | | - with: |
188 | | - go-version: '=1.23' |
189 | | - - name: Install architect |
190 | | - uses: giantswarm/install-binary-action@c37eb401e5092993fc76d545030b1d1769e61237 # v3.0.0 |
191 | | - with: |
192 | | - binary: "architect" |
193 | | - version: "6.17.0" |
194 | | - - name: Checkout code |
195 | | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
196 | | - with: |
197 | | - ref: ${{ needs.gather_facts.outputs.branch }} |
198 | | - - name: Prepare release changes |
199 | | - run: | |
200 | | - architect prepare-release ${{ env.architect_flags }} --version "${{ needs.gather_facts.outputs.version }}" |
201 | | - - name: Update version field in Chart.yaml |
202 | | - run: | |
203 | | - # Define chart_dir |
204 | | - repository="${{ needs.gather_facts.outputs.repo_name }}" |
205 | | - chart="helm/${repository}" |
206 | | -
|
207 | | - # Check chart directory. |
208 | | - if [ ! -d "${chart}" ] |
209 | | - then |
210 | | - echo "Could not find chart directory '${chart}', adding app suffix." |
211 | | -
|
212 | | - # Add app suffix. |
213 | | - chart="helm/${repository}-app" |
214 | 32 |
|
215 | | - # Check chart directory with app suffix. |
216 | | - if [ ! -d "${chart}" ] |
217 | | - then |
218 | | - echo "Could not find chart directory '${chart}', removing app suffix." |
219 | | -
|
220 | | - # Remove app suffix. |
221 | | - chart="helm/${repository%-app}" |
222 | | -
|
223 | | - if [ ! -d "${chart}" ] |
224 | | - then |
225 | | - # Print error. |
226 | | - echo "Could not find chart directory '${chart}', doing nothing." |
227 | | - fi |
228 | | - fi |
229 | | - fi |
230 | | -
|
231 | | - # Define chart YAML. |
232 | | - chart_yaml="${chart}/Chart.yaml" |
233 | | -
|
234 | | - # Check chart YAML. |
235 | | - if [ -f "${chart_yaml}" ] |
236 | | - then |
237 | | - # check if version in Chart.yaml is templated using architect |
238 | | - if [ $(grep -c "^version:.*\.Version.*$" "${chart_yaml}") = "0" ]; then |
239 | | - yq -i '.version = "${{ needs.gather_facts.outputs.version }}"' "${chart_yaml}" |
240 | | - fi |
241 | | - fi |
242 | | -
|
243 | | - - name: Bump go module defined in go.mod if needed |
244 | | - run: | |
245 | | - if [ "${{ needs.gather_facts.outputs.needs_major_bump }}" = true ] && test -f "go.mod"; then |
246 | | - go install github.com/marwan-at-work/mod/cmd/[email protected] |
247 | | - mod upgrade |
248 | | - fi |
249 | | - - name: Set up git identity |
250 | | - run: | |
251 | | - git config --local user.email "[email protected]" |
252 | | - git config --local user.name "taylorbot" |
253 | | - - name: Create release commit |
254 | | - env: |
255 | | - version: "${{ needs.gather_facts.outputs.version }}" |
256 | | - run: | |
257 | | - git add -A |
258 | | - git commit -m "Release v${{ env.version }}" |
259 | | - - name: Push changes |
260 | | - env: |
261 | | - remote_repo: "https://${{ github.actor }}:${{ secrets.TAYLORBOT_GITHUB_ACTION }}@github.com/${{ github.repository }}.git" |
262 | | - run: | |
263 | | - git push "${remote_repo}" HEAD:${{ needs.gather_facts.outputs.branch }} |
264 | | - - name: Create PR |
265 | | - env: |
266 | | - GITHUB_TOKEN: "${{ secrets.TAYLORBOT_GITHUB_ACTION }}" |
267 | | - base: "${{ needs.gather_facts.outputs.base }}" |
268 | | - version: "${{ needs.gather_facts.outputs.version }}" |
269 | | - run: | |
270 | | - gh pr create --assignee ${{ github.actor }} --title "Release v${{ env.version }}" --body "" --base ${{ env.base }} --head "${{ needs.gather_facts.outputs.branch }}" |
| 33 | +jobs: |
| 34 | + publish: |
| 35 | + uses: giantswarm/github-workflows/.github/workflows/create-release-pr.yaml@897ce7c11f81fcd01f7cf38e839a42848a63c7e7 |
| 36 | + with: |
| 37 | + branch: ${{ inputs.branch }} |
| 38 | + secrets: |
| 39 | + TAYLORBOT_GITHUB_ACTION: ${{ secrets.TAYLORBOT_GITHUB_ACTION }} |
0 commit comments