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