1name: CI
2
3on:
4 push:
5 branches:
6 - master
7 pull_request:
8 branches:
9 - master
10
11env:
12 GO_DEV_VERSION: "1.15" # Recommended Go version for development.
13 GOLANGCI_LINT_VERSION: "v1.31.0"
14 NODE_VERSION: "14"
15
16jobs:
17 test:
18 runs-on: ubuntu-latest
19 strategy:
20 fail-fast: false
21 matrix:
22 go: ["1.15"]
23 pkger: [false, true]
24 name: Go ${{ matrix.go }} (${{ matrix.pkger && 'static' || 'live' }})
25
26 steps:
27 - uses: actions/checkout@v2
28
29 - name: Cache Go modules
30 uses: actions/cache@v2
31 with:
32 path: ~/go/pkg/mod
33 key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
34
35 - name: Install Go
36 uses: actions/setup-go@v2
37 with:
38 go-version: ${{ matrix.go }}
39
40 - name: Download Go modules
41 run: go mod download
42
43 - name: Run pkger
44 if: ${{ matrix.pkger }}
45 run: |
46 mkdir frontend/build # Ensure this exists; the tests won't use it.
47 go run github.com/markbates/pkger/cmd/pkger list
48 go run github.com/markbates/pkger/cmd/pkger -o internal/pkger
49
50 - name: Run tests
51 run: go test -race -covermode=atomic -coverprofile=coverage.txt ./...
52
53 - name: Run 1x benchmarks
54 run: go test -run=- -bench . -benchtime=1x ./...
55
56 style:
57 name: Style
58 runs-on: ubuntu-latest
59
60 steps:
61 - uses: actions/checkout@v2
62
63 - name: Cache Go modules
64 uses: actions/cache@v2
65 with:
66 path: ~/go/pkg/mod
67 key: ${{ runner.os }}-go-${{ env.GO_DEV_VERSION }}-${{ hashFiles('**/go.sum') }}
68
69 - name: Install Go
70 uses: actions/setup-go@v2
71 with:
72 go-version: ${{ env.GO_DEV_VERSION }}
73
74 - name: Check go.mod tidyness
75 run: |
76 go mod tidy
77 git diff --exit-code go.mod go.sum
78
79 - name: golangci-lint
80 run: |
81 curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin $GOLANGCI_LINT_VERSION
82 $(go env GOPATH)/bin/golangci-lint run --timeout 10m
83
84 generate:
85 name: go generate
86 runs-on: ubuntu-latest
87
88 steps:
89 - uses: actions/checkout@v2
90
91 - name: Cache Go modules
92 uses: actions/cache@v2
93 with:
94 path: ~/go/pkg/mod
95 key: ${{ runner.os }}-go-${{ env.GO_DEV_VERSION }}-${{ hashFiles('**/go.sum') }}
96
97 - name: Install Go
98 uses: actions/setup-go@v2
99 with:
100 go-version: ${{ env.GO_DEV_VERSION }}
101
102 - name: go generate
103 run: |
104 go generate ./...
105 git diff --exit-code
106
107 build_frontend:
108 name: Build frontend
109 runs-on: ubuntu-latest
110 defaults:
111 run:
112 working-directory: frontend
113
114 steps:
115 - uses: actions/checkout@v2
116
117 - uses: actions/setup-node@v2-beta
118 with:
119 node-version: ${{ env.NODE_VERSION }}
120
121 - name: Get yarn cache directory path
122 id: yarn-cache-dir-path
123 run: echo "::set-output name=dir::$(yarn cache dir)"
124
125 - uses: actions/cache@v2
126 with:
127 path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
128 key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
129 restore-keys: |
130 ${{ runner.os }}-yarn-
131
132 - name: yarn install
133 run: yarn install --frozen-lockfile
134
135 - name: yarn build
136 run: yarn build
137
138 docker:
139 name: Docker
140 runs-on: ubuntu-latest
141 needs: [test, style, generate, build_frontend]
142
143 steps:
144 - uses: actions/checkout@v2
145 with:
146 fetch-depth: 0
147
148 - name: Get version
149 run: |
150 export CODIES_VERSION="r$(git rev-list --count HEAD).$(git rev-parse --short HEAD)"
151 echo Version $CODIES_VERSION
152 echo "::set-env name=CODIES_VERSION::$CODIES_VERSION"
153
154 - name: Build / push image
155 uses: whoan/docker-build-with-cache-action@v4
156 with:
157 username: "${{ secrets.DOCKER_USERNAME }}"
158 password: "${{ secrets.DOCKER_PASSWORD }}"
159 image_name: zikaeroh/codies
160 image_tag: "latest,${{ env.CODIES_VERSION }}"
161 build_extra_args: "--build-arg=version=${{ env.CODIES_VERSION }}"
162 push_image_and_stages: ${{ github.repository == 'zikaeroh/codies' && github.event_name == 'push' && github.ref == 'refs/heads/master' }}