|
| 1 | +name: Tests |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + arch: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + runner: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + binaries: |
| 15 | + name: Build concierge |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Check out the code |
| 19 | + uses: actions/checkout@v6 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Setup Go |
| 24 | + uses: actions/setup-go@v6 |
| 25 | + with: |
| 26 | + go-version-file: "go.mod" |
| 27 | + |
| 28 | + - name: Run tests |
| 29 | + run: | |
| 30 | + go test -v -race ./... |
| 31 | +
|
| 32 | + - name: Setup goreleaser |
| 33 | + run: | |
| 34 | + sudo snap install --classic goreleaser |
| 35 | +
|
| 36 | + - name: Build concierge |
| 37 | + id: build |
| 38 | + run: | |
| 39 | + goreleaser build --clean --snapshot --single-target --output . |
| 40 | + env: |
| 41 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + GOOS: linux |
| 43 | + GOARCH: ${{ inputs.arch }} |
| 44 | + |
| 45 | + - name: Upload binary artifact |
| 46 | + uses: actions/upload-artifact@v6 |
| 47 | + with: |
| 48 | + name: binary-${{ inputs.runner }} |
| 49 | + path: ./concierge |
| 50 | + |
| 51 | + define-matrix: |
| 52 | + name: Define spread matrix |
| 53 | + runs-on: ubuntu-latest |
| 54 | + outputs: |
| 55 | + suites: ${{ steps.suites.outputs.suites }} |
| 56 | + steps: |
| 57 | + - name: Checkout |
| 58 | + uses: actions/checkout@v6 |
| 59 | + |
| 60 | + - name: Setup Go |
| 61 | + uses: actions/setup-go@v6 |
| 62 | + with: |
| 63 | + go-version-file: "go.mod" |
| 64 | + |
| 65 | + - name: Install |
| 66 | + run: | |
| 67 | + go install github.com/snapcore/spread/cmd/spread@latest |
| 68 | +
|
| 69 | + - name: Generate matrix list |
| 70 | + id: suites |
| 71 | + env: |
| 72 | + ARCH: ${{ inputs.arch }} |
| 73 | + run: | |
| 74 | + list="$(spread -list github-ci | sed "s|github-ci:ubuntu-24.04:tests/||g" | jq -r -ncR '[inputs | select(length>0)]')" |
| 75 | + case $ARCH in |
| 76 | + ppc64le|s390x) |
| 77 | + skip='{ |
| 78 | + "preset-k8s": "Uses k8s snap.", |
| 79 | + "provider-k8s": "Uses k8s snap.", |
| 80 | + "preset-microk8s": "Uses microk8s snap.", |
| 81 | + "provider-microk8s": "Uses microk8s snap.", |
| 82 | + "juju-extra-bootstrap-args": "Uses microk8s snap.", |
| 83 | + "preset-dev": "Uses k8s and microk8s snaps.", |
| 84 | + "overrides-env": "Uses k8s and rockcraft snaps.", |
| 85 | + "provider-lxd-init-no-bootstrap": "Packs a charm (from charmcraft init) for only standard bases." |
| 86 | + }' |
| 87 | + echo "Skipping these tests:" |
| 88 | + echo $skip | jq |
| 89 | + list=$(echo "$list" | jq --compact-output --argjson skip "$skip" 'map(select(. as $item | $skip | has($item) | not))') |
| 90 | + ;; |
| 91 | + amd64) |
| 92 | + echo 'Standard architecture, using all tests.' |
| 93 | + ;; |
| 94 | + *) |
| 95 | + echo "Unknown architecture $ARCH, using all tests." |
| 96 | + ;; |
| 97 | + esac |
| 98 | + echo "suites=$list" |
| 99 | + echo "suites=$list" >> $GITHUB_OUTPUT |
| 100 | +
|
| 101 | + spread-test: |
| 102 | + name: Spread (${{ matrix.suite }}) |
| 103 | + runs-on: ${{ inputs.runner }} |
| 104 | + needs: |
| 105 | + - binaries |
| 106 | + - define-matrix |
| 107 | + strategy: |
| 108 | + fail-fast: false |
| 109 | + matrix: |
| 110 | + suite: ${{ fromJSON(needs.define-matrix.outputs.suites) }} |
| 111 | + steps: |
| 112 | + - name: Checkout |
| 113 | + uses: actions/checkout@v6 |
| 114 | + |
| 115 | + - name: Download binary artifact |
| 116 | + uses: actions/download-artifact@v7 |
| 117 | + with: |
| 118 | + name: binary-${{ inputs.runner }} |
| 119 | + |
| 120 | + - name: Setup Go |
| 121 | + uses: actions/setup-go@v6 |
| 122 | + with: |
| 123 | + go-version-file: "go.mod" |
| 124 | + architecture: ${{ inputs.arch }} |
| 125 | + |
| 126 | + - name: Install |
| 127 | + run: | |
| 128 | + go install github.com/snapcore/spread/cmd/spread@latest |
| 129 | +
|
| 130 | + - name: Run integration tests |
| 131 | + run: | |
| 132 | + spread -v "github-ci:ubuntu-24.04:tests/${{ matrix.suite }}" |
0 commit comments