|
| 1 | +--- |
| 2 | +name: "Prepare Helm Chart" |
| 3 | +description: | |
| 4 | + Add Helm repositories and build chart dependencies |
| 5 | + for all charts found under a path. |
| 6 | +author: hoverkraft |
| 7 | +branding: |
| 8 | + icon: package |
| 9 | + color: blue |
| 10 | + |
| 11 | +inputs: |
| 12 | + path: |
| 13 | + description: "Path containing the chart(s) to prepare" |
| 14 | + required: true |
| 15 | + helm-repositories: |
| 16 | + description: | |
| 17 | + List of Helm repositories to add before building chart dependencies. |
| 18 | + See https://helm.sh/docs/helm/helm_repo_add/. |
| 19 | + required: false |
| 20 | + |
| 21 | +runs: |
| 22 | + using: "composite" |
| 23 | + steps: |
| 24 | + - name: Add Helm repositories |
| 25 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 26 | + env: |
| 27 | + INPUT_HELM_REPOSITORIES: ${{ inputs.helm-repositories }} |
| 28 | + with: |
| 29 | + script: | |
| 30 | + const repositories = (process.env.INPUT_HELM_REPOSITORIES ?? '') |
| 31 | + .split(/\r?\n/) |
| 32 | + .map((line) => line.trim()) |
| 33 | + .filter((line) => line.length > 0); |
| 34 | +
|
| 35 | + for (const repository of repositories) { |
| 36 | + await exec.exec('helm', [ |
| 37 | + 'repo', |
| 38 | + 'add', |
| 39 | + ...repository.split(/\s+/), |
| 40 | + ]); |
| 41 | + } |
| 42 | +
|
| 43 | + - name: Build chart dependencies |
| 44 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 45 | + env: |
| 46 | + INPUT_PATH: ${{ inputs.path }} |
| 47 | + with: |
| 48 | + script: | |
| 49 | + const path = require('node:path'); |
| 50 | +
|
| 51 | + const chartPath = process.env.INPUT_PATH; |
| 52 | + if (!chartPath) { |
| 53 | + core.setFailed('"path" input is missing'); |
| 54 | + return; |
| 55 | + } |
| 56 | +
|
| 57 | + core.info('Building charts dependencies'); |
| 58 | +
|
| 59 | + const chartRootDir = path.resolve( |
| 60 | + process.env.GITHUB_WORKSPACE ?? '.', |
| 61 | + chartPath, |
| 62 | + ); |
| 63 | + const chartFiles = []; |
| 64 | + const globber = await glob.create( |
| 65 | + `${chartPath}/**/Chart.yaml`, |
| 66 | + { followSymbolicLinks: false }, |
| 67 | + ); |
| 68 | +
|
| 69 | + for await (const chartFile of globber.globGenerator()) { |
| 70 | + chartFiles.push(chartFile); |
| 71 | + } |
| 72 | +
|
| 73 | + if (chartFiles.length === 0) { |
| 74 | + core.info(`No charts found in ${chartRootDir}`); |
| 75 | + return; |
| 76 | + } |
| 77 | +
|
| 78 | + chartFiles.sort(); |
| 79 | +
|
| 80 | + for (const chartFile of chartFiles) { |
| 81 | + const chartDir = path.dirname(chartFile); |
| 82 | + core.info(`Building dependencies for ${chartDir}`); |
| 83 | + await exec.exec('helm', ['dependency', 'build', chartDir]); |
| 84 | + } |
0 commit comments