Skip to content

Commit fb9397c

Browse files
authored
Automate release version generation [main] (#3267)
* Remove build_version file and references * Remove unused files
1 parent f93e581 commit fb9397c

7 files changed

+72
-151
lines changed

Diff for: .github/workflows/release-build-sign-upload.yml

+57-28
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,18 @@ run-name: "Release: Build Sign Upload [${{ github.ref_name }}]"
3838

3939
on:
4040
workflow_dispatch:
41+
inputs:
42+
release_version:
43+
description: 'Release version bump'
44+
required: true
45+
default: 'patch'
46+
type: choice
47+
options:
48+
- minor
49+
- patch
4150

4251
permissions:
43-
contents: read
52+
contents: write
4453

4554
defaults:
4655
run:
@@ -50,39 +59,56 @@ jobs:
5059
setup:
5160
name: Setup
5261
runs-on: ubuntu-latest
53-
62+
env:
63+
VERSION_MAJOR: 8
5464
outputs:
55-
aws-s3-bucket: "v${{ steps.parse-semver.outputs.version-major }}-cf-cli-releases"
65+
aws-s3-bucket: "v${{ steps.bump-version.outputs.version-major }}-cf-cli-releases"
5666

57-
version-build: ${{ steps.parse-semver.outputs.version-build }}
58-
version-major: ${{ steps.parse-semver.outputs.version-major }}
59-
version-minor: ${{ steps.parse-semver.outputs.version-minor }}
60-
version-patch: ${{ steps.parse-semver.outputs.version-patch }}
67+
version-build: ${{ steps.bump-version.outputs.version-build }}
68+
version-major: ${{ env.VERSION_MAJOR }}
69+
version-minor: ${{ steps.bump-version.outputs.version-minor }}
70+
version-patch: ${{ steps.bump-version.outputs.version-patch }}
6171

6272
steps:
6373
- name: Checkout cli
6474
uses: actions/checkout@v4
65-
66-
- name: Check if VERSION_BUILD matches tag ${{ github.ref }}
75+
76+
- name: Bump version
77+
id: bump-version
6778
run: |
68-
echo "Git Ref: ${{ github.ref }}"
69-
echo "VERSION_BUILD: $(cat BUILD_VERSION)"
79+
set -x
80+
git fetch --tags --quiet
81+
latest_tag="$(git tag | sort -V | grep v${VERSION_MAJOR} | tail -1)"
82+
echo "Latest tag is ${latest_tag}"
7083
71-
exit 0
84+
version="${latest_tag#[vV]}"
7285
73-
- name: Parse semver
74-
id: parse-semver
75-
run: |
76-
VERSION=$(cat BUILD_VERSION)
77-
VERSION="${VERSION#[vV]}"
86+
version_minor="${version#*.}"
87+
version_minor="${version_minor%.*}"
88+
version_patch=${version##*.}
7889
79-
VERSION_MINOR="${VERSION#*.}"
80-
VERSION_MINOR="${VERSION_MINOR%.*}"
90+
if [ "${{ inputs.release_version }}" == "minor" ]; then
91+
version_minor=$(($version_minor + 1))
92+
version_patch=0
93+
else
94+
version_patch=$(($version_patch + 1))
95+
fi
8196
82-
echo "version-build=${VERSION}" >> "${GITHUB_OUTPUT}"
83-
echo "version-major=${VERSION%%\.*}" >> "${GITHUB_OUTPUT}"
84-
echo "version-minor=${VERSION_MINOR}" >> "${GITHUB_OUTPUT}"
85-
echo "version-patch=${VERSION##*.}" >> "${GITHUB_OUTPUT}"
97+
new_version="${VERSION_MAJOR}.${version_minor}.${version_patch}"
98+
echo "new version is ${new_version}"
99+
100+
echo "version-build=${new_version}" >> "${GITHUB_OUTPUT}"
101+
echo "version-minor=${version_minor}" >> "${GITHUB_OUTPUT}"
102+
echo "version-patch=${version_patch}" >> "${GITHUB_OUTPUT}"
103+
104+
- name: Publish Tag
105+
run: |
106+
new_tag="v${{ steps.bump-version.outputs.version-build }}"
107+
echo "new version is $new_tag"
108+
git config user.name "GitHub Actions"
109+
git config user.email "[email protected]"
110+
git tag -am "Bump cli version ${new_tag}" ${new_tag}
111+
git push origin $new_tag
86112
87113
build-linux:
88114
name: Build Linux
@@ -135,6 +161,8 @@ jobs:
135161
${{ runner.os }}-go-
136162
137163
- name: Build Linux
164+
env:
165+
CF_BUILD_VERSION: ${VERSION_BUILD}
138166
run: |
139167
make out/cf-cli_linux_i686
140168
make out/cf-cli_linux_x86-64
@@ -252,7 +280,6 @@ jobs:
252280
name: cf-cli-linux-rpm-packages
253281
path: signed-redhat-installer/*.rpm
254282

255-
256283
- name: Build Debian Packages
257284
env:
258285
VERSION_BUILD: ${{ needs.setup.outputs.version-build }}
@@ -431,6 +458,8 @@ jobs:
431458
${{ runner.os }}-go-
432459
433460
- name: Build macOS Binaries
461+
env:
462+
CF_BUILD_VERSION: ${VERSION_BUILD}
434463
run: |
435464
make out/cf-cli_osx
436465
make out/cf-cli_macosarm
@@ -610,6 +639,8 @@ jobs:
610639
go install github.com/akavel/[email protected]
611640
612641
- name: Build CF CLI for Windows
642+
env:
643+
CF_BUILD_VERSION: ${VERSION_BUILD}
613644
run: |
614645
Get-Command make
615646
Get-Item Makefile
@@ -694,14 +725,12 @@ jobs:
694725
695726
- name: Zip Windows artifact
696727
run: |
697-
# strip leading v to go from tag -> semver
698-
$installer_release_version="$(cat BUILD_VERSION)".Replace("v", "")
699728
pushd "${env:RUNNER_TEMP}\win32"
700-
$installer_zip_filename="${env:RUNNER_TEMP}\cf${env:VERSION_MAJOR}-cli-installer_${installer_release_version}_win32.zip"
729+
$installer_zip_filename="${env:RUNNER_TEMP}\cf${env:VERSION_MAJOR}-cli-installer_${env:VERSION_BUILD}_win32.zip"
701730
Compress-Archive -DestinationPath "$installer_zip_filename" -Path *
702731
popd
703732
pushd "${env:RUNNER_TEMP}\winx64"
704-
$installer_zip_filename="${env:RUNNER_TEMP}\cf${env:VERSION_MAJOR}-cli-installer_${installer_release_version}_winx64.zip"
733+
$installer_zip_filename="${env:RUNNER_TEMP}\cf${env:VERSION_MAJOR}-cli-installer_${env:VERSION_BUILD}_winx64.zip"
705734
Compress-Archive -DestinationPath "$installer_zip_filename" -Path *
706735
popd
707736
Get-ChildItem "${env:RUNNER_TEMP}"

Diff for: .github/workflows/release-update-repos.yml

+15-36
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ run-name: "Release: Update Repositories [${{ github.ref_name }}]"
33

44
on:
55
workflow_dispatch:
6-
inputs:
7-
build_version:
8-
description: 'build version format: n.n.n'
9-
required: true
10-
type: string
116

127
permissions:
138
contents: write
@@ -20,21 +15,16 @@ jobs:
2015
setup:
2116
name: Setup
2217
runs-on: ubuntu-latest
23-
if: ${{ github.action_repository != 'cloudfoundry/cli' }}
18+
env:
19+
VERSION_MAJOR: 8
2420
outputs:
25-
secrets-environment: ${{ steps.set-secrets-environment.outputs.secrets-environment }}
26-
2721
version-build: ${{ steps.parse-semver.outputs.version-build }}
28-
version-major: ${{ steps.parse-semver.outputs.version-major }}
22+
version-major: ${{ env.VERSION_MAJOR }}
2923
version-minor: ${{ steps.parse-semver.outputs.version-minor }}
3024
version-patch: ${{ steps.parse-semver.outputs.version-patch }}
3125
claw-url: ${{ steps.set-claw-url.outputs.claw-url }}
3226

3327
steps:
34-
- name: Set environment
35-
id: set-secrets-environment
36-
run: echo "secrets-environment=PROD" >> "${GITHUB_OUTPUT}"
37-
3828
- name: Set CLAW URL
3929
id: set-claw-url
4030
run: echo "claw-url=https://packages.cloudfoundry.org" >> "${GITHUB_OUTPUT}"
@@ -45,18 +35,21 @@ jobs:
4535
- name: Parse semver
4636
id: parse-semver
4737
run: |
48-
VERSION=$(cat BUILD_VERSION)
49-
VERSION="${VERSION#[vV]}"
38+
git fetch --tags --quiet
39+
latest_tag="$(git tag | sort -V | grep v${VERSION_MAJOR} | tail -1)"
40+
echo "Latest tag is ${latest_tag}"
41+
42+
version="${latest_tag#[vV]}"
5043
51-
VERSION_MINOR="${VERSION#*.}"
52-
VERSION_MINOR="${VERSION_MINOR%.*}"
44+
version_minor="${version#*.}"
45+
version_minor="${version_minor%.*}"
5346
54-
echo "version-build=${VERSION}" >> "${GITHUB_OUTPUT}"
55-
echo "version-major=${VERSION%%\.*}" >> "${GITHUB_OUTPUT}"
56-
echo "version-minor=${VERSION_MINOR}" >> "${GITHUB_OUTPUT}"
57-
echo "version-patch=${VERSION##*.}" >> "${GITHUB_OUTPUT}"
47+
echo "version-build=${version}" >> "${GITHUB_OUTPUT}"
48+
echo "version-major=${version%%\.*}" >> "${GITHUB_OUTPUT}"
49+
echo "version-minor=${version_minor}" >> "${GITHUB_OUTPUT}"
50+
echo "version-patch=${version##*.}" >> "${GITHUB_OUTPUT}"
5851
59-
echo "VERSION_BUILD=${VERSION}" >> "${GITHUB_ENV}"
52+
echo "VERSION_BUILD=${version}" >> "${GITHUB_ENV}"
6053
6154
- name: Test if CLAW serve this version
6255
env:
@@ -71,7 +64,6 @@ jobs:
7164
name: Update Homebrew Repository
7265
runs-on: ubuntu-latest
7366
needs: setup
74-
environment: ${{ needs.setup.outputs.secrets-environment }}
7567
env:
7668
CLAW_URL: ${{ needs.setup.outputs.claw-url }}
7769
VERSION_BUILD: ${{ needs.setup.outputs.version-build }}
@@ -216,7 +208,6 @@ jobs:
216208
needs:
217209
- setup
218210
- update-homebrew
219-
environment: ${{ needs.setup.outputs.secrets-environment }}
220211
env:
221212
CLAW_URL: ${{ needs.setup.outputs.claw-url }}
222213
VERSION_BUILD: ${{ needs.setup.outputs.version-build }}
@@ -244,7 +235,6 @@ jobs:
244235
name: Update Debian Repository
245236
runs-on: ubuntu-20.04
246237
needs: setup
247-
environment: ${{ needs.setup.outputs.secrets-environment }}
248238
env:
249239
CLAW_URL: ${{ needs.setup.outputs.claw-url }}
250240
VERSION_BUILD: ${{ needs.setup.outputs.version-build }}
@@ -254,7 +244,6 @@ jobs:
254244
- name: Setup
255245
run: |
256246
echo "VERSION_BUILD: ${VERSION_BUILD}"
257-
echo "Environment: ${ENVIRONMENT}"
258247
259248
- name: Checkout
260249
uses: actions/checkout@v4
@@ -320,7 +309,6 @@ jobs:
320309
needs:
321310
- setup
322311
- update-deb
323-
environment: ${{ needs.setup.outputs.secrets-environment }}
324312
env:
325313
CLAW_URL: ${{ needs.setup.outputs.claw-url }}
326314
VERSION_BUILD: ${{ needs.setup.outputs.version-build }}
@@ -352,7 +340,6 @@ jobs:
352340
update-rpm:
353341
name: Update RPM Repository
354342
runs-on: ubuntu-latest
355-
environment: ${{ needs.setup.outputs.secrets-environment }}
356343
needs: setup
357344
env:
358345
CLAW_URL: ${{ needs.setup.outputs.claw-url }}
@@ -361,12 +348,8 @@ jobs:
361348
steps:
362349

363350
- name: Setup
364-
env:
365-
ENVIRONMENT: ${{ github.event.inputs.environment }}
366-
VERSION_BUILD: ${{ github.event.inputs.build_version }}
367351
run: |
368352
echo "VERSION_BUILD: ${VERSION_BUILD}"
369-
echo "Environment: ${ENVIRONMENT}"
370353
371354
# TODO: fix backup
372355
# - name: Download current RPM repodata
@@ -450,7 +433,6 @@ jobs:
450433
runs-on: ubuntu-latest
451434
container:
452435
image: fedora
453-
environment: ${{ needs.setup.outputs.secrets-environment }}
454436
env:
455437
CLAW_URL: ${{ needs.setup.outputs.claw-url }}
456438
VERSION_BUILD: ${{ needs.setup.outputs.version-build }}
@@ -480,7 +462,6 @@ jobs:
480462
run:
481463
shell: pwsh
482464
needs: setup
483-
environment: ${{ needs.setup.outputs.secrets-environment }}
484465
env:
485466
CLAW_URL: ${{ needs.setup.outputs.claw-url }}
486467
VERSION_BUILD: ${{ needs.setup.outputs.version-build }}
@@ -490,7 +471,6 @@ jobs:
490471
- name: Setup
491472
run: |
492473
echo "VERSION_BUILD: ${VERSION_BUILD}"
493-
echo "Environment: ${ENVIRONMENT}"
494474
495475
- name: Checkout
496476
uses: actions/checkout@v4
@@ -549,7 +529,6 @@ jobs:
549529
needs:
550530
- setup
551531
- update-windows
552-
environment: ${{ needs.setup.outputs.secrets-environment }}
553532
env:
554533
VERSION_BUILD: ${{ needs.setup.outputs.version-build }}
555534
VERSION_MAJOR: ${{ needs.setup.outputs.version-major }}

Diff for: BUILD_VERSION

-1
This file was deleted.

Diff for: Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ FLAKE_ATTEMPTS ?=5
44
PACKAGES ?= api actor command types util version integration/helpers
55
LC_ALL = "en_US.UTF-8"
66

7-
CF_BUILD_VERSION ?= $$(cat BUILD_VERSION) # TODO: version specific
87
CF_BUILD_SHA ?= $$(git rev-parse --short HEAD)
98
CF_BUILD_DATE ?= $$(date -u +"%Y-%m-%d")
109
LD_FLAGS_COMMON=-w -s \

Diff for: bin/bump-version

-50
This file was deleted.

0 commit comments

Comments
 (0)