|
| 1 | +# Copyright 2023 Nutanix. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +name: checks |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + pull_request: |
| 11 | + types: |
| 12 | + - opened |
| 13 | + - synchronize |
| 14 | + - reopened |
| 15 | + merge_group: |
| 16 | + types: |
| 17 | + - checks_requested |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +defaults: |
| 23 | + run: |
| 24 | + shell: bash |
| 25 | + |
| 26 | +jobs: |
| 27 | + unit-test: |
| 28 | + runs-on: ubuntu-22.04 |
| 29 | + steps: |
| 30 | + - name: Check out code |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Install devbox |
| 34 | + uses: jetify-com/[email protected] |
| 35 | + with: |
| 36 | + enable-cache: true |
| 37 | + |
| 38 | + - name: Go cache |
| 39 | + uses: actions/cache@v4 |
| 40 | + with: |
| 41 | + path: | |
| 42 | + ~/.cache/go-build |
| 43 | + ~/go/pkg/mod |
| 44 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 45 | + restore-keys: | |
| 46 | + ${{ runner.os }}-go- |
| 47 | +
|
| 48 | + - name: Run unit tests |
| 49 | + run: devbox run -- make test |
| 50 | + |
| 51 | + - name: Annotate tests |
| 52 | + if: always() |
| 53 | + |
| 54 | + with: |
| 55 | + test-results: test.json |
| 56 | + |
| 57 | + lint-go: |
| 58 | + runs-on: ubuntu-22.04 |
| 59 | + permissions: |
| 60 | + contents: read |
| 61 | + pull-requests: write |
| 62 | + steps: |
| 63 | + - name: Check out code |
| 64 | + uses: actions/checkout@v4 |
| 65 | + |
| 66 | + - name: Install devbox |
| 67 | + uses: jetify-com/[email protected] |
| 68 | + with: |
| 69 | + enable-cache: true |
| 70 | + |
| 71 | + - name: Export golang and golangci-lint versions |
| 72 | + id: versions |
| 73 | + run: | |
| 74 | + echo "golangci-lint=$(devbox run -- golangci-lint version --format short)" >>"${GITHUB_OUTPUT}" |
| 75 | + echo "golang=$(devbox run -- go version | grep -o "[[:digit:]]\+.[[:digit:]]\+\(.[[:digit:]]\+\)\?")" >>"${GITHUB_OUTPUT}" |
| 76 | +
|
| 77 | + - name: golangci-lint |
| 78 | + uses: reviewdog/action-golangci-lint@v2 |
| 79 | + with: |
| 80 | + fail_on_error: true |
| 81 | + reporter: github-pr-review |
| 82 | + golangci_lint_version: v${{ steps.versions.outputs.golangci-lint }} |
| 83 | + go_version: v${{ steps.versions.outputs.golang }} |
| 84 | + golangci_lint_flags: "--config=${{ github.workspace }}/.golangci.yml" |
| 85 | + |
| 86 | + lint-gha: |
| 87 | + runs-on: ubuntu-22.04 |
| 88 | + permissions: |
| 89 | + contents: read |
| 90 | + pull-requests: write |
| 91 | + steps: |
| 92 | + - name: Check out code |
| 93 | + uses: actions/checkout@v4 |
| 94 | + |
| 95 | + - name: actionlint |
| 96 | + uses: reviewdog/action-actionlint@v1 |
| 97 | + with: |
| 98 | + fail_on_error: true |
| 99 | + reporter: github-pr-review |
| 100 | + |
| 101 | + pre-commit: |
| 102 | + runs-on: ubuntu-22.04 |
| 103 | + steps: |
| 104 | + - name: Check out code |
| 105 | + uses: actions/checkout@v4 |
| 106 | + with: |
| 107 | + ref: ${{ github.event.pull_request.head.sha }} |
| 108 | + |
| 109 | + - name: Install devbox |
| 110 | + uses: jetify-com/[email protected] |
| 111 | + with: |
| 112 | + enable-cache: true |
| 113 | + |
| 114 | + - name: Go cache |
| 115 | + uses: actions/cache@v4 |
| 116 | + with: |
| 117 | + path: | |
| 118 | + ~/.cache/go-build |
| 119 | + ~/go/pkg/mod |
| 120 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 121 | + restore-keys: | |
| 122 | + ${{ runner.os }}-go- |
| 123 | +
|
| 124 | + - name: Set up pre-commit cache |
| 125 | + uses: actions/cache@v4 |
| 126 | + with: |
| 127 | + path: ~/.cache/pre-commit |
| 128 | + key: pre-commit-3|${{ hashFiles('.pre-commit-config.yaml') }} |
| 129 | + |
| 130 | + - name: Run pre-commit |
| 131 | + run: devbox run -- make pre-commit |
| 132 | + env: |
| 133 | + SKIP: no-commit-to-branch,golangci-lint,actionlint-system |
| 134 | + |
| 135 | + lint-test-helm: |
| 136 | + runs-on: ubuntu-22.04 |
| 137 | + env: |
| 138 | + KIND_CLUSTER_NAME: chart-testing |
| 139 | + KIND_KUBECONFIG: ct-kind-kubeconfig |
| 140 | + steps: |
| 141 | + - name: Checkout |
| 142 | + uses: actions/checkout@v4 |
| 143 | + with: |
| 144 | + fetch-depth: 0 |
| 145 | + |
| 146 | + - name: Install devbox |
| 147 | + uses: jetify-com/[email protected] |
| 148 | + with: |
| 149 | + enable-cache: true |
| 150 | + |
| 151 | + - name: Run chart-testing (list-changed) |
| 152 | + id: list-changed |
| 153 | + run: | |
| 154 | + changed="$(devbox run -- \ |
| 155 | + ct list-changed --config charts/ct-config.yaml \ |
| 156 | + )" |
| 157 | + if [[ -n "$changed" ]]; then |
| 158 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 159 | + fi |
| 160 | +
|
| 161 | + - if: steps.list-changed.outputs.changed == 'true' |
| 162 | + name: Run chart-testing (lint) |
| 163 | + run: | |
| 164 | + devbox run -- \ |
| 165 | + ct lint --config charts/ct-config.yaml |
| 166 | +
|
| 167 | + - if: steps.list-changed.outputs.changed == 'true' |
| 168 | + name: Create kind cluster |
| 169 | + run: devbox run -- make kind.create |
| 170 | + |
| 171 | + - if: steps.list-changed.outputs.changed == 'true' |
| 172 | + name: Build Docker images |
| 173 | + run: devbox run -- make release-snapshot |
| 174 | + |
| 175 | + - if: steps.list-changed.outputs.changed == 'true' |
| 176 | + name: Sideload docker image |
| 177 | + run: | |
| 178 | + devbox run -- \ |
| 179 | + kind load docker-image \ |
| 180 | + --name "${KIND_CLUSTER_NAME}" \ |
| 181 | + "ko.local/${{ github.event.repository.name }}:$(devbox run -- gojq -r '.version+"-"+.runtime.goarch' dist/metadata.json)" |
| 182 | +
|
| 183 | + - if: steps.list-changed.outputs.changed == 'true' |
| 184 | + name: Setup Cluster API and cert-manager |
| 185 | + run: devbox run -- make clusterctl.init |
| 186 | + |
| 187 | + - if: steps.list-changed.outputs.changed == 'true' |
| 188 | + name: Run chart-testing (install) |
| 189 | + run: | |
| 190 | + devbox run -- \ |
| 191 | + ct install \ |
| 192 | + --config charts/ct-config.yaml \ |
| 193 | + --helm-extra-set-args "--set-string image.repository=ko.local/${{ github.event.repository.name }} --set-string image.tag=$(devbox run -- gojq -r '.version+"-"+.runtime.goarch' dist/metadata.json)" |
| 194 | + env: |
| 195 | + KUBECONFIG: ${{ env.KIND_KUBECONFIG }} |
| 196 | + |
| 197 | + - if: steps.list-changed.outputs.changed == 'true' && always() |
| 198 | + name: Delete chart-testing KinD cluster |
| 199 | + run: | |
| 200 | + devbox run -- make kind.delete |
0 commit comments