-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add branch preparation CI changes
Signed-off-by: Abhinandan Purkait <[email protected]>
- Loading branch information
1 parent
d4c1903
commit 80e4df6
Showing
3 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
name: Branch Preparation CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'release/**' | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+**' | ||
|
||
jobs: | ||
prepare_release_branch_after_release: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.ref_type == 'tag' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: cachix/install-nix-action@v22 | ||
- name: Pre-populate nix-shell | ||
run: | | ||
export NIX_PATH=nixpkgs=$(jq '.nixpkgs.url' nix/sources.json -r) | ||
echo "NIX_PATH=$NIX_PATH" >> $GITHUB_ENV | ||
nix-shell --pure --run "echo" ./shell.nix | ||
- name: Test the chart version updater script | ||
run: | | ||
nix-shell --pure --run "./scripts/test-update-chart-version.sh" ./shell.nix | ||
- name: Check if the chart is publishable | ||
run: | | ||
tag=${{ github.ref_name }} | ||
echo "BASE=$(nix-shell --pure --run "./scripts/update-chart-version.sh --tag $tag" ./shell.nix)" >> $GITHUB_ENV | ||
- name: Create Pull Request to release | ||
if: ${{ env.BASE }} | ||
id: cpr | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
base: ${{ env.BASE }} | ||
commit-message: "chore(ci): update helm chart versions and/or git submodules" | ||
committer: GitHub <[email protected]> | ||
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> | ||
title: "Prepare release branch after release ${{ github.ref_name }}" | ||
labels: | | ||
prepare-release-branch | ||
automated-pr | ||
draft: false | ||
signoff: true | ||
branch: "create-pull-request/patch-${{ env.BASE }}" | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
prepare_develop_branch_on_creation: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.ref_type == 'branch' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- run: | | ||
git checkout develop | ||
- uses: cachix/install-nix-action@v22 | ||
- name: Pre-populate nix-shell | ||
run: | | ||
export NIX_PATH=nixpkgs=$(jq '.nixpkgs.url' nix/sources.json -r) | ||
echo "NIX_PATH=$NIX_PATH" >> $GITHUB_ENV | ||
nix-shell --pure --run "echo" ./shell.nix | ||
- name: Test the chart version updater script | ||
run: | | ||
nix-shell --pure --run "./scripts/test-update-chart-version.sh" ./shell.nix | ||
- name: Check if the chart is publishable | ||
run: | | ||
branch_name=${{ github.ref_name }} | ||
nix-shell --pure --run "./scripts/update-chart-version.sh --branch $branch_name --type develop" ./shell.nix | ||
- name: Create Pull Request to develop | ||
id: cpr | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
base: develop | ||
commit-message: "chore(ci): update helm chart versions and/or git submodules" | ||
committer: GitHub <[email protected]> | ||
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> | ||
title: "Prepare develop branch on ${{ github.ref_name }} creation" | ||
labels: | | ||
prepare-develop-branch | ||
automated-pr | ||
draft: false | ||
signoff: true | ||
branch: "create-pull-request/patch-${{ env.BASE }}" | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
prepare_release_branch_on_creation: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.ref_type == 'branch' }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: cachix/install-nix-action@v22 | ||
- name: Pre-populate nix-shell | ||
run: | | ||
export NIX_PATH=nixpkgs=$(jq '.nixpkgs.url' nix/sources.json -r) | ||
echo "NIX_PATH=$NIX_PATH" >> $GITHUB_ENV | ||
nix-shell --pure --run "echo" ./shell.nix | ||
- name: Test the chart version updater script | ||
run: | | ||
nix-shell --pure --run "./scripts/test-update-chart-version.sh" ./shell.nix | ||
- name: Check if the chart is publishable | ||
run: | | ||
branch_name=${{ github.ref_name }} | ||
nix-shell --pure --run "./scripts/update-chart-version.sh --branch $branch_name --type release" ./shell.nix | ||
- name: Create Pull Request to release | ||
id: cpr | ||
uses: peter-evans/create-pull-request@v5 | ||
with: | ||
base: ${{ github.ref_name }} | ||
commit-message: "chore(ci): update helm chart versions and/or git submodules" | ||
committer: GitHub <[email protected]> | ||
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> | ||
title: "Prepare ${{ github.ref_name }} branch" | ||
labels: | | ||
prepare-release-branch | ||
automated-pr | ||
draft: false | ||
signoff: true | ||
branch: "create-pull-request/patch-${{ github.ref_name }}" | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# Path to the script to be tested | ||
SCRIPT_DIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")" | ||
SCRIPT_TO_TEST="$SCRIPT_DIR/update-chart-version.sh" | ||
|
||
# Function to run a test case | ||
run_test() { | ||
local test_name=$1 | ||
local expected_output=$2 | ||
shift 2 | ||
local output | ||
|
||
echo "Running: $test_name" | ||
output=$("$SCRIPT_TO_TEST" "$@" 2>&1) | ||
if [ "$output" == "$expected_output" ]; then | ||
echo "PASS" | ||
else | ||
echo "FAIL" | ||
echo "Expected: $expected_output" | ||
echo "Got: $output" | ||
fi | ||
echo "----------------------------------------" | ||
} | ||
|
||
# Define test cases | ||
run_test "Test 1: On branch creation, version to be reflected on release branch" \ | ||
"1.2.0-prerelease" \ | ||
--branch "release/1.2" --type "release" --dry-run --chart-version "1.2.0-develop" | ||
|
||
run_test "Test 2: On branch creation, version to be reflected on develop branch" \ | ||
"1.3.0-develop" \ | ||
--branch "release/1.2" --type "develop" --dry-run --chart-version "1.2.0-prerelease" | ||
|
||
run_test "Test 3: After branch creation on push, version to be reflected on release branch" \ | ||
"" \ | ||
--branch "release/1.2" --type "release" --dry-run --chart-version "1.2.0-prerelease" | ||
|
||
run_test "Test 4: After branch creation on push, version to be reflected on develop branch" \ | ||
"" \ | ||
--branch "release/1.2" --type "develop" --dry-run --chart-version "1.3.0-develop" | ||
|
||
run_test "Test 5: On branch creation, version to be reflected on release branch, x.y is newer" \ | ||
"1.5.0-prerelease" \ | ||
--branch "release/1.5" --type "release" --dry-run --chart-version "1.2.0-develop" | ||
|
||
run_test "Test 6: On branch creation, version to be reflected on develop branch, x.y is newer" \ | ||
"1.6.0-develop" \ | ||
--branch "release/1.5" --type "develop" --dry-run --chart-version "1.2.0-develop" | ||
|
||
run_test "Test 7: On branch creation, version to be reflected on release branch, x.y is older" \ | ||
"1.2.0-prerelease" \ | ||
--branch "release/1.2" --type "release" --dry-run --chart-version "1.5.0-develop" | ||
|
||
run_test "Test 8: On branch creation, version to be reflected on develop branch, x.y is older" \ | ||
"" \ | ||
--branch "release/1.2" --type "develop" --dry-run --chart-version "1.5.0-develop" | ||
|
||
run_test "Test 9: On tag creation, version to be reflected on release/x.y branch" \ | ||
"1.2.1-prerelease" \ | ||
--tag "v1.2.0" --dry-run --chart-version "1.2.0-prerelease" | ||
|
||
run_test "Test 10: On tag creation, version to be reflected on release/x.y branch, tag is in future" \ | ||
"For release/x.y branch the current chart version(1.2.0-prerelease)'s X.Y must exactly match X.Y from tag (1.5.0)" \ | ||
--tag "v1.5.0" --dry-run --chart-version "1.2.0-prerelease" | ||
|
||
run_test "Test 11: On tag creation, version to be reflected on release/x.y branch, tag is in past" \ | ||
"For release/x.y branch the current chart version(1.2.0-prerelease)'s X.Y must exactly match X.Y from tag (1.0.0)" \ | ||
--tag "v1.0.0" --dry-run --chart-version "1.2.0-prerelease" | ||
|
||
run_test "Test 12: On tag creation, version to be reflected on release/x.y branch, the current chart version is not prerelease" \ | ||
"Chart version(1.2.0-develop) should be a prerelease format to proceed for tag creation flow" \ | ||
--tag "v1.0.0" --dry-run --chart-version "1.2.0-develop" | ||
|
||
run_test "Test 13: rc tag, with chart type prerelease" \ | ||
"" \ | ||
--tag "v1.2.3-rc" --dry-run --chart-version "1.2.3-prerelease" | ||
|
||
if [ -n "$FAILED" ]; then | ||
echo "Some of the tests have failed..." | ||
exit 1 | ||
fi |
Oops, something went wrong.