Skip to content

Commit 2a2cfc4

Browse files
authored
ci: Add cache (#36)
* ci: Add cache ci: Change config * chore(scripts): Add check goreleaser check script * ci: Build only for one platform for check
1 parent 1b79a05 commit 2a2cfc4

File tree

4 files changed

+142
-2
lines changed

4 files changed

+142
-2
lines changed

.github/workflows/go.yml

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818
- 'go.sum'
1919
- 'Makefile'
2020
- '!**.*md'
21+
- '.github/workflows/**'
2122

2223
jobs:
2324
linting:
@@ -43,18 +44,37 @@ jobs:
4344
go-version: ${{ matrix.go }}
4445
- run: |
4546
go version
47+
shell: bash
4648
4749
- name: Vet
4850
run: |
4951
make vet
52+
shell: bash
53+
54+
- name: Set up cache
55+
uses: actions/cache@v2.1.6
56+
env:
57+
cache-name: cache-vendored-tools
58+
with:
59+
path: |
60+
${{ env.GOBIN }}
61+
~/.cache/go-build
62+
~/go/pkg/mod
63+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/tools/go.sum') }}
64+
restore-keys: |
65+
${{ runner.os }}-build-${{ env.cache-name }}-
66+
${{ runner.os }}-build-
67+
${{ runner.os }}-
5068
5169
- name: Install tools
5270
run: |
5371
make install-tools
72+
shell: bash
5473

5574
- name: Lint
5675
run: |
5776
make lint-pipeline
77+
shell: bash
5878

5979
reports:
6080
needs: linting
@@ -79,27 +99,48 @@ jobs:
7999
go-version: ${{ matrix.go }}
80100
- run: |
81101
go version
102+
shell: bash
103+
104+
- name: Set up cache
105+
uses: actions/cache@v2.1.6
106+
env:
107+
cache-name: cache-vendored-tools
108+
with:
109+
path: |
110+
${{ env.GOBIN }}
111+
~/.cache/go-build
112+
~/go/pkg/mod
113+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/tools/go.sum') }}
114+
restore-keys: |
115+
${{ runner.os }}-build-${{ env.cache-name }}-
116+
${{ runner.os }}-build-
117+
${{ runner.os }}-
82118
83119
- name: Install tools
84120
run: |
85121
make install-tools
122+
shell: bash
86123

87124
- name: Prepare test coverage
88125
run: |
89126
make test-cover
127+
shell: bash
90128

91129
- name: Tests report
92130
run: |
93131
make test-sonar-report
132+
shell: bash
94133

95134
- name: Prepare lint report
96135
run: |
97136
make lint-sonar
137+
shell: bash
98138

99139
- name: Cover report upload
100140
if: success()
101141
run: |
102-
bash <(curl -s https://codecov.io/bash) -f ./coverage/full.cov
142+
bash <(curl -s https://codecov.io/bash) -f ./coverage/full.cov
143+
shell: bash
103144

104145
- name: SonarCloud report upload
105146
uses: sonarsource/sonarcloud-github-action@v1.6
@@ -127,16 +168,35 @@ jobs:
127168
with:
128169
stable: 'true'
129170
go-version: ${{ matrix.go }}
171+
130172
- run: |
131173
go version
174+
shell: bash
175+
176+
- name: Set up cache
177+
uses: actions/cache@v2.1.6
178+
env:
179+
cache-name: cache-vendored-tools
180+
with:
181+
path: |
182+
${{ env.GOBIN }}
183+
~/.cache/go-build
184+
~/go/pkg/mod
185+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/tools/go.sum') }}
186+
restore-keys: |
187+
${{ runner.os }}-build-${{ env.cache-name }}-
188+
${{ runner.os }}-build-
189+
${{ runner.os }}-
132190
133191
- name: Install tools
134192
run: |
135193
make install-tools
194+
shell: bash
136195

137196
- name: Test
138197
run: |
139198
make test
199+
shell: bash
140200

141201

142202
build:
@@ -160,17 +220,38 @@ jobs:
160220
with:
161221
stable: 'true'
162222
go-version: ${{ matrix.go }}
223+
163224
- run: |
164225
go version
226+
shell: bash
227+
228+
- name: Set up cache
229+
uses: actions/cache@v2.1.6
230+
env:
231+
cache-name: cache-vendored-tools
232+
with:
233+
path: |
234+
${{ env.GOBIN }}
235+
~/.cache/go-build
236+
~/go/pkg/mod
237+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/tools/go.sum') }}
238+
restore-keys: |
239+
${{ runner.os }}-build-${{ env.cache-name }}-
240+
${{ runner.os }}-build-
241+
${{ runner.os }}-
242+
165243
166244
- name: Install tools
167245
run: |
168246
make install-tools
247+
shell: bash
169248

170249
- name: Build
171250
run: |
172251
make build
252+
shell: bash
173253

174254
- name: Check release
175255
run: |
176-
make release-local-snapshot
256+
make check-releaser
257+
shell: bash

.github/workflows/release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,35 @@ jobs:
2828
with:
2929
stable: 'true'
3030
go-version: ${{ matrix.go }}
31+
3132
- run: |
3233
go version
34+
shell: bash
3335
3436
- name: Install tools
3537
run: |
3638
make install-tools
39+
shell: bash
3740

3841
- name: Vet
3942
run: |
4043
make vet
44+
shell: bash
4145

4246
- name: Lint
4347
run: |
4448
make lint-pipeline
49+
shell: bash
4550

4651
- name: Test
4752
run: |
4853
make test
54+
shell: bash
4955

5056
- name: Run GoReleaser
5157
if: success()
5258
env:
5359
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5460
run: |
5561
make release
62+
shell: bash

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ release-local-snapshot:
121121
./scripts/release/local-snapshot-release.sh
122122
.PHONY: release-local-snapshot
123123

124+
## Check goreleaser config.
125+
check-releaser:
126+
./scripts/release/check.sh
127+
.PHONY: check-releaser
128+
124129
## Issue new release.
125130
new-version: vet test build
126131
./scripts/release/new-version.sh

scripts/release/check.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
set -Eeuo pipefail
4+
5+
SCRIPT_NAME="$(basename "$0")"
6+
SCRIPT_DIR="$(dirname "$0")"
7+
REPO_ROOT="$(cd "${SCRIPT_DIR}" && git rev-parse --show-toplevel)"
8+
SCRIPTS_DIR="${REPO_ROOT}/scripts"
9+
10+
source "${SCRIPTS_DIR}/helpers-source.sh"
11+
12+
echo "${SCRIPT_NAME} is running... "
13+
14+
checkInstalled 'goreleaser'
15+
16+
APP=aoc-cli
17+
18+
# Get new tags from the remote
19+
git fetch --tags -f
20+
21+
COMMIT="$(git rev-parse HEAD)"
22+
SHORTCOMMIT="$(git rev-parse --short HEAD)"
23+
DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
24+
VERSION="$(git describe --tags --always "$(git rev-list --tags --max-count=1)")"
25+
GOVERSION="$(go version | awk '{print $3;}')"
26+
27+
if [ -z "${VERSION}" ] || [ "${VERSION}" = "${SHORTCOMMIT}" ]
28+
then
29+
VERSION="v0.0.0"
30+
fi
31+
32+
33+
VERSION="${VERSION}-local"
34+
35+
36+
BUILDINFO_VARS_PKG=github.com/obalunenko/version
37+
export GO_BUILD_LDFLAGS="-s -w \
38+
-X ${BUILDINFO_VARS_PKG}.version=${VERSION} \
39+
-X ${BUILDINFO_VARS_PKG}.commit=${COMMIT} \
40+
-X ${BUILDINFO_VARS_PKG}.shortcommit=${SHORTCOMMIT} \
41+
-X ${BUILDINFO_VARS_PKG}.builddate=${DATE} \
42+
-X ${BUILDINFO_VARS_PKG}.appname=${APP} \
43+
-X ${BUILDINFO_VARS_PKG}.goversion=${GOVERSION}"
44+
45+
goreleaser check
46+
47+
goreleaser build --rm-dist --single-target --snapshot

0 commit comments

Comments
 (0)