|
| 1 | +name: build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + workflow_dispatch: |
| 6 | + workflow_call: |
| 7 | + |
| 8 | +env: |
| 9 | + PKG_NAME: "nomad-autoscaler" |
| 10 | + |
| 11 | +jobs: |
| 12 | + get-go-version: |
| 13 | + name: "Determine Go toolchain version" |
| 14 | + runs-on: ubuntu-20.04 |
| 15 | + outputs: |
| 16 | + go-version: ${{ steps.get-go-version.outputs.go-version }} |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v2 |
| 19 | + - name: Determine Go version |
| 20 | + id: get-go-version |
| 21 | + run: | |
| 22 | + echo "Building with Go $(cat .go-version)" |
| 23 | + echo "::set-output name=go-version::$(cat .go-version)" |
| 24 | +
|
| 25 | + get-product-version: |
| 26 | + runs-on: ubuntu-20.04 |
| 27 | + outputs: |
| 28 | + product-version: ${{ steps.get-product-version.outputs.product-version }} |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@v2 |
| 31 | + - name: get product version |
| 32 | + id: get-product-version |
| 33 | + run: | |
| 34 | + make version |
| 35 | + echo "::set-output name=product-version::$(make version)" |
| 36 | +
|
| 37 | + generate-metadata-file: |
| 38 | + needs: get-product-version |
| 39 | + runs-on: ubuntu-20.04 |
| 40 | + outputs: |
| 41 | + filepath: ${{ steps.generate-metadata-file.outputs.filepath }} |
| 42 | + steps: |
| 43 | + - name: "Checkout directory" |
| 44 | + uses: actions/checkout@v2 |
| 45 | + - name: Generate metadata file |
| 46 | + id: generate-metadata-file |
| 47 | + uses: hashicorp/actions-generate-metadata@v1 |
| 48 | + with: |
| 49 | + version: ${{ needs.get-product-version.outputs.product-version }} |
| 50 | + product: ${{ env.PKG_NAME }} |
| 51 | + repositoryOwner: "hashicorp" |
| 52 | + - uses: actions/upload-artifact@v2 |
| 53 | + if: ${{ !env.ACT }} |
| 54 | + with: |
| 55 | + name: metadata.json |
| 56 | + path: ${{ steps.generate-metadata-file.outputs.filepath }} |
| 57 | + |
| 58 | + build-linux: |
| 59 | + needs: |
| 60 | + - get-go-version |
| 61 | + - get-product-version |
| 62 | + runs-on: ubuntu-20.04 |
| 63 | + strategy: |
| 64 | + matrix: |
| 65 | + goos: ["linux"] |
| 66 | + goarch: ["386", "amd64", "arm", "arm64"] |
| 67 | + fail-fast: true |
| 68 | + |
| 69 | + name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build |
| 70 | + |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v2 |
| 73 | + - name: Setup go |
| 74 | + uses: actions/setup-go@v2 |
| 75 | + with: |
| 76 | + go-version: ${{ needs.get-go-version.outputs.go-version }} |
| 77 | + - name: Build |
| 78 | + env: |
| 79 | + GOOS: ${{ matrix.goos }} |
| 80 | + GOARCH: ${{ matrix.goarch }} |
| 81 | + run: | |
| 82 | + make pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 83 | + mv \ |
| 84 | + pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip \ |
| 85 | + ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 86 | + - uses: actions/upload-artifact@v2 |
| 87 | + if: ${{ !env.ACT }} |
| 88 | + with: |
| 89 | + name: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 90 | + path: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 91 | + - name: Package |
| 92 | + uses: hashicorp/actions-packaging-linux@v1 |
| 93 | + with: |
| 94 | + name: "nomad-autoscaler" |
| 95 | + description: "Nomad Autoscaler brings autoscaling to your Nomad workloads." |
| 96 | + arch: ${{ matrix.goarch }} |
| 97 | + version: ${{ needs.get-product-version.outputs.product-version }} |
| 98 | + maintainer: "HashiCorp" |
| 99 | + homepage: "https://github.com/hashicorp/nomad-autoscaler" |
| 100 | + license: "MPL-2.0" |
| 101 | + binary: pkg/${{ matrix.goos }}_${{ matrix.goarch }}/${{ env.PKG_NAME }} |
| 102 | + deb_depends: "openssl" |
| 103 | + rpm_depends: "openssl" |
| 104 | + - name: Set Package Names |
| 105 | + if: ${{ !env.ACT }} |
| 106 | + run: | |
| 107 | + echo "RPM_PACKAGE=$(basename out/*.rpm)" >> $GITHUB_ENV |
| 108 | + echo "DEB_PACKAGE=$(basename out/*.deb)" >> $GITHUB_ENV |
| 109 | + - uses: actions/upload-artifact@v2 |
| 110 | + if: ${{ !env.ACT }} |
| 111 | + with: |
| 112 | + name: ${{ env.RPM_PACKAGE }} |
| 113 | + path: out/${{ env.RPM_PACKAGE }} |
| 114 | + - uses: actions/upload-artifact@v2 |
| 115 | + if: ${{ !env.ACT }} |
| 116 | + with: |
| 117 | + name: ${{ env.DEB_PACKAGE }} |
| 118 | + path: out/${{ env.DEB_PACKAGE }} |
| 119 | + |
| 120 | + build-darwin: |
| 121 | + needs: |
| 122 | + - get-go-version |
| 123 | + - get-product-version |
| 124 | + runs-on: macos-11 |
| 125 | + strategy: |
| 126 | + matrix: |
| 127 | + goos: ["darwin"] |
| 128 | + goarch: ["amd64", "arm64"] |
| 129 | + fail-fast: true |
| 130 | + |
| 131 | + name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build |
| 132 | + |
| 133 | + steps: |
| 134 | + - uses: actions/checkout@v2 |
| 135 | + - name: Setup go |
| 136 | + uses: actions/setup-go@v3 |
| 137 | + with: |
| 138 | + go-version: ${{ needs.get-go-version.outputs.go-version }} |
| 139 | + - name: Build |
| 140 | + env: |
| 141 | + GOOS: ${{ matrix.goos }} |
| 142 | + GOARCH: ${{ matrix.goarch }} |
| 143 | + run: | |
| 144 | + make pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 145 | + mv \ |
| 146 | + pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip \ |
| 147 | + ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 148 | + - uses: actions/upload-artifact@v2 |
| 149 | + if: ${{ !env.ACT }} |
| 150 | + with: |
| 151 | + name: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 152 | + path: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 153 | + |
| 154 | + build-other: |
| 155 | + needs: |
| 156 | + - get-go-version |
| 157 | + - get-product-version |
| 158 | + runs-on: ubuntu-20.04 |
| 159 | + strategy: |
| 160 | + matrix: |
| 161 | + goos: ["freebsd", "windows"] |
| 162 | + goarch: ["amd64", "arm", "arm64"] |
| 163 | + exclude: |
| 164 | + - goos: "windows" |
| 165 | + goarch: "arm" |
| 166 | + fail-fast: true |
| 167 | + |
| 168 | + name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build |
| 169 | + |
| 170 | + steps: |
| 171 | + - uses: actions/checkout@v2 |
| 172 | + - name: Setup go |
| 173 | + uses: actions/setup-go@v3 |
| 174 | + with: |
| 175 | + go-version: ${{ needs.get-go-version.outputs.go-version }} |
| 176 | + - name: Build |
| 177 | + env: |
| 178 | + GOOS: ${{ matrix.goos }} |
| 179 | + GOARCH: ${{ matrix.goarch }} |
| 180 | + run: | |
| 181 | + make pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 182 | + mv \ |
| 183 | + pkg/${{ matrix.goos }}_${{ matrix.goarch }}.zip \ |
| 184 | + ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 185 | + - uses: actions/upload-artifact@v2 |
| 186 | + if: ${{ !env.ACT }} |
| 187 | + with: |
| 188 | + name: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 189 | + path: ${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip |
| 190 | + |
| 191 | + build-docker-default: |
| 192 | + needs: |
| 193 | + - get-product-version |
| 194 | + - build-linux |
| 195 | + runs-on: ubuntu-20.04 |
| 196 | + strategy: |
| 197 | + matrix: |
| 198 | + arch: ["arm", "arm64", "386", "amd64"] |
| 199 | + fail-fast: true |
| 200 | + env: |
| 201 | + version: ${{ needs.get-product-version.outputs.product-version }} |
| 202 | + |
| 203 | + name: Docker ${{ matrix.arch }} default release build |
| 204 | + |
| 205 | + steps: |
| 206 | + - uses: actions/checkout@v2 |
| 207 | + - name: Docker Build (Action) |
| 208 | + uses: hashicorp/actions-docker-build@v1 |
| 209 | + with: |
| 210 | + smoke_test: | |
| 211 | + TEST_VERSION="$(docker run "${IMAGE_NAME}" version | awk '/Nomad Autoscaler/{print $3}')" |
| 212 | + if [ "${TEST_VERSION}" != "v${version}" ]; then |
| 213 | + echo "Test FAILED" |
| 214 | + exit 1 |
| 215 | + fi |
| 216 | + echo "Test PASSED" |
| 217 | + version: ${{ env.version }} |
| 218 | + target: release |
| 219 | + arch: ${{ matrix.arch }} |
| 220 | + tags: | |
| 221 | + docker.io/hashicorp/${{ env.PKG_NAME }}:${{ env.version }} |
| 222 | + 986891699432.dkr.ecr.us-east-1.amazonaws.com/hashicorp/${{ env.PKG_NAME }}:${{ env.version }} |
| 223 | + dev_tags: | |
| 224 | + docker.io/hashicorppreview/${{ env.PKG_NAME }}:${{ env.version }}-dev |
| 225 | + docker.io/hashicorppreview/${{ env.PKG_NAME }}:${{ env.version }}-${{ github.sha }} |
0 commit comments