Skip to content

Commit

Permalink
ci(helm): update helm chart version fix
Browse files Browse the repository at this point in the history
When pushing tags (annotated?), github's event.base_ref may not be set.
When this happens, we can figure out the released branch ourselves, by
inspecting all branches containing the tag, and ensuring it's the tip
and it's the current HEAD.

Signed-off-by: Tiago Castro <tiagolobocastro@gmail.com>
  • Loading branch information
tiagolobocastro committed Jan 15, 2025
1 parent 3fe353c commit 3c132b1
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 299 deletions.
22 changes: 19 additions & 3 deletions .github/workflows/k8s-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,37 @@ jobs:
run: nix-shell ./scripts/python/shell.nix --run "echo"
- name: BootStrap k8s cluster
run: nix-shell ./scripts/k8s/shell.nix --run "./scripts/k8s/deployer.sh start --label"
- name: Prepare vnext images and binary
- name: Prepare v-next images and binary
run: nix-shell ./scripts/python/shell.nix --run "./scripts/python/upgrade-test-helper.sh --build --chart-tag --chart ./chart"
- name: Load images to kind cluster
run: nix-shell ./scripts/python/shell.nix --run "./scripts/python/upgrade-test-helper.sh --load"
- name: Run Pytests
- name: Run pytest
run: |
export REUSE_CLUSTER=1
export CHART_VNEXT_SKIP=1
export CLEAN=0
nix-shell ./scripts/python/shell.nix --run "./scripts/python/test.sh"
- name: The job has failed
- name: Collect logs
if: ${{ failure() }}
run: |
nix-shell ./scripts/k8s/shell.nix --run "kubectl get pods -A -o wide"
nix-shell ./scripts/k8s/shell.nix --run "kubectl -n mayastor logs -l openebs.io/release=mayastor --all-containers=true"
nix-shell ./scripts/k8s/shell.nix --run "kubectl -n mayastor logs -l app=upgrade --all-containers=true"
- name: Upload pytest logs
if: always()
uses: actions/upload-artifact@v4
with:
name: pytest.log
path: pytest.log
- name: Report pytest results
if: always()
uses: pmeier/pytest-results-action@main
with:
path: report.xml
summary: true
display-options: a
fail-on-empty: true
title: Test results

k8s-ci-vm:
runs-on: ubuntu-latest-16-cores
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/release-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ jobs:
run: |
tag="${{ github.ref_name }}"
BASE_REF="${{ github.event.base_ref }}"
BRANCH="${BASE_REF#refs/heads/}"
if [ -n "$BASE_REF" ]; then
BRANCH="${BASE_REF#refs/heads/}"
else
BRANCH="$(nix-shell --pure --run "./scripts/helm/find-released-branch.sh "$tag"" ./scripts/helm/shell.nix)"
fi
echo "BASE_BRANCH=$BRANCH" >> $GITHUB_ENV
nix-shell --pure --run "./scripts/helm/publish-chart-yaml.sh --released "$tag" --released-branch "$BRANCH"" ./scripts/helm/shell.nix
nix-shell --pure --run "SKIP_GIT=1 ./scripts/helm/generate-readme.sh" ./scripts/helm/shell.nix
- name: Create Pull Request
Expand All @@ -73,7 +79,7 @@ jobs:
signoff: true
delete-branch: true
branch-suffix: "random"
base: ${{ github.event.base_ref }}
base: ${{ env.BASE_BRANCH }}
token: ${{ secrets.ORG_CI_GITHUB }}
- name: Approve Pull Request by CI Bot
if: ${{ steps.cpr.outputs.pull-request-number }}
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ repos:
pass_filenames: false
types: [file, rust]
language: system
- id: python-fmt
name: Python fmt
description: Run python fmt on files included in the commit.
entry: nix-shell --pure --run './scripts/python/fmt.sh'
pass_filenames: false
types: [file, python]
language: system
- id: commit-lint
name: Commit Lint
description: Runs commitlint against the commit message.
Expand Down
258 changes: 0 additions & 258 deletions Jenkinsfile

This file was deleted.

56 changes: 56 additions & 0 deletions scripts/helm/find-released-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

SCRIPTDIR="$(dirname "$(realpath "${BASH_SOURCE[0]:-"$0"}")")"
ROOTDIR="$SCRIPTDIR/../.."

source "$ROOTDIR/scripts/utils/log.sh"

set -euo pipefail

# Check if the given branch matches the tag
# Example:
# release/2.7 matches tag v2.7.2, v2.7.2-rc.4, etc..
# release/2.7 does not match tag v2.6.0, etc...
tag_matches_branch() {
local tag="${1#v}"
local release_branch="$2"

branch_version="${release_branch#release/}"
if ! [[ "$branch_version" =~ ^[0-9]+.[0-9]+$ ]]; then
return 1
fi

if ! [[ "$tag" = "$branch_version"* ]]; then
return 1
fi
}

# For the given tag, find the branch which is compatible
# See tag_matches_branch for more information.
find_released_branch() {
local tag="$1"
local branches
branches=$(git branch -r --contains "$TAG" --points-at "$TAG" --format "%(refname:short)" 2>/dev/null)
local branch=""

for release_branch in $branches; do
release_branch=${release_branch#origin/}
if tag_matches_branch "$TAG" "$release_branch"; then
if [ -n "$branch" ]; then
log_fatal "Multiple branches matched!"
fi
branch="$release_branch"
fi
done

echo "$branch"
}

TAG="$1"
BRANCH="$(find_released_branch "$TAG")"

if [ -z "$BRANCH" ]; then
log_fatal "Failed to find matching released branch for tag '$TAG'"
fi

echo "$BRANCH"
Loading

0 comments on commit 3c132b1

Please sign in to comment.