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