|
7 | 7 |
|
8 | 8 | jobs:
|
9 | 9 | build:
|
10 |
| - runs-on: ubuntu-latest |
11 |
| - strategy: |
12 |
| - matrix: |
13 |
| - goos: [linux, darwin, windows] |
14 |
| - goarch: [arm64, amd64] |
15 |
| - exclude: |
16 |
| - - goarch: arm64 |
17 |
| - goos: windows |
| 10 | + runs-on: ubuntu-22.04 |
| 11 | + outputs: |
| 12 | + matrix: ${{ steps.configure.outputs.matrix }} |
| 13 | + artifacts-dir: ${{ steps.configure.outputs.artifacts-dir }} |
| 14 | + cache-key: ${{ steps.configure.outputs.cache-key }} |
18 | 15 | steps:
|
19 | 16 | - name: Checkout commit
|
20 |
| - uses: actions/checkout@v3 |
| 17 | + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
21 | 20 |
|
22 | 21 | - name: Setup Go
|
23 |
| - uses: actions/setup-go@v3 |
| 22 | + uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a #v3.2.1 |
24 | 23 | with:
|
25 | 24 | go-version: 1.19
|
26 | 25 |
|
27 |
| - - name: Build Falcoctl |
28 |
| - run: > |
29 |
| - go build -o falcoctl-${{ matrix.goos }}-${{ matrix.goarch }} . |
30 |
| - env: |
31 |
| - CGO_ENABLED: 0 |
32 |
| - GOOS: ${{ matrix.goos }} |
33 |
| - GOARCH: ${{ matrix.goarch }} |
| 26 | + - name: Run GoReleaser |
| 27 | + uses: goreleaser/goreleaser-action@68acf3b1adf004ac9c2f0a4259e85c5f66e99bef #v3.0.0 |
| 28 | + with: |
| 29 | + distribution: goreleaser |
| 30 | + version: v1.10.3 |
| 31 | + args: release --rm-dist --snapshot |
34 | 32 |
|
35 |
| - - name: Create Archives |
| 33 | + - name: Save config variables |
| 34 | + id: configure |
36 | 35 | run: |
|
37 |
| - cp falcoctl-${{ matrix.goos }}-${{ matrix.goarch }} falcoctl |
38 |
| - tar -czvf falcoctl-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz falcoctl LICENSE |
| 36 | + # Save artifacts info in matrix variable. Only artifacts of type "Archive". |
| 37 | + # The matrix variable is used in a later job to upload the artifacts. |
| 38 | + matrix=$(jq 'map(. | select(.type=="Archive"))' dist/artifacts.json) |
| 39 | + echo "::set-output name=matrix::{\"include\":$(echo $matrix)}" |
| 40 | + |
| 41 | + # Save the commit hash to be used as unique key for the cached artifacts. |
| 42 | + echo "::set-output name=cache-key::${{ github.sha }}" |
| 43 | + |
| 44 | + # Save the artifacts directory in a variable. |
| 45 | + echo "::set-output name=artifacts-dir::dist" |
39 | 46 |
|
40 |
| - - name: Upload falcoctl |
41 |
| - uses: actions/upload-artifact@v2 |
| 47 | + - name: Cache artifacts - upload |
| 48 | + id: cache-artifacts |
| 49 | + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 #v3.0.8 |
42 | 50 | with:
|
43 |
| - name: falcoctl-${{ matrix.goos }}-${{ matrix.goarch }} |
44 |
| - path: ./falcoctl-${{ matrix.goos }}-${{ matrix.goarch }} |
45 |
| - retention-days: 1 |
| 51 | + path: ${{ steps.configure.outputs.artifacts-dir }} |
| 52 | + key: ${{ steps.configure.outputs.cache-key }} |
| 53 | + |
| 54 | + upload-artifacts: |
| 55 | + runs-on: ubuntu-22.04 |
| 56 | + needs: build |
| 57 | + strategy: |
| 58 | + matrix: ${{ fromJson(needs.build.outputs.matrix) }} |
| 59 | + steps: |
| 60 | + - name: Cache artifacts - download |
| 61 | + id: cache-artifacts |
| 62 | + uses: actions/cache@fd5de65bc895cf536527842281bea11763fefd77 #v3.0.8 |
| 63 | + with: |
| 64 | + path: ${{ needs.build.outputs.artifacts-dir}} |
| 65 | + key: ${{ needs.build.outputs.cache-key}} |
46 | 66 |
|
47 |
| - - name: Upload falcoctl Archive |
48 |
| - uses: actions/upload-artifact@v2 |
| 67 | + - name: Upload ${{ matrix.name }} |
| 68 | + uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 #v3.1.0 |
49 | 69 | with:
|
50 |
| - name: falcoctl-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz |
51 |
| - path: ./falcoctl-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz |
| 70 | + name: ${{ matrix.name }} |
| 71 | + path: ./${{ matrix.path }} |
52 | 72 | retention-days: 1
|
53 | 73 |
|
54 | 74 | test:
|
55 | 75 | needs: build
|
56 | 76 | runs-on: ubuntu-latest
|
57 | 77 | steps:
|
58 |
| - - name: Checkout commit |
59 |
| - uses: actions/checkout@v3 |
| 78 | + - name: Checkout commit |
| 79 | + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b #v3.0.2 |
60 | 80 |
|
61 |
| - - name: Setup Go 1.19 |
62 |
| - uses: actions/setup-go@v3 |
63 |
| - with: |
64 |
| - go-version: 1.19 |
65 |
| - - run: go test ./... |
| 81 | + - name: Setup Go |
| 82 | + uses: actions/setup-go@84cbf8094393cdc5fe1fe1671ff2647332956b1a #v3.2.1 |
| 83 | + with: |
| 84 | + go-version: 1.19 |
| 85 | + |
| 86 | + - name: Run tests |
| 87 | + run: go test ./... |
0 commit comments