-
Notifications
You must be signed in to change notification settings - Fork 107
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 a7cd733
Showing
3 changed files
with
401 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,121 @@ | ||
name: Branch Preparation CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'release/**' | ||
tags: | ||
- 'v[0-9]+.[0-9]+.[0-9]+**' | ||
|
||
jobs: | ||
prepare_develop_branch_after_release: | ||
runs-on: ubuntu-latest | ||
if: ${{ github.ref_type == 'tag' }} | ||
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: | | ||
tag=${{ github.ref_name }} | ||
echo "BASE=$(nix-shell --pure --run "./scripts/update-chart-version.sh --tag $tag --type develop" ./shell.nix)" >> $GITHUB_ENV | ||
- name: Create Pull Request to develop | ||
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 develop branch after release ${{ github.ref_name }}" | ||
labels: | | ||
prepare-develop-branch | ||
automated-pr | ||
draft: false | ||
signoff: true | ||
branch: "create-pull-request/patch-${{ env.BASE }}" | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
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 --type release" ./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_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" ./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,77 @@ | ||
#!/usr/bin/env bash | ||
|
||
# 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: When commits are added and chart type is develop [branch creation]" \ | ||
"1.2.0-prerelease" \ | ||
--branch "release/1.2" --dry-run --chart-version "1.3.0-develop" | ||
|
||
run_test "Test 2: When commits are added and chart type is prerelease [commit pushes]" \ | ||
"" \ | ||
--branch "release/1.2" --dry-run --chart-version "1.2.0-prerelease" | ||
|
||
run_test "Test 3: Invalid branch name and chart type is prerelease" \ | ||
"Invalid branch name format. Expected 'release/x.y' only" \ | ||
--branch "feature/1.2" --dry-run --chart-version "1.2.0-prerelease" | ||
|
||
run_test "Test 4: Invalid branch name and chart type is develop" \ | ||
"Invalid branch name format. Expected 'release/x.y' only" \ | ||
--branch "feature/1.2" --dry-run --chart-version "1.2.0-develop" | ||
|
||
run_test "Test 5: Valid tag with type release and chart type is prerelease [first release] " \ | ||
"1.2.1-prerelease" \ | ||
--tag "v1.2.0" --type "release" --dry-run --chart-version "1.2.0-prerelease" | ||
|
||
run_test "Test 6: Valid tag with type release and chart type is prerelease [patch release]" \ | ||
"1.2.2-prerelease" \ | ||
--tag "v1.2.1" --type "release" --dry-run --chart-version "1.2.1-prerelease" | ||
|
||
run_test "Test 7: Tag greater than current chart type release" \ | ||
"For prerelease, X.Y from current chart version (1.2.1-prerelease) must exactly match X.Y from tag (1.4.0)" \ | ||
--tag "v1.4.0" --type "release" --dry-run --chart-version "1.2.1-prerelease" | ||
|
||
run_test "Test 8: Valid tag with type develop and chart type is prerelease [first release]" \ | ||
"1.3.0-develop" \ | ||
--tag "v1.2.0" --type "develop" --dry-run --chart-version "1.2.0-prerelease" | ||
|
||
run_test "Test 9: Valid tag with type develop and chart type is prerelease [patch release]" \ | ||
"1.3.0-develop" \ | ||
--tag "v1.2.1" --type "develop" --dry-run --chart-version "1.2.1-prerelease" | ||
|
||
run_test "Test 10: Tag is lesser than chart type develop " \ | ||
"" \ | ||
--tag "v1.0.0" --type "develop" --dry-run --chart-version "1.2.1-develop" | ||
|
||
run_test "Test 11: Tag is greater than chart type release " \ | ||
"1.5.0-develop" \ | ||
--tag "v1.4.0" --type "develop" --dry-run --chart-version "1.2.1-develop" | ||
|
||
run_test "Test 12: rc tag, with type release and chart type prerelease" \ | ||
"" \ | ||
--tag "v1.2.3-rc" --type "develop" --dry-run --chart-version "1.2.3-develop" | ||
|
||
run_test "Test 13:rc tag, with type develop and chart type develop" \ | ||
"" \ | ||
--tag "v1.2.3-rc" --type "develop" --dry-run --chart-version "1.2.4-develop" |
Oops, something went wrong.