Skip to content

Commit ed4ebcf

Browse files
authored
Merge pull request #71 from afdesk/ci/publish-helm
ci: publish helm
2 parents 56db43c + 5023312 commit ed4ebcf

File tree

4 files changed

+76
-1
lines changed

4 files changed

+76
-1
lines changed

.github/workflows/bypass-test.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ on:
99
- 'mkdocs.yml'
1010
- 'LICENSE'
1111
- '.release-please-manifest.json'
12+
- 'helm/trivy/Chart.yaml'
1213
pull_request:
1314
paths:
1415
- '**.md'
1516
- 'docs/**'
1617
- 'mkdocs.yml'
1718
- 'LICENSE'
1819
- '.release-please-manifest.json'
20+
- 'helm/trivy/Chart.yaml'
1921
jobs:
2022
test:
2123
name: Test

.github/workflows/publish-chart.yaml

+31-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ name: Publish Helm chart
44
on:
55
workflow_dispatch:
66
pull_request:
7+
types:
8+
- opened
9+
- synchronize
10+
- reopened
11+
- closed
712
branches:
813
- main
914
paths:
@@ -18,7 +23,9 @@ env:
1823
KIND_VERSION: "v0.14.0"
1924
KIND_IMAGE: "kindest/node:v1.23.6@sha256:b1fa224cc6c7ff32455e0b1fd9cbfd3d3bc87ecaa8fcb06961ed1afb3db0f9ae"
2025
jobs:
26+
# `test-chart` job starts if a PR with Helm Chart is created, merged etc.
2127
test-chart:
28+
if: github.event_name != 'push'
2229
runs-on: ubuntu-20.04
2330
steps:
2431
- name: Checkout
@@ -48,8 +55,31 @@ jobs:
4855
sed -i -e '136s,false,'true',g' ./helm/trivy/values.yaml
4956
ct lint-and-install --validate-maintainers=false --charts helm/trivy
5057
58+
# `update-chart-version` job starts if a new tag is pushed
59+
update-chart-version:
60+
if: github.event_name == 'push'
61+
runs-on: ubuntu-20.04
62+
steps:
63+
- name: Checkout
64+
uses: actions/[email protected]
65+
with:
66+
fetch-depth: 0
67+
- name: Set up Git user
68+
run: |
69+
git config --global user.email "[email protected]"
70+
git config --global user.name "GitHub Actions"
71+
- name: Get the tag without the 'v' prefix
72+
run: echo "TAG=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
73+
- name: Create a PR
74+
run: ./misc/helm-chart/create-pr.sh ${{ env.TAG }}
75+
env:
76+
# Use ORG_REPO_TOKEN instead of GITHUB_TOKEN
77+
# This allows the created PR to trigger tests and other workflows
78+
GITHUB_TOKEN: ${{ secrets.ORG_REPO_TOKEN }}
79+
80+
# `publish-chart` job starts if a PR with a new Helm Chart is merged or manually
5181
publish-chart:
52-
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
82+
if: github.event.pull_request.merged == true || github.event_name == 'workflow_dispatch'
5383
needs:
5484
- test-chart
5585
runs-on: ubuntu-20.04

.github/workflows/test.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- 'mkdocs.yml'
88
- 'LICENSE'
99
- '.release-please-manifest.json' ## don't run tests for release-please PRs
10+
- 'helm/trivy/Chart.yaml'
1011
merge_group:
1112
env:
1213
GO_VERSION: '1.22'

misc/helm-chart/create-pr.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
VERSION=$1
6+
7+
# Update version in file
8+
echo "Update Chart.yaml with Trivy $VERSION"
9+
sed -i "s/version: [0-9]\+\.[0-9]\+\.[0-9]\+/version: $VERSION/" ./helm/trivy/Chart.yaml
10+
sed -i "s/appVersion: [0-9]\+\.[0-9]\+\.[0-9]\+/appVersion: $VERSION/" ./helm/trivy/Chart.yaml
11+
12+
echo "Create PR for update Trivy $VERSION in the Helm Chart"
13+
14+
# Create a new branch
15+
NEW_BRANCH="ci/helm-chart/bump-trivy-to-$VERSION"
16+
17+
echo "Creating new branch: $NEW_BRANCH"
18+
git switch -c "$NEW_BRANCH"
19+
20+
# Create the title
21+
TITLE="ci(helm): bump Trivy version to $VERSION"
22+
23+
# commit Helm Values with a new version
24+
git add ./helm/trivy/Chart.yaml
25+
git commit -m "$TITLE"
26+
27+
# Create the pull request description
28+
PR_DESCRIPTION="# Description
29+
30+
This PR bumps Trivy up to the $VERSION version for the Helm chart."
31+
32+
echo "Pushing new branch to origin: $NEW_BRANCH"
33+
git push origin "$NEW_BRANCH"
34+
35+
echo "Pull request title: $TITLE"
36+
37+
echo "Pull request description:"
38+
echo "$PR_DESCRIPTION"
39+
40+
# Create a new pull request
41+
echo "Creating pull request..."
42+
gh pr create --base main --head "$NEW_BRANCH" --title "$TITLE" --body "$PR_DESCRIPTION" --repo "$GITHUB_REPOSITORY" --label "lifecycle/active"

0 commit comments

Comments
 (0)