9
9
types :
10
10
- opened
11
11
- synchronize
12
- workflow_dispatch :
12
+ push :
13
+ branches :
14
+ - main
15
+ paths :
16
+ - " charts/**"
13
17
14
18
env :
15
19
# make install test false for now
16
20
DO_INSTALL_TEST : false
17
21
18
22
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
+
19
51
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'
21
54
runs-on : ubuntu-latest
22
55
steps :
23
56
- name : Checkout
38
71
- name : Set up chart-testing
39
72
uses : helm/chart-testing-action@v2
40
73
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
42
79
id : list-changed
43
80
run : |
44
81
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
@@ -47,21 +84,16 @@ jobs:
47
84
echo "charts=$(echo "$changed" | tr '\n' ' ')" >> "$GITHUB_OUTPUT"
48
85
fi
49
86
50
- - name : Run chart-testing (lint)
87
+ - name : Lint charts
51
88
if : steps.list-changed.outputs.changed == 'true'
52
89
run : ct lint --config .github/config/chart-testing.yaml
53
90
54
- - name : Run chart- testing (template)
91
+ - name : Unit testing
55
92
if : steps.list-changed.outputs.changed == 'true'
56
- id : update-dependencies
93
+ id : unittest
57
94
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 }}
65
97
66
98
- name : Create kind cluster
67
99
if : ${{ steps.list-changed.outputs.changed == 'true' && env.DO_INSTALL_TEST == 'true' }}
0 commit comments