|
2 | 2 | # |
3 | 3 | # devctl |
4 | 4 | # |
5 | | -# https://github.com/giantswarm/devctl/blob/72df19d0bff1cc8a679b00fdb4ac4e2504f8962a/pkg/gen/input/workflows/internal/file/create_release.yaml.template |
| 5 | +# https://github.com/giantswarm/devctl/blob/0df8c5e633bb1e4fd17c35525a7b382395526f22/pkg/gen/input/workflows/internal/file/create_release.yaml.template |
6 | 6 | # |
7 | 7 | name: Create Release |
| 8 | + |
8 | 9 | on: |
9 | 10 | push: |
10 | 11 | branches: |
|
18 | 19 | permissions: {} |
19 | 20 |
|
20 | 21 | jobs: |
21 | | - debug_info: |
22 | | - name: Debug info |
23 | | - runs-on: ubuntu-22.04 |
24 | | - steps: |
25 | | - - name: Print github context JSON |
26 | | - run: | |
27 | | - cat <<EOF |
28 | | - ${{ toJson(github) }} |
29 | | - EOF |
30 | | - gather_facts: |
31 | | - name: Gather facts |
32 | | - runs-on: ubuntu-22.04 |
33 | | - permissions: |
34 | | - contents: read |
35 | | - outputs: |
36 | | - project_go_path: ${{ steps.get_project_go_path.outputs.path }} |
37 | | - ref_version: ${{ steps.ref_version.outputs.refversion }} |
38 | | - version: ${{ steps.get_version.outputs.version }} |
39 | | - steps: |
40 | | - - name: Get version |
41 | | - id: get_version |
42 | | - env: |
43 | | - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} |
44 | | - run: | |
45 | | - title=$(echo -n "${COMMIT_MESSAGE}" | head -1) |
46 | | - # Matches strings like: |
47 | | - # |
48 | | - # - "Release v1.2.3" |
49 | | - # - "Release v1.2.3-r4" |
50 | | - # - "Release v1.2.3 (#56)" |
51 | | - # - "Release v1.2.3-r4 (#56)" |
52 | | - # |
53 | | - # And outputs version part (1.2.3). |
54 | | - if echo "${title}" | grep -iqE '^Release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then |
55 | | - version=$(echo "${title}" | cut -d ' ' -f 2) |
56 | | - fi |
57 | | - version="${version#v}" # Strip "v" prefix. |
58 | | - echo "version=\"${version}\"" |
59 | | - echo "version=${version}" >> $GITHUB_OUTPUT |
60 | | - - name: Checkout code |
61 | | - if: ${{ steps.get_version.outputs.version != '' }} |
62 | | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
63 | | - - name: Get project.go path |
64 | | - id: get_project_go_path |
65 | | - if: ${{ steps.get_version.outputs.version != '' }} |
66 | | - run: | |
67 | | - path='./pkg/project/project.go' |
68 | | - if [[ ! -f $path ]] ; then |
69 | | - path='' |
70 | | - fi |
71 | | - echo "path=\"$path\"" |
72 | | - echo "path=${path}" >> $GITHUB_OUTPUT |
73 | | - - name: Check if reference version |
74 | | - id: ref_version |
75 | | - env: |
76 | | - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} |
77 | | - run: | |
78 | | - title=$(echo -n "${COMMIT_MESSAGE}" | head -1) |
79 | | - if echo "${title}" | grep -qE '^release v[0-9]+\.[0-9]+\.[0-9]+([.-][^ .-][^ ]*)?( \(#[0-9]+\))?$' ; then |
80 | | - version=$(echo "${title}" | cut -d ' ' -f 2) |
81 | | - fi |
82 | | - version=$(echo "${title}" | cut -d ' ' -f 2) |
83 | | - version="${version#v}" # Strip "v" prefix. |
84 | | - refversion=false |
85 | | - if [[ "${version}" =~ ^[0-9]+.[0-9]+.[0-9]+-[0-9]+$ ]]; then |
86 | | - refversion=true |
87 | | - fi |
88 | | - echo "refversion =\"${refversion}\"" |
89 | | - echo "refversion=${refversion}" >> $GITHUB_OUTPUT |
90 | | - update_project_go: |
91 | | - name: Update project.go |
92 | | - runs-on: ubuntu-22.04 |
93 | | - permissions: |
94 | | - contents: read |
95 | | - if: ${{ needs.gather_facts.outputs.version != '' && needs.gather_facts.outputs.project_go_path != '' && needs.gather_facts.outputs.ref_version != 'true' }} |
96 | | - needs: |
97 | | - - gather_facts |
98 | | - steps: |
99 | | - - name: Install architect |
100 | | - uses: giantswarm/install-binary-action@c94c7adadeb14af4bdbdd601f9a6e7f69638134c # v4.0.0 |
101 | | - with: |
102 | | - binary: "architect" |
103 | | - version: "6.14.1" |
104 | | - - name: Install semver |
105 | | - uses: giantswarm/install-binary-action@c94c7adadeb14af4bdbdd601f9a6e7f69638134c # v4.0.0 |
106 | | - with: |
107 | | - binary: "semver" |
108 | | - version: "3.2.0" |
109 | | - download_url: "https://github.com/fsaintjacques/${binary}-tool/archive/${version}.tar.gz" |
110 | | - tarball_binary_path: "*/src/${binary}" |
111 | | - smoke_test: "${binary} --version" |
112 | | - - name: Checkout code |
113 | | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
114 | | - with: |
115 | | - persist-credentials: false |
116 | | - - name: Update project.go |
117 | | - id: update_project_go |
118 | | - env: |
119 | | - branch: "${{ github.ref }}-version-bump" |
120 | | - run: | |
121 | | - git checkout -b ${{ env.branch }} |
122 | | - file="${{ needs.gather_facts.outputs.project_go_path }}" |
123 | | - version="${{ needs.gather_facts.outputs.version }}" |
124 | | - new_version="$(semver bump patch $version)-dev" |
125 | | - echo "version=\"$version\" new_version=\"$new_version\"" |
126 | | - echo "new_version=${new_version}" >> $GITHUB_OUTPUT |
127 | | - sed -Ei "s/(version[[:space:]]*=[[:space:]]*)\"${version}\"/\1\"${new_version}\"/" $file |
128 | | - if git diff --exit-code $file ; then |
129 | | - echo "error: no changes in \"$file\"" >&2 |
130 | | - exit 1 |
131 | | - fi |
132 | | - - name: Set up git identity |
133 | | - run: | |
134 | | - git config --local user.email "dev@giantswarm.io" |
135 | | - git config --local user.name "taylorbot" |
136 | | - - name: Commit changes |
137 | | - run: | |
138 | | - file="${{ needs.gather_facts.outputs.project_go_path }}" |
139 | | - git add $file |
140 | | - git commit -m "Bump version to ${{ steps.update_project_go.outputs.new_version }}" |
141 | | - - name: Push changes |
142 | | - env: |
143 | | - REMOTE_REPO: "https://${{ github.actor }}:${{ secrets.TAYLORBOT_GITHUB_ACTION }}@github.com/${{ github.repository }}.git" |
144 | | - branch: "${{ github.ref }}-version-bump" |
145 | | - run: | |
146 | | - git push "${REMOTE_REPO}" HEAD:${{ env.branch }} |
147 | | - - name: Create PR |
148 | | - env: |
149 | | - GITHUB_TOKEN: "${{ secrets.TAYLORBOT_GITHUB_ACTION }}" |
150 | | - base: "${{ github.ref }}" |
151 | | - branch: "${{ github.ref }}-version-bump" |
152 | | - version: "${{ needs.gather_facts.outputs.version }}" |
153 | | - title: "Bump version to ${{ steps.update_project_go.outputs.new_version }}" |
154 | | - run: | |
155 | | - gh pr create --title "${{ env.title }}" --body "" --base ${{ env.base }} --head ${{ env.branch }} --reviewer ${{ github.actor }} |
156 | | - - name: Enable auto-merge for PR |
157 | | - env: |
158 | | - GITHUB_TOKEN: "${{ secrets.TAYLORBOT_GITHUB_ACTION }}" |
159 | | - base: "${{ github.ref }}" |
160 | | - branch: "${{ github.ref }}-version-bump" |
161 | | - version: "${{ needs.gather_facts.outputs.version }}" |
162 | | - title: "Bump version to ${{ steps.update_project_go.outputs.new_version }}" |
163 | | - run: | |
164 | | - gh pr merge --auto --squash "${{ env.branch }}" || echo "::warning::Auto-merge not allowed. Please adjust the repository settings." |
165 | | - create_release: |
166 | | - name: Create release |
167 | | - runs-on: ubuntu-22.04 |
168 | | - permissions: |
169 | | - contents: read |
170 | | - needs: |
171 | | - - gather_facts |
172 | | - if: ${{ needs.gather_facts.outputs.version }} |
173 | | - outputs: |
174 | | - upload_url: ${{ steps.create_gh_release.outputs.upload_url }} |
175 | | - steps: |
176 | | - - name: Checkout code |
177 | | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
178 | | - with: |
179 | | - ref: ${{ github.sha }} |
180 | | - persist-credentials: false |
181 | | - - name: Ensure correct version in project.go |
182 | | - if: ${{ needs.gather_facts.outputs.project_go_path != '' && needs.gather_facts.outputs.ref_version != 'true' }} |
183 | | - run: | |
184 | | - file="${{ needs.gather_facts.outputs.project_go_path }}" |
185 | | - version="${{ needs.gather_facts.outputs.version }}" |
186 | | - grep -qE "version[[:space:]]*=[[:space:]]*\"$version\"" $file |
187 | | - - name: Get Changelog Entry |
188 | | - id: changelog_reader |
189 | | - uses: mindsers/changelog-reader-action@32aa5b4c155d76c94e4ec883a223c947b2f02656 # v2.2.3 |
190 | | - with: |
191 | | - version: ${{ needs.gather_facts.outputs.version }} |
192 | | - path: ./CHANGELOG.md |
193 | | - - name: Set up git identity |
194 | | - run: | |
195 | | - git config --local user.email "dev@giantswarm.io" |
196 | | - git config --local user.name "taylorbot" |
197 | | - - name: Create tag |
198 | | - run: | |
199 | | - version="${{ needs.gather_facts.outputs.version }}" |
200 | | - git tag "v$version" ${{ github.sha }} |
201 | | - - name: Push tag |
202 | | - env: |
203 | | - REMOTE_REPO: "https://${{ github.actor }}:${{ secrets.TAYLORBOT_GITHUB_ACTION }}@github.com/${{ github.repository }}.git" |
204 | | - run: | |
205 | | - git push "${REMOTE_REPO}" --tags |
206 | | - - name: Create release |
207 | | - id: create_gh_release |
208 | | - uses: ncipollo/release-action@b7eabc95ff50cbeeedec83973935c8f306dfcd0b # v1.20.0 |
209 | | - with: |
210 | | - body: ${{ steps.changelog_reader.outputs.changes }} |
211 | | - tag: "v${{ needs.gather_facts.outputs.version }}" |
212 | | - token: ${{ secrets.TAYLORBOT_GITHUB_ACTION }} |
213 | | - skipIfReleaseExists: true |
214 | | - |
215 | | - create-release-branch: |
216 | | - name: Create release branch |
217 | | - runs-on: ubuntu-22.04 |
| 22 | + create-release: |
| 23 | + uses: giantswarm/github-workflows/.github/workflows/create-release.yaml@main |
| 24 | + with: |
| 25 | + build-release-artifacts: false |
| 26 | + fetch-deep-gitlog-for-build: true |
| 27 | + secrets: |
| 28 | + TAYLORBOT_GITHUB_ACTION: ${{ secrets.TAYLORBOT_GITHUB_ACTION }} |
218 | 29 | permissions: |
219 | 30 | contents: write |
220 | | - needs: |
221 | | - - gather_facts |
222 | | - if: ${{ needs.gather_facts.outputs.version }} |
223 | | - steps: |
224 | | - - name: Install semver |
225 | | - uses: giantswarm/install-binary-action@c94c7adadeb14af4bdbdd601f9a6e7f69638134c # v4.0.0 |
226 | | - with: |
227 | | - binary: "semver" |
228 | | - version: "3.0.0" |
229 | | - download_url: "https://github.com/fsaintjacques/${binary}-tool/archive/${version}.tar.gz" |
230 | | - tarball_binary_path: "*/src/${binary}" |
231 | | - smoke_test: "${binary} --version" |
232 | | - - name: Check out the repository |
233 | | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
234 | | - with: |
235 | | - fetch-depth: 0 # Clone the whole history, not just the most recent commit. |
236 | | - - name: Fetch all tags and branches |
237 | | - run: "git fetch --all" |
238 | | - - name: Create long-lived release branch |
239 | | - run: | |
240 | | - current_version="${{ needs.gather_facts.outputs.version }}" |
241 | | - parent_version="$(git describe --tags --abbrev=0 HEAD^ || true)" |
242 | | - parent_version="${parent_version#v}" # Strip "v" prefix. |
243 | | -
|
244 | | - if [[ -z "$parent_version" ]] ; then |
245 | | - echo "Unable to find a parent tag version. No branch to create." |
246 | | - exit 0 |
247 | | - fi |
248 | | -
|
249 | | - echo "current_version=$current_version parent_version=$parent_version" |
250 | | -
|
251 | | - current_major=$(semver get major $current_version) |
252 | | - current_minor=$(semver get minor $current_version) |
253 | | - parent_major=$(semver get major $parent_version) |
254 | | - parent_minor=$(semver get minor $parent_version) |
255 | | - echo "current_major=$current_major current_minor=$current_minor parent_major=$parent_major parent_minor=$parent_minor" |
256 | | -
|
257 | | - if [[ $current_major -gt $parent_major ]] ; then |
258 | | - echo "Current tag is a new major version" |
259 | | - elif [[ $current_major -eq $parent_major ]] && [[ $current_minor -gt $parent_minor ]] ; then |
260 | | - echo "Current tag is a new minor version" |
261 | | - else |
262 | | - echo "Current tag is not a new major or minor version. Nothing to do here." |
263 | | - exit 0 |
264 | | - fi |
265 | | -
|
266 | | - release_branch="release-v${parent_major}.${parent_minor}.x" |
267 | | - echo "release_branch=$release_branch" |
268 | | -
|
269 | | - if git rev-parse --verify $release_branch ; then |
270 | | - echo "Release branch $release_branch already exists. Nothing to do here." |
271 | | - exit 0 |
272 | | - fi |
273 | | -
|
274 | | - git branch $release_branch HEAD^ |
275 | | - git push origin $release_branch |
0 commit comments