Skip to content

Commit 0f2d19d

Browse files
authored
CLOUDP-238747: Fix CI release flow (#1497)
Signed-off-by: jose.vazquez <jose.vazquez@mongodb.com>
1 parent 39e420e commit 0f2d19d

File tree

3 files changed

+76
-45
lines changed

3 files changed

+76
-45
lines changed

.github/workflows/release-post-merge.yml

Lines changed: 33 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
name: Create Release
66

77
on:
8-
pull_request:
9-
branches:
10-
- pre-release/**
11-
- release/**
12-
types:
13-
- closed
14-
workflow_dispatch:
8+
push:
9+
tags:
10+
- 'v*'
11+
workflow_call:
1512
inputs:
16-
version:
17-
description: "Release version (Be sure `Release-branch` is successful):"
13+
tag:
14+
type: string
15+
description: "Name of existing tag (or branch) to release (format should be 'v*')"
1816
required: true
19-
branch:
20-
description: "Name of the branch to release, defaults to 'main'"
21-
default: main
17+
workflow_dispatch:
18+
inputs:
19+
tag:
20+
type: string
21+
description: "Name of existing tag (or branch) to release (format should be 'v*')"
2222
required: true
2323
image_repo:
2424
type: choice
@@ -56,15 +56,12 @@ jobs:
5656
create-release:
5757
environment: release
5858
name: Create Release
59-
if: github.event.pull_request.merged == true || github.event_name != 'workflow_dispatch'
6059
runs-on: ubuntu-latest
6160
env:
62-
IMAGE_REPOSITORY: ${{ github.event.inputs.image_repo }}
6361
RELEASE_HELM: ${{ github.event.inputs.release_helm || 'true' }}
6462
CERTIFY: ${{ github.event.inputs.certify || 'true' }}
6563
RELEASE_TO_GITHUB: ${{ github.event.inputs.release_to_github || 'true' }}
66-
BRANCH: ${{ github.event.inputs.branch || github.head_ref || github.ref_name || 'main' }}
67-
VERSION: ${{ github.event.inputs.version }}
64+
TAG: ${{ github.event.inputs.tag || github.head_ref || github.ref_name }}
6865
steps:
6966
- name: Free disk space
7067
run: |
@@ -76,39 +73,30 @@ jobs:
7673
- name: Check release and show environment & version
7774
id: tag
7875
run: |
79-
version="$VERSION"
80-
if [[ "$version" == "" ]]; then
81-
version=$(echo "$BRANCH" | awk -F '/' '{print $2}')
82-
release=$(echo "$BRANCH" | awk -F '/' '{print $1}')
83-
if [[ "$release" == "release" ]]; then
84-
echo "Releasing version $version..."
85-
repo="mongodb/mongodb-atlas-kubernetes-operator"
86-
elif [[ "$release" == "pre-release" ]]; then
87-
echo "Pre-releasing version $version..."
88-
repo="mongodb/mongodb-atlas-kubernetes-operator-prerelease"
89-
RELEASE_HELM=false
90-
CERTIFY=false
91-
RELEASE_TO_GITHUB=false
92-
else
93-
echo "Release branch must be 'release/...' or 'pre-release/...' but got: $release"
94-
exit 1
95-
fi
76+
version=$(echo "${TAG}" |awk -F'^v' '{print $2}')
77+
prerelease_tail=$(echo "${version}" | awk -F'-' '{print $2}')
78+
if [[ "$prerelease_tail" == "" ]]; then
79+
echo "Releasing version $version..."
80+
repo="mongodb/mongodb-atlas-kubernetes-operator"
81+
else
82+
echo "Pre-releasing version $version..."
83+
repo="mongodb/mongodb-atlas-kubernetes-operator-prerelease"
84+
RELEASE_HELM=false
85+
CERTIFY=false
86+
RELEASE_TO_GITHUB=false
9687
fi
97-
tag="v${version}"
98-
certified_version="${version}-certified"
99-
echo "release_helm=$RELEASE_HELM" >> "$GITHUB_OUTPUT"
100-
echo "certify=$CERTIFY" >> "$GITHUB_OUTPUT"
101-
echo "release_to_github=$RELEASE_TO_GITHUB" >> "$GITHUB_OUTPUT"
102-
echo "repo=$repo" >> "$GITHUB_OUTPUT"
103-
echo "version=$version" >> "$GITHUB_OUTPUT"
104-
echo "tag=$tag" >> "$GITHUB_OUTPUT"
105-
echo "certified_version=$certified_version" >> "$GITHUB_OUTPUT"
88+
echo "release_helm=${RELEASE_HELM}" >> "$GITHUB_OUTPUT"
89+
echo "certify=${CERTIFY}" >> "$GITHUB_OUTPUT"
90+
echo "release_to_github=${RELEASE_TO_GITHUB}" >> "$GITHUB_OUTPUT"
91+
echo "repo=${repo}" >> "$GITHUB_OUTPUT"
92+
echo "version=${version}" >> "$GITHUB_OUTPUT"
93+
echo "certified_version=${version}-certified" >> "$GITHUB_OUTPUT"
10694
- name: Check out code
10795
uses: actions/checkout@v4
10896
with:
10997
submodules: true
11098
fetch-depth: 0
111-
ref: ${{ env.BRANCH }}
99+
ref: ${{ env.TAG }}
112100
- name: Set up Go
113101
if: ${{ steps.tag.outputs.release_helm == 'true' }}
114102
uses: actions/setup-go@v5
@@ -218,8 +206,8 @@ jobs:
218206
env:
219207
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
220208
with:
221-
tag_name: ${{ steps.tag.outputs.tag }}
222-
release_name: ${{ steps.tag.outputs.tag }}
209+
tag_name: ${{ env.TAG }}
210+
release_name: ${{ env.TAG }}
223211
body_path: docs/release-notes/release-notes.md
224212
draft: true
225213
prerelease: false

.github/workflows/tag.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Tag Release
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
jobs:
9+
tag-release:
10+
if: (github.event.pull_request.merged == true && (startsWith(github.head_ref, 'release/') || startsWith(github.head_ref, 'pre-release/')))
11+
environment: release
12+
name: Tag Release
13+
runs-on: ubuntu-latest
14+
env:
15+
BRANCH: ${{ github.head_ref }}
16+
outputs:
17+
tag: ${{ steps.tag.outputs.tag }}
18+
steps:
19+
- name: Check out code
20+
uses: actions/checkout@v4
21+
with:
22+
submodules: true
23+
fetch-depth: 0
24+
ref: ${{ env.BRANCH }}
25+
- name: Tag and kick release
26+
id: tag
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: |
30+
version=$(echo "$BRANCH" | awk -F '/' '{print $2}')
31+
tag="v${version}"
32+
git tag "${tag}"
33+
git push origin "${tag}"
34+
echo "tag=${tag}" >> "$GITHUB_OUTPUT"
35+
36+
release-post-merge:
37+
needs:
38+
- tag-release
39+
uses: ./.github/workflows/release-post-merge.yml
40+
with:
41+
tag: ${{ needs.tag-release.outputs.tag }}

docs/dev/release.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ The new job "Create Release" will be triggered and the following will be done:
2424
* Atlas Operator image built and pushed to dockerhub
2525
* Draft Release will be created with all commits since the previous release
2626

27+
Once the Pull Request is approved, a tag is created out of the branch, which can then be discarded. A branch `release/X.Y.Z` will imply a tag `vX.Y.Z`, and `pre-release/X.Y.Z-...` will imply `vX.Y.Z-...`. The `tag.yml` workflow is the one responsible for creating such tag and triggering the release process workflow (`release-post-merge.yml`).
28+
2729
## Edit the Release Notes and publish the release
2830

2931
Follow the format described in the release-notes-template.md file. Publish the release.

0 commit comments

Comments
 (0)