Skip to content

Commit

Permalink
ci: verify helm chart can be packaged in CI build
Browse files Browse the repository at this point in the history
  • Loading branch information
basti1302 committed Jul 4, 2024
1 parent 7edfb2a commit 50cd0f1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,26 @@ jobs:
imageDescription: the controller for the Dash0 Kubernetes operator
context: .

publish-helm-chart-dry-run:
name: Publish Helm Chart (Dry Run)
runs-on: ubuntu-latest
if: ${{ ! contains(github.ref, 'refs/tags/') }}
needs:
- build-and-push-images
concurrency:
group: ci-concurrency-group-${{ github.ref }}
cancel-in-progress: true

steps:
- uses: actions/checkout@v4

- name: publish helm chart (dry run)
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
echo "verifying that helm chart can be published"
DRY_RUN=true helm-chart/bin/publish.sh 0.0.0
publish-helm-chart:
name: Publish Helm Chart
runs-on: ubuntu-latest
Expand Down
21 changes: 14 additions & 7 deletions helm-chart/bin/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ set -euo pipefail

cd "$(dirname "${0}")"/..

# For testing the script locally, provide the relative path to a directory to a with a separate clone of the
# repository, as seen from the helm-chart directory. For example:
# Use DRY_RUN=true to verify that the helm chart can be successfully packaged -- all steps will be executed except for
# the final git push to the gh-pages branch.
#
# For testing the script locally, provide the relative path to a directory with a separate clone of the
# repository, as seen from the helm-chart directory via TEST_PUBLISH_DIR. For example:
# TEST_PUBLISH_DIR=../../dash0-operator-helm-chart-publish-test bin/publish.sh 9.9.9
# The main branch should be checked out initially in that clone.
# You could theoretically use your main working copy/clone for testing, but since the script switches the branch to
# gh-pages and that is an orphan branch it might leave the working copy in a slightly messy state. Therefore it is
# better to use another clone for that.
# Additionally, if TEST_PUBLISH_DIR is set, no actual git push will take place.
# Additionally, a non-empty TEST_PUBLISH_DIR implies DRY_RUN=true.
if [[ -n "${TEST_PUBLISH_DIR:-}" ]]; then
cd "$TEST_PUBLISH_DIR"/helm-chart
DRY_RUN=true
fi

# Abort when there are local changes in the repository. This is mostly relevant for testing the script locally.
Expand Down Expand Up @@ -49,6 +53,9 @@ echo "switching to gh-pages branch"
git fetch origin gh-pages:gh-pages
git switch gh-pages

git status
git log

# clean up potential left-overs from the --dependency-update flag
rm -rf helm-chart

Expand All @@ -59,11 +66,11 @@ echo "git add & commit"
git add "dash0-operator-$version.tgz" index.yaml
git commit -m"feat(chart): publish version $version"

if [[ -z "${TEST_PUBLISH_DIR:-}" ]]; then
echo "executing git push"
git push --no-verify --set-upstream origin gh-pages
else
if [[ "${DRY_RUN:-}" == "true" ]]; then
echo "executing git push (--dry-run)"
git push --no-verify --dry-run origin gh-pages
else
echo "executing git push"
git push --no-verify --set-upstream origin gh-pages
fi

0 comments on commit 50cd0f1

Please sign in to comment.