|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - release-* |
| 8 | + pull_request: {} |
| 9 | + workflow_dispatch: {} |
| 10 | + |
| 11 | +env: |
| 12 | + # Common versions |
| 13 | + GO_VERSION: '1.20' |
| 14 | + GOLANGCI_VERSION: 'v1.54.0' |
| 15 | + DOCKER_BUILDX_VERSION: 'v0.9.1' |
| 16 | + |
| 17 | + # Common users. We can't run a step 'if secrets.XXX != ""' but we can run a |
| 18 | + # step 'if env.XXX' != ""', so we copy these to succinctly test whether |
| 19 | + # credentials have been provided before trying to run steps that need them. |
| 20 | + UPBOUND_MARKETPLACE_PUSH_ROBOT_USR: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }} |
| 21 | +jobs: |
| 22 | + detect-noop: |
| 23 | + runs-on: ubuntu-22.04 |
| 24 | + outputs: |
| 25 | + noop: ${{ steps.noop.outputs.should_skip }} |
| 26 | + steps: |
| 27 | + - name: Detect No-op Changes |
| 28 | + id: noop |
| 29 | + uses: fkirc/skip-duplicate-actions@v5.2.0 |
| 30 | + with: |
| 31 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + paths_ignore: '["**.md", "**.png", "**.jpg"]' |
| 33 | + do_not_skip: '["workflow_dispatch", "schedule", "push"]' |
| 34 | + |
| 35 | + |
| 36 | + lint: |
| 37 | + runs-on: ubuntu-22.04 |
| 38 | + needs: detect-noop |
| 39 | + if: needs.detect-noop.outputs.noop != 'true' |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Checkout |
| 43 | + uses: actions/checkout@v2 |
| 44 | + with: |
| 45 | + submodules: true |
| 46 | + |
| 47 | + - name: Setup Go |
| 48 | + uses: actions/setup-go@v2 |
| 49 | + with: |
| 50 | + go-version: ${{ env.GO_VERSION }} |
| 51 | + |
| 52 | + - name: Find the Go Build Cache |
| 53 | + id: go |
| 54 | + run: echo "::set-output name=cache::$(make go.cachedir)" |
| 55 | + |
| 56 | + - name: Cache the Go Build Cache |
| 57 | + uses: actions/cache@v2 |
| 58 | + with: |
| 59 | + path: ${{ steps.go.outputs.cache }} |
| 60 | + key: ${{ runner.os }}-build-lint-${{ hashFiles('**/go.sum') }} |
| 61 | + restore-keys: ${{ runner.os }}-build-lint- |
| 62 | + |
| 63 | + - name: Cache Go Dependencies |
| 64 | + uses: actions/cache@v2 |
| 65 | + with: |
| 66 | + path: .work/pkg |
| 67 | + key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }} |
| 68 | + restore-keys: ${{ runner.os }}-pkg- |
| 69 | + |
| 70 | + - name: Vendor Dependencies |
| 71 | + run: make vendor vendor.check |
| 72 | + |
| 73 | + # We could run 'make lint' but we prefer this action because it leaves |
| 74 | + # 'annotations' (i.e. it comments on PRs to point out linter violations). |
| 75 | + - name: Lint |
| 76 | + uses: golangci/golangci-lint-action@v3 |
| 77 | + with: |
| 78 | + version: ${{ env.GOLANGCI_VERSION }} |
| 79 | + |
| 80 | + check-diff: |
| 81 | + runs-on: ubuntu-22.04 |
| 82 | + needs: detect-noop |
| 83 | + if: needs.detect-noop.outputs.noop != 'true' |
| 84 | + |
| 85 | + steps: |
| 86 | + - name: Checkout |
| 87 | + uses: actions/checkout@v2 |
| 88 | + with: |
| 89 | + submodules: true |
| 90 | + |
| 91 | + - name: Setup Go |
| 92 | + uses: actions/setup-go@v2 |
| 93 | + with: |
| 94 | + go-version: ${{ env.GO_VERSION }} |
| 95 | + |
| 96 | + - name: Find the Go Build Cache |
| 97 | + id: go |
| 98 | + run: echo "::set-output name=cache::$(make go.cachedir)" |
| 99 | + |
| 100 | + - name: Cache the Go Build Cache |
| 101 | + uses: actions/cache@v2 |
| 102 | + with: |
| 103 | + path: ${{ steps.go.outputs.cache }} |
| 104 | + key: ${{ runner.os }}-build-check-diff-${{ hashFiles('**/go.sum') }} |
| 105 | + restore-keys: ${{ runner.os }}-build-check-diff- |
| 106 | + |
| 107 | + - name: Cache Go Dependencies |
| 108 | + uses: actions/cache@v2 |
| 109 | + with: |
| 110 | + path: .work/pkg |
| 111 | + key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }} |
| 112 | + restore-keys: ${{ runner.os }}-pkg- |
| 113 | + |
| 114 | + - name: Vendor Dependencies |
| 115 | + run: make vendor vendor.check |
| 116 | + |
| 117 | + - name: Check Diff |
| 118 | + id: check-diff |
| 119 | + run: | |
| 120 | + mkdir _output |
| 121 | + make check-diff |
| 122 | +
|
| 123 | + - name: Show diff |
| 124 | + if: failure() && steps.check-diff.outcome == 'failure' |
| 125 | + run: git diff |
| 126 | + |
| 127 | + unit-tests: |
| 128 | + runs-on: ubuntu-22.04 |
| 129 | + needs: detect-noop |
| 130 | + if: needs.detect-noop.outputs.noop != 'true' |
| 131 | + |
| 132 | + steps: |
| 133 | + - name: Checkout |
| 134 | + uses: actions/checkout@v2 |
| 135 | + with: |
| 136 | + submodules: true |
| 137 | + |
| 138 | + - name: Fetch History |
| 139 | + run: git fetch --prune --unshallow |
| 140 | + |
| 141 | + - name: Setup Go |
| 142 | + uses: actions/setup-go@v2 |
| 143 | + with: |
| 144 | + go-version: ${{ env.GO_VERSION }} |
| 145 | + |
| 146 | + - name: Find the Go Build Cache |
| 147 | + id: go |
| 148 | + run: echo "::set-output name=cache::$(make go.cachedir)" |
| 149 | + |
| 150 | + - name: Cache the Go Build Cache |
| 151 | + uses: actions/cache@v2 |
| 152 | + with: |
| 153 | + path: ${{ steps.go.outputs.cache }} |
| 154 | + key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }} |
| 155 | + restore-keys: ${{ runner.os }}-build-unit-tests- |
| 156 | + |
| 157 | + - name: Cache Go Dependencies |
| 158 | + uses: actions/cache@v2 |
| 159 | + with: |
| 160 | + path: .work/pkg |
| 161 | + key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }} |
| 162 | + restore-keys: ${{ runner.os }}-pkg- |
| 163 | + |
| 164 | + - name: Vendor Dependencies |
| 165 | + run: make vendor vendor.check |
| 166 | + |
| 167 | + - name: Run Unit Tests |
| 168 | + run: make -j2 test |
| 169 | + |
| 170 | + - name: Publish Unit Test Coverage |
| 171 | + uses: codecov/codecov-action@v1 |
| 172 | + with: |
| 173 | + flags: unittests |
| 174 | + file: _output/tests/linux_amd64/coverage.txt |
| 175 | + |
| 176 | + publish-artifacts: |
| 177 | + runs-on: ubuntu-22.04 |
| 178 | + needs: detect-noop |
| 179 | + if: needs.detect-noop.outputs.noop != 'true' |
| 180 | + |
| 181 | + steps: |
| 182 | + - name: Setup QEMU |
| 183 | + uses: docker/setup-qemu-action@v1 |
| 184 | + with: |
| 185 | + platforms: all |
| 186 | + |
| 187 | + - name: Setup Docker Buildx |
| 188 | + uses: docker/setup-buildx-action@v1 |
| 189 | + with: |
| 190 | + version: ${{ env.DOCKER_BUILDX_VERSION }} |
| 191 | + install: true |
| 192 | + |
| 193 | + - name: Login to Upbound |
| 194 | + uses: docker/login-action@v1 |
| 195 | + if: env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR != '' |
| 196 | + with: |
| 197 | + registry: xpkg.upbound.io |
| 198 | + username: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR }} |
| 199 | + password: ${{ secrets.UPBOUND_MARKETPLACE_PUSH_ROBOT_PSW }} |
| 200 | + |
| 201 | + - name: Checkout |
| 202 | + uses: actions/checkout@v2 |
| 203 | + with: |
| 204 | + submodules: true |
| 205 | + |
| 206 | + - name: Fetch History |
| 207 | + run: git fetch --prune --unshallow |
| 208 | + |
| 209 | + - name: Setup Go |
| 210 | + uses: actions/setup-go@v2 |
| 211 | + with: |
| 212 | + go-version: ${{ env.GO_VERSION }} |
| 213 | + |
| 214 | + - name: Find the Go Build Cache |
| 215 | + id: go |
| 216 | + run: echo "::set-output name=cache::$(make go.cachedir)" |
| 217 | + |
| 218 | + - name: Cache the Go Build Cache |
| 219 | + uses: actions/cache@v2 |
| 220 | + with: |
| 221 | + path: ${{ steps.go.outputs.cache }} |
| 222 | + key: ${{ runner.os }}-build-publish-artifacts-${{ hashFiles('**/go.sum') }} |
| 223 | + restore-keys: ${{ runner.os }}-build-publish-artifacts- |
| 224 | + |
| 225 | + - name: Cache Go Dependencies |
| 226 | + uses: actions/cache@v2 |
| 227 | + with: |
| 228 | + path: .work/pkg |
| 229 | + key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }} |
| 230 | + restore-keys: ${{ runner.os }}-pkg- |
| 231 | + |
| 232 | + - name: Vendor Dependencies |
| 233 | + run: make vendor vendor.check |
| 234 | + |
| 235 | + - name: Build Artifacts |
| 236 | + run: make -j2 build.all |
| 237 | + env: |
| 238 | + # We're using docker buildx, which doesn't actually load the images it |
| 239 | + # builds by default. Specifying --load does so. |
| 240 | + BUILD_ARGS: "--load" |
| 241 | + |
| 242 | + - name: Publish Artifacts to GitHub |
| 243 | + uses: actions/upload-artifact@v3 |
| 244 | + with: |
| 245 | + name: output |
| 246 | + path: _output/** |
| 247 | + |
| 248 | + - name: Publish Artifacts |
| 249 | + if: env.UPBOUND_MARKETPLACE_PUSH_ROBOT_USR != '' |
| 250 | + run: make publish BRANCH_NAME=${GITHUB_REF##*/} |
0 commit comments