|
6 | 6 | - main
|
7 | 7 | paths-ignore:
|
8 | 8 | - '**.md'
|
| 9 | + tags: |
| 10 | + - 'v[0-9]+.[0-9]+.[0-9]+' |
9 | 11 | pull_request:
|
10 | 12 | branches:
|
11 | 13 | - main
|
|
15 | 17 | - synchronize
|
16 | 18 | paths-ignore:
|
17 | 19 | - '**.md'
|
18 |
| - create: |
19 |
| - tags: |
20 |
| - - 'v[0-9]+.[0-9]+.[0-9]+*' |
21 |
| - |
22 |
| -env: |
23 |
| - DOCKER_BUILDKIT: 1 |
24 | 20 |
|
25 | 21 | jobs:
|
26 |
| - |
27 | 22 | binary:
|
28 | 23 | name: Build Binary
|
29 | 24 | runs-on: ubuntu-20.04
|
30 | 25 | steps:
|
31 | 26 | - name: Checkout Repository
|
32 | 27 | uses: actions/checkout@v3
|
33 |
| - - name: Determine Go version from go.mod |
34 |
| - run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV |
| 28 | + - name: Cache Go build |
| 29 | + uses: actions/cache@v3 |
| 30 | + with: |
| 31 | + path: | |
| 32 | + ~/.cache/go-build |
| 33 | + ~/go/pkg/mod |
| 34 | + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} |
| 35 | + restore-keys: | |
| 36 | + ${{ runner.os }}-go-build- |
35 | 37 | - name: Setup Golang Environment
|
36 | 38 | uses: actions/setup-go@v3
|
37 | 39 | with:
|
38 |
| - go-version: ${{ env.GO_VERSION }} |
39 |
| - - name: Build Binary |
40 |
| - run: make build |
41 |
| - - name: Store Artifacts in Cache |
42 |
| - uses: actions/cache@v3 |
| 40 | + go-version-file: go.mod |
| 41 | + - name: Determine GOPATH |
| 42 | + id: go |
| 43 | + run: echo "::set-output name=go_path::$(go env GOPATH)" |
| 44 | + - name: Build binary |
| 45 | + uses: goreleaser/goreleaser-action@v3 |
43 | 46 | with:
|
44 |
| - path: ${{ github.workspace }}/nginx-asg-sync |
45 |
| - key: nginx-asg-sync-${{ github.run_id }}-${{ github.run_number }} |
| 47 | + version: latest |
| 48 | + args: build --snapshot --rm-dist --single-target |
| 49 | + env: |
| 50 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + GOPATH: ${{ needs.checks.outputs.go_path }} |
46 | 52 |
|
47 | 53 | unit-tests:
|
48 | 54 | name: Unit Tests
|
49 | 55 | runs-on: ubuntu-20.04
|
50 | 56 | steps:
|
51 | 57 | - name: Checkout Repository
|
52 | 58 | uses: actions/checkout@v3
|
53 |
| - - name: Determine Go version from go.mod |
54 |
| - run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV |
55 | 59 | - name: Setup Golang Environment
|
56 | 60 | uses: actions/setup-go@v3
|
57 | 61 | with:
|
58 |
| - go-version: ${{ env.GO_VERSION }} |
| 62 | + go-version-file: go.mod |
59 | 63 | - name: Run Tests
|
60 | 64 | run: make test
|
61 | 65 |
|
62 | 66 | build:
|
63 |
| - name: Build Image |
| 67 | + name: Build Packages |
64 | 68 | runs-on: ubuntu-20.04
|
65 | 69 | needs: [binary, unit-tests]
|
66 | 70 | steps:
|
67 | 71 | - name: Checkout Repository
|
68 | 72 | uses: actions/checkout@v3
|
69 |
| - - name: Fetch Cached Artifacts |
70 |
| - uses: actions/cache@v3 |
71 | 73 | with:
|
72 |
| - path: ${{ github.workspace }}/nginx-asg-sync |
73 |
| - key: nginx-asg-sync-${{ github.run_id }}-${{ github.run_number }} |
74 |
| - - name: Docker Buildx |
75 |
| - uses: docker/setup-buildx-action@v2 |
76 |
| - - name: Build Image Amazon 2 |
77 |
| - uses: docker/build-push-action@v3 |
78 |
| - with: |
79 |
| - file: build/Dockerfile |
80 |
| - context: '.' |
81 |
| - target: local |
82 |
| - load: true |
83 |
| - cache-from: type=gha |
84 |
| - cache-to: type=gha,mode=max |
85 |
| - tags: amazon2-builder:${{ github.sha }} |
86 |
| - build-args: | |
87 |
| - CONTAINER_VERSION=amazonlinux:2 |
88 |
| - OS_TYPE=rpm_based |
89 |
| - - name: Run Amazon 2 |
90 |
| - uses: addnab/docker-run-action@v3 |
91 |
| - with: |
92 |
| - image: amazon2-builder:${{ github.sha }} |
93 |
| - run: /build.sh |
94 |
| - options: -v ${{ github.workspace }}/build/package/rpm:/rpm -v ${{ github.workspace }}/build_output:/build_output |
95 |
| - - name: Build Image Centos 7 |
96 |
| - uses: docker/build-push-action@v3 |
97 |
| - with: |
98 |
| - file: build/Dockerfile |
99 |
| - context: '.' |
100 |
| - target: local |
101 |
| - load: true |
102 |
| - cache-from: type=gha |
103 |
| - cache-to: type=gha,mode=max |
104 |
| - tags: centos7-builder:${{ github.sha }} |
105 |
| - build-args: | |
106 |
| - CONTAINER_VERSION=centos:7 |
107 |
| - OS_TYPE=rpm_based |
108 |
| - - name: Run Centos 7 |
109 |
| - uses: addnab/docker-run-action@v3 |
110 |
| - with: |
111 |
| - image: centos7-builder:${{ github.sha }} |
112 |
| - run: /build.sh |
113 |
| - options: -v ${{ github.workspace }}/build/package/rpm:/rpm -v ${{ github.workspace }}/build_output:/build_output |
114 |
| - - name: Build Image Centos stream 8 |
115 |
| - uses: docker/build-push-action@v3 |
116 |
| - with: |
117 |
| - file: build/Dockerfile |
118 |
| - context: '.' |
119 |
| - target: local |
120 |
| - load: true |
121 |
| - cache-from: type=gha |
122 |
| - cache-to: type=gha,mode=max |
123 |
| - tags: centosstream8-builder:${{ github.sha }} |
124 |
| - build-args: | |
125 |
| - CONTAINER_VERSION=quay.io/centos/centos:stream8 |
126 |
| - OS_TYPE=rpm_based |
127 |
| - - name: Run Centos stream 8 |
128 |
| - uses: addnab/docker-run-action@v3 |
| 74 | + fetch-depth: 0 |
| 75 | + - name: Cache Go build |
| 76 | + uses: actions/cache@v3 |
129 | 77 | with:
|
130 |
| - image: centosstream8-builder:${{ github.sha }} |
131 |
| - run: /build.sh |
132 |
| - options: -v ${{ github.workspace }}/build/package/rpm:/rpm -v ${{ github.workspace }}/build_output:/build_output |
133 |
| - - name: Build Image Debian |
134 |
| - uses: docker/build-push-action@v3 |
| 78 | + path: | |
| 79 | + ~/.cache/go-build |
| 80 | + ~/go/pkg/mod |
| 81 | + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} |
| 82 | + restore-keys: | |
| 83 | + ${{ runner.os }}-go-build- |
| 84 | + - name: Setup Golang Environment |
| 85 | + uses: actions/setup-go@v3 |
135 | 86 | with:
|
136 |
| - file: build/Dockerfile |
137 |
| - context: '.' |
138 |
| - target: local |
139 |
| - load: true |
140 |
| - cache-from: type=gha |
141 |
| - cache-to: type=gha,mode=max |
142 |
| - tags: debian-builder:${{ github.sha }} |
143 |
| - build-args: | |
144 |
| - OS_TYPE=deb_based |
145 |
| - - name: Run Debian |
146 |
| - uses: addnab/docker-run-action@v3 |
| 87 | + go-version-file: go.mod |
| 88 | + - name: Determine GOPATH |
| 89 | + id: go |
| 90 | + run: echo "::set-output name=go_path::$(go env GOPATH)" |
| 91 | + - name: Download Syft |
| 92 | + uses: anchore/sbom-action/[email protected] |
| 93 | + - name: Build binaries |
| 94 | + uses: goreleaser/goreleaser-action@v3 |
147 | 95 | with:
|
148 |
| - image: debian-builder:${{ github.sha }} |
149 |
| - run: /build.sh |
150 |
| - options: -v ${{ github.workspace }}/build/package/debian:/debian -v ${{ github.workspace }}/build_output:/build_output |
| 96 | + version: latest |
| 97 | + args: release ${{ startsWith(github.ref, 'refs/tags/') && '' || '--snapshot' }} --rm-dist |
| 98 | + env: |
| 99 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 100 | + GOPATH: ${{ needs.checks.outputs.go_path }} |
0 commit comments