Skip to content

Commit 9c0d9ea

Browse files
committed
[skip ci] cicd: update lint and test workflow
1 parent 1243414 commit 9c0d9ea

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

.github/workflows/lint-test.yaml renamed to .github/workflows/test.yaml

+45-13
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,48 @@ on:
99
types:
1010
- opened
1111
- synchronize
12-
workflow_dispatch:
12+
push:
13+
branches:
14+
- main
15+
paths:
16+
- "charts/**"
1317

1418
env:
1519
# make install test false for now
1620
DO_INSTALL_TEST: false
1721

1822
jobs:
23+
# The pre-check job determines whether the workflow should proceed based on the event type and associated PRs:
24+
# - true if the commit is not associated with any PR if it is a push event
25+
# - true if the event is a PR event
26+
# so that, we can skip the following job if the commit is associated with a PR when it is merged to main branch
27+
# - to prevent running the job twice
28+
pre-check:
29+
runs-on: ubuntu-latest
30+
outputs:
31+
run_workflow: ${{ steps.check-commit.outputs.result }}
32+
steps:
33+
- uses: actions/github-script@v7
34+
if: github.event_name == 'push'
35+
id: check-commit
36+
with:
37+
script: |
38+
const associatedPRs = await github.rest.repos.listPullRequestsAssociatedWithCommit({
39+
owner: context.repo.owner,
40+
repo: context.repo.repo,
41+
commit_sha: context.sha
42+
});
43+
return associatedPRs.data.length == 0;
44+
result-encoding: string
45+
46+
# Set default output for PR events
47+
- if: github.event_name == 'pull_request'
48+
id: pr-event
49+
run: echo "result=true" >> $GITHUB_OUTPUT
50+
1951
lint-test:
20-
if: github.head_ref != 'release-please--branches--main'
52+
needs: pre-check
53+
if: needs.pre-check.outputs.run_workflow == 'true' || github.head_ref != 'release-please--branches--main'
2154
runs-on: ubuntu-latest
2255
steps:
2356
- name: Checkout
@@ -38,7 +71,11 @@ jobs:
3871
- name: Set up chart-testing
3972
uses: helm/chart-testing-action@v2
4073

41-
- name: Run chart-testing (list-changed)
74+
- name: Install Helm Unittest plugin
75+
run: |
76+
helm plugin install https://github.com/helm-unittest/helm-unittest.git
77+
78+
- name: List changed charts
4279
id: list-changed
4380
run: |
4481
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
@@ -47,21 +84,16 @@ jobs:
4784
echo "charts=$(echo "$changed" | tr '\n' ' ')" >> "$GITHUB_OUTPUT"
4885
fi
4986
50-
- name: Run chart-testing (lint)
87+
- name: Lint charts
5188
if: steps.list-changed.outputs.changed == 'true'
5289
run: ct lint --config .github/config/chart-testing.yaml
5390

54-
- name: Run chart-testing (template)
91+
- name: Unit testing
5592
if: steps.list-changed.outputs.changed == 'true'
56-
id: update-dependencies
93+
id: unittest
5794
run: |
58-
for updated_chart in ${{ steps.list-changed.outputs.charts }}; do
59-
echo "================================================================================"
60-
echo " templating $updated_chart"
61-
echo "================================================================================"
62-
helm dependency update $updated_chart
63-
helm template $updated_chart
64-
done
95+
helm dependency update ${{ steps.list-changed.outputs.charts }}
96+
helm unittest ${{ steps.list-changed.outputs.charts }}
6597
6698
- name: Create kind cluster
6799
if: ${{ steps.list-changed.outputs.changed == 'true' && env.DO_INSTALL_TEST == 'true' }}

0 commit comments

Comments
 (0)