Skip to content

Commit 54d4727

Browse files
Ani1357Release Candidate GitHub ActionsvcAPLBotlocal_test
authored
ci: added release candidate pipelines (#2076)
Co-authored-by: Release Candidate GitHub Action <rc_githubactions@github.com> Co-authored-by: svcAPLBot <174728082+svcAPLBot@users.noreply.github.com> Co-authored-by: local_test <local@mail.com>
1 parent f3b5745 commit 54d4727

File tree

4 files changed

+258
-0
lines changed

4 files changed

+258
-0
lines changed

.github/workflows/create_rc.yml

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Create Release Candidate.
2+
run-name: Create Release Candidate from ${{ github.event.inputs.rc_commit_sha || 'main' }}
3+
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
rc_commit_sha:
8+
description: 'Commit from which to create the release candidate. If not provided, the latest commit on main will be used'
9+
required: false
10+
type: string
11+
dry_run:
12+
description: 'Dry Run: If true, the pipeline will not publish the helm chart.'
13+
required: true
14+
default: 'true'
15+
type: choice
16+
options:
17+
- true
18+
- false
19+
20+
jobs:
21+
create_patch_release:
22+
runs-on: ubuntu-22.04
23+
outputs:
24+
rc_branch: ${{ steps.create_release.outputs.rc_branch }}
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
with:
29+
fetch-depth: 0
30+
31+
- name: Determine commit from where to create the RC
32+
id: determine_commit
33+
run: |
34+
if [ -n "${{ github.event.inputs.rc_commit_sha }}" ]; then
35+
commit_sha="${{ github.event.inputs.rc_commit_sha }}"
36+
echo "Using provided commit sha: $commit_sha"
37+
echo "commit_sha=$commit_sha" >> $GITHUB_ENV
38+
else
39+
commit_sha=$(git rev-parse HEAD)
40+
echo "No commit sha provided, using the latest commit on main: $commit_sha"
41+
echo "commit_sha=$commit_sha" >> $GITHUB_ENV
42+
fi
43+
44+
- name: Install dependencies
45+
run: |
46+
npm install standard-version
47+
48+
- name: Create release candidate tag & branch
49+
id: create_release
50+
env:
51+
DRY_RUN: ${{ github.event.inputs.dry_run }}
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
COMMIT_SHA: ${{ env.commit_sha }}
54+
BOT_EMAIL: ${{ vars.BOT_EMAIL }}
55+
BOT_USERNAME: ${{ vars.BOT_USERNAME }}
56+
run: |
57+
ci/scripts/create_rc.sh
58+
59+
- name: Prepare chart
60+
env:
61+
BOT_EMAIL: ${{ vars.BOT_EMAIL }}
62+
BOT_USERNAME: ${{ vars.BOT_USERNAME }}
63+
id: prepare_chart
64+
run: |
65+
ci/scripts/prepare_chart_for_release.sh
66+
67+
- name: Dry Run Outputs
68+
if: ${{ github.event.inputs.dry_run == 'true'}}
69+
run: |
70+
echo "This Pipeline was executed in dry run mode so it will not publish the helm chart."
71+
echo "Below are some useful data to check:"
72+
echo "Release candidate branch: $(git rev-parse --abbrev-ref HEAD)"
73+
echo "-*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*"
74+
echo "Contents of: chart/apl/Chart.yaml"
75+
cat chart/apl/Chart.yaml
76+
echo "-*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*"
77+
echo "Contents of: package.json"
78+
cat package.json
79+
echo "-*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*"
80+
echo "Latest 5 commits on the release candidate branch"
81+
git log -n 5 --pretty=format:"%h %s" --abbrev-commit
82+
echo "-*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*--*-*"
83+
echo "Commits behind main branch VS Commits ahead of main branch"
84+
git rev-list --left-right --count origin/main...HEAD
85+
86+
- name: Create and publish otomi chart release
87+
if: ${{ github.event.inputs.dry_run == 'false' }}
88+
id: chart_release
89+
uses: helm/chart-releaser-action@v1.7.0
90+
with:
91+
charts_dir: chart
92+
skip_existing: true
93+
mark_as_latest: false
94+
env:
95+
CR_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

.github/workflows/patch_rc.yml

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: Patch Release Candidate
2+
3+
on:
4+
push:
5+
branches:
6+
- rc/*
7+
tags-ignore:
8+
- '*'
9+
10+
jobs:
11+
patch_rc:
12+
runs-on: ubuntu-22.04
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Analze commits since last rc release
20+
id: analyze_commits
21+
run: |
22+
23+
CURRENT_VERSION=$(jq '.version' package.json -r)
24+
echo "Current version: $CURRENT_VERSION"
25+
LATEST_TAG=$(git tag -l "v${CURRENT_VERSION%.*}*" | sort -V | tail -n 1)
26+
echo "Latest tag: $LATEST_TAG"
27+
28+
echo "Commits since last rc release:"
29+
git -P log --pretty=format:"%s" "${LATEST_TAG}..HEAD"
30+
COMMITS=$(git log --pretty=format:"%s" "${LATEST_TAG}..HEAD")
31+
32+
if [[ $COMMITS == *"feat:"* || $COMMITS == *"fix:"* ]]; then
33+
echo "RC_RELEASE=true" >> $GITHUB_ENV
34+
else
35+
echo "No feat/fix commits found. Skipping release."
36+
echo "RC_RELEASE=false" >> $GITHUB_ENV
37+
fi
38+
39+
- name: Install dependencies
40+
if: ${{ env.RC_RELEASE == 'true' }}
41+
run: |
42+
npm install standard-version
43+
44+
- name: Configure Git
45+
if: ${{ env.RC_RELEASE == 'true' }}
46+
run: |
47+
git config --global user.email "githubactions_rc@github.com"
48+
git config --global user.name "GitHub Action RC"
49+
50+
- name: Release new RC version
51+
if: ${{ env.RC_RELEASE == 'true' }}
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
run: |
55+
echo "Detected "feat"/"fix"/"chore: trigger" commits. Running standard-version..."
56+
npm run release -- --prerelease rc --skip.changelog
57+
git push --follow-tags
58+
TAG="v$(jq '.version' package.json -r)"
59+
gh release create "$TAG" --title="Release: $TAG" --notes="Automated release for $TAG" --latest=false -p
60+
61+
- name: Prepare chart
62+
if: ${{ env.RC_RELEASE == 'true' }}
63+
id: prepare_chart
64+
env:
65+
BOT_EMAIL: ${{ vars.BOT_EMAIL }}
66+
BOT_USERNAME: ${{ vars.BOT_USERNAME }}
67+
run: |
68+
ci/scripts/prepare_chart_for_release.sh
69+
70+
- name: Create and publish otomi chart release
71+
if: ${{ github.event.inputs.dry_run == 'false' }} && ${{ env.RC_RELEASE == 'true' }}
72+
id: chart_release
73+
uses: helm/chart-releaser-action@v1.7.0
74+
with:
75+
charts_dir: chart
76+
skip_existing: true
77+
mark_as_latest: false
78+
env:
79+
CR_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

ci/scripts/create_rc.sh

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# This script creates a release candidate tag for a given commit.
5+
# Input:
6+
# - COMMIT_SHA: The commit SHA to create the release candidate tag for.
7+
# - DRY_RUN: If set to true, the script will not create the tag, but will print the commands that would be executed.
8+
# - GITHUB_TOKEN: The GitHub token to use for authentication.
9+
# - BOT_EMAIL: The email address to use for the git commit.
10+
# - BOT_USERNAME: The username to use for the git commit.
11+
12+
# Validate required environment variables
13+
: "${COMMIT_SHA:?COMMIT_SHA is required}"
14+
: "${BOT_EMAIL:?BOT_EMAIL is required}"
15+
: "${BOT_USERNAME:?BOT_USERNAME is required}"
16+
: "${GITHUB_TOKEN:?GITHUB_TOKEN is required}"
17+
18+
# Configure Git
19+
echo "Configuring Git..."
20+
git config --global user.email "$BOT_EMAIL"
21+
git config --global user.name "$BOT_USERNAME"
22+
23+
# Reset to the specified commit
24+
echo "Resetting to commit $COMMIT_SHA..."
25+
git reset --hard "$COMMIT_SHA"
26+
27+
# Determine the next version
28+
echo "Determining the next version..."
29+
npm run release -- --skip.commit --skip.tag --skip.changelog
30+
new_version=$(jq -r '.version' package.json)
31+
branch_name="rc/v${new_version%.*}"
32+
release_branch_name="${branch_name//rc/release}"
33+
echo "$branch_name" >> rc_branch_name.txt
34+
git reset --hard "$COMMIT_SHA"
35+
36+
echo "Creating branch $branch_name..."
37+
git checkout -b "$branch_name"
38+
39+
# Dry run or actual execution
40+
if [ "$DRY_RUN" == "true" ]; then
41+
echo -e "Running in dry run mode. No changes will be pushed."
42+
npm run release -- --prerelease rc --skip.changelog
43+
else
44+
npm run release -- --prerelease rc --skip.changelog
45+
git push -u origin "$branch_name" --follow-tags
46+
git fetch --tags origin
47+
rc_version="v$(jq -r '.version' package.json)"
48+
echo "Creating GitHub release: $rc_version"
49+
gh release create "$rc_version" --verify-tag --title="Release Candidate: $rc_version" --notes="Automated release for $rc_version" --latest=false -p
50+
fi
51+
52+
echo "Script completed successfully."
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# This script prepares the helm chart for release.
5+
# Input:
6+
# - BOT_EMAIL: The email address to use for the git commit.
7+
# - BOT_USERNAME: The username to use for the git commit.
8+
9+
# Validate required environment variables
10+
: "${BOT_EMAIL:?BOT_EMAIL is required}"
11+
: "${BOT_USERNAME:?BOT_USERNAME is required}"
12+
13+
# Retrieve the app version from package.json
14+
app_version=$(jq -r '.version' package.json)
15+
16+
# Update Chart.yaml and values.yaml with the new app version
17+
sed -i "s/0.0.0-chart-version/$app_version/g" chart/apl/Chart.yaml
18+
sed -i "s/APP_VERSION_PLACEHOLDER/v$app_version/g" chart/apl/Chart.yaml
19+
20+
echo "Chart and values files updated successfully with version $app_version"
21+
22+
# Copy readme from repo into the charts and add tpl/chart-values.md
23+
cp README.md chart/apl/
24+
printf "\n\n" >>chart/apl/README.md
25+
cat tpl/chart-values.md >>chart/apl/README.md
26+
27+
# Generate schema
28+
npx js-yaml values-schema.yaml > chart/apl/values.schema.json
29+
30+
# Set the global id for git as it seems needed by the next step when a custom image is used
31+
git config --global user.email $BOT_EMAIL
32+
git config --global user.name $BOT_USERNAME

0 commit comments

Comments
 (0)