Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(helm): auto public Helm chart after PR merged #7526

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/bypass-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ on:
- 'mkdocs.yml'
- 'LICENSE'
- '.release-please-manifest.json'
- 'helm/trivy/Chart.yaml'
pull_request:
paths:
- '**.md'
- 'docs/**'
- 'mkdocs.yml'
- 'LICENSE'
- '.release-please-manifest.json'
- 'helm/trivy/Chart.yaml'
jobs:
test:
name: Test
Expand Down
29 changes: 28 additions & 1 deletion .github/workflows/publish-chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ name: Publish Helm chart
on:
workflow_dispatch:
pull_request:
types:
- opened
- synchronize
- reopened
- closed
afdesk marked this conversation as resolved.
Show resolved Hide resolved
branches:
- main
paths:
Expand All @@ -19,6 +24,7 @@ env:
KIND_IMAGE: "kindest/node:v1.23.6@sha256:b1fa224cc6c7ff32455e0b1fd9cbfd3d3bc87ecaa8fcb06961ed1afb3db0f9ae"
jobs:
test-chart:
if: github.event_name != 'push'
runs-on: ubuntu-20.04
steps:
- name: Checkout
Expand Down Expand Up @@ -48,8 +54,29 @@ jobs:
sed -i -e '136s,false,'true',g' ./helm/trivy/values.yaml
ct lint-and-install --validate-maintainers=false --charts helm/trivy

update-chart-version:
if: github.event_name == 'push'
afdesk marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4.1.6
with:
fetch-depth: 0
- name: Set up Git user
run: |
git config --global user.email "actions@github.com"
git config --global user.name "GitHub Actions"
- name: Get the tag without the 'v' prefix
run: echo "TAG=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Create a PR
run: ./misc/helm-chart/create-pr.sh ${{ env.TAG }}
env:
# Use ORG_REPO_TOKEN instead of GITHUB_TOKEN
# This allows the created PR to trigger tests and other workflows
GITHUB_TOKEN: ${{ secrets.ORG_REPO_TOKEN }}

publish-chart:
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be wrong, but I remember that the events for merging a PR by default and merging using merge queue may be different.
Does this work correctly?

needs:
- test-chart
runs-on: ubuntu-20.04
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- 'mkdocs.yml'
- 'LICENSE'
- '.release-please-manifest.json' ## don't run tests for release-please PRs
- 'helm/trivy/Chart.yaml'
merge_group:
env:
GO_VERSION: '1.22'
Expand Down
42 changes: 42 additions & 0 deletions misc/helm-chart/create-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

set -e

VERSION=$1

# Update version in file
echo "Update Chart.yaml with Trivy $VERSION"
sed -i "s/version: [0-9]\+\.[0-9]\+\.[0-9]\+/version: $VERSION/" ./helm/trivy/Chart.yaml
sed -i "s/appVersion: [0-9]\+\.[0-9]\+\.[0-9]\+/appVersion: $VERSION/" ./helm/trivy/Chart.yaml

echo "Create PR for update Trivy $VERSION in the Helm Chart"

# Create a new branch
NEW_BRANCH="ci/bump-trivy-to-$VERSION"
afdesk marked this conversation as resolved.
Show resolved Hide resolved

echo "Creating new branch: $NEW_BRANCH"
git switch -c "$NEW_BRANCH"

# Create the title
TITLE="ci(helm): bump Trivy version to $VERSION"

# commit Helm Values with a new version
git add ./helm/trivy/Chart.yaml
git commit -m "$TITLE"

# Create the pull request description
PR_DESCRIPTION="# Description

This PR bumps Trivy up to the $VERSION version for the Helm chart."

echo "Pushing new branch to origin: $NEW_BRANCH"
git push origin "$NEW_BRANCH"

echo "Pull request title: $TITLE"

echo "Pull request description:"
echo "$PR_DESCRIPTION"

# Create a new pull request
echo "Creating pull request..."
gh pr create --base main --head "$NEW_BRANCH" --title "$TITLE" --body "$PR_DESCRIPTION" --repo "$GITHUB_REPOSITORY" --label "lifecycle/active"