|
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: |
| 22 | + vars: |
| 23 | + name: Checks and variables |
| 24 | + runs-on: ubuntu-20.04 |
| 25 | + outputs: |
| 26 | + go_version: ${{ steps.vars.outputs.go_version }} |
| 27 | + steps: |
| 28 | + - name: Checkout Repository |
| 29 | + uses: actions/checkout@v3 |
| 30 | + - name: Output Variables |
| 31 | + id: vars |
| 32 | + run: | |
| 33 | + echo "::set-output name=go_version::$(grep "go 1." go.mod | cut -d " " -f 2)" |
26 | 34 |
|
27 | 35 | binary: |
28 | 36 | name: Build Binary |
29 | 37 | runs-on: ubuntu-20.04 |
| 38 | + needs: vars |
30 | 39 | steps: |
31 | 40 | - name: Checkout Repository |
32 | 41 | 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 |
| 42 | + - name: Cache Go build |
| 43 | + uses: actions/cache@v3 |
| 44 | + with: |
| 45 | + path: | |
| 46 | + ~/.cache/go-build |
| 47 | + ~/go/pkg/mod |
| 48 | + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} |
| 49 | + restore-keys: | |
| 50 | + ${{ runner.os }}-go-build- |
35 | 51 | - name: Setup Golang Environment |
36 | 52 | uses: actions/setup-go@v3 |
37 | 53 | 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 |
| 54 | + go-version: ${{ needs.checks.outputs.go_version }} |
| 55 | + - name: Build binary |
| 56 | + uses: goreleaser/goreleaser-action@v3 |
43 | 57 | with: |
44 | | - path: ${{ github.workspace }}/nginx-asg-sync |
45 | | - key: nginx-asg-sync-${{ github.run_id }}-${{ github.run_number }} |
| 58 | + version: latest |
| 59 | + args: build --snapshot --rm-dist --single-target |
| 60 | + env: |
| 61 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 62 | + GOPATH: ${{ needs.checks.outputs.go_path }} |
46 | 63 |
|
47 | 64 | unit-tests: |
48 | 65 | name: Unit Tests |
49 | 66 | runs-on: ubuntu-20.04 |
| 67 | + needs: vars |
50 | 68 | steps: |
51 | 69 | - name: Checkout Repository |
52 | 70 | 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 | 71 | - name: Setup Golang Environment |
56 | 72 | uses: actions/setup-go@v3 |
57 | 73 | with: |
58 | | - go-version: ${{ env.GO_VERSION }} |
| 74 | + go-version: ${{ needs.vars.outputs.go_version }} |
59 | 75 | - name: Run Tests |
60 | 76 | run: make test |
61 | 77 |
|
62 | 78 | build: |
63 | | - name: Build Image |
| 79 | + name: Build Packages |
64 | 80 | runs-on: ubuntu-20.04 |
65 | 81 | needs: [binary, unit-tests] |
66 | 82 | steps: |
67 | 83 | - name: Checkout Repository |
68 | 84 | uses: actions/checkout@v3 |
69 | | - - name: Fetch Cached Artifacts |
70 | | - uses: actions/cache@v3 |
71 | | - 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 | 85 | 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 |
| 86 | + fetch-depth: 0 |
| 87 | + - name: Cache Go build |
| 88 | + uses: actions/cache@v3 |
129 | 89 | 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 |
| 90 | + path: | |
| 91 | + ~/.cache/go-build |
| 92 | + ~/go/pkg/mod |
| 93 | + key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }} |
| 94 | + restore-keys: | |
| 95 | + ${{ runner.os }}-go-build- |
| 96 | + - name: Determine GOPATH |
| 97 | + id: go |
| 98 | + run: echo "::set-output name=go_path::$(go env GOPATH)" |
| 99 | + - name: Setup Golang Environment |
| 100 | + uses: actions/setup-go@v3 |
135 | 101 | 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 |
| 102 | + go-version: ${{ needs.vars.outputs.go_version }} |
| 103 | + - name: Download Syft |
| 104 | + uses: anchore/sbom-action/[email protected] |
| 105 | + - name: Build binaries |
| 106 | + uses: goreleaser/goreleaser-action@v3 |
147 | 107 | 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 |
| 108 | + version: latest |
| 109 | + args: release ${{ startsWith(github.ref, 'refs/tags/') && '' || '--snapshot' }} --rm-dist |
| 110 | + env: |
| 111 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 112 | + GOPATH: ${{ needs.checks.outputs.go_path }} |
0 commit comments