-
Notifications
You must be signed in to change notification settings - Fork 13
145 lines (140 loc) · 4.85 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: ci
on:
push:
pull_request:
jobs:
golangci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'
- uses: actions/setup-go@v5
with:
go-version: "^1.20"
- uses: golangci/golangci-lint-action@v6.1.1
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'
- uses: actions/setup-go@v5
with:
go-version: "^1.20"
- name: run tests on cmd
run: go test ./cmd
- name: run tests on pkg
run: go test ./pkg -timeout 120s -coverprofile=cover.out -covermode=atomic
- uses: codecov/codecov-action@v4
with:
files: ./cover.out
version_tag:
if: github.event.repository.fork == false && github.actor != 'dependabot[bot]'
needs:
- tests
- golangci
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.tag_action.outputs.new_tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Bump version and push tag
if: github.ref == 'refs/heads/main'
id: tag_action
uses: anothrNick/github-tag-action@1.71.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
DEFAULT_BUMP: patch
PRERELEASE: ${{ github.ref != 'refs/heads/main' }}
build:
if: github.event.repository.fork == false && github.actor != 'dependabot[bot]'
needs: version_tag
runs-on: ubuntu-latest
env:
CGO_ENABLED: 0
strategy:
matrix:
goos: [linux, darwin]
goarch: ["386", amd64, arm64]
exclude:
- goarch: "386"
goos: darwin
steps:
- uses: actions/checkout@v4
with:
fetch-depth: '0'
## build tailwind assets
- uses: actions/setup-node@v4
with:
node-version: '19'
- uses: pnpm/action-setup@v2
with:
version: 8
- run: pnpm install
- run: npm run build
## setup go
- uses: actions/setup-go@v5
with:
go-version: "^1.22"
## above is fine to get latest for now, also save a copy with short sha
- id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- run: mkdir -p ${{ matrix.goos }}/${{ matrix.goarch }}
- run: env GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags="-X 'github.com/datarootsio/cheek/pkg.version=${{ needs.version_tag.outputs.new_tag }}' -X 'github.com/datarootsio/cheek/pkg.commitSHA=${{ steps.vars.outputs.sha_short }}'" -o ${{ matrix.goos }}/${{ matrix.goarch }}
- run: cp ${{ matrix.goos }}/${{ matrix.goarch }}/cheek ${{ matrix.goos }}/${{ matrix.goarch }}/cheek-${{ steps.vars.outputs.sha_short }}
- run: cp ${{ matrix.goos }}/${{ matrix.goarch }}/cheek ${{ matrix.goos }}/${{ matrix.goarch }}/cheek-${{ needs.version_tag.outputs.new_tag }}
## upload binary to google storage
- id: auth
uses: google-github-actions/auth@v2.1.6
with:
credentials_json: ${{ secrets.gcp_credentials_cheek }}
- id: upload-files
uses: google-github-actions/upload-cloud-storage@v2.2.0
with:
path: ${{ matrix.goos }}/${{ matrix.goarch }}/cheek-${{ steps.vars.outputs.sha_short }}
destination: cheek-scheduler/${{ matrix.goos }}/${{ matrix.goarch }}/
- uses: google-github-actions/upload-cloud-storage@v2.2.0
if: github.ref == 'refs/heads/main'
with:
path: ${{ matrix.goos }}/${{ matrix.goarch }}/cheek-${{ needs.version_tag.outputs.new_tag }}
destination: cheek-scheduler/${{ matrix.goos }}/${{ matrix.goarch }}/
- uses: google-github-actions/upload-cloud-storage@v2.2.0
if: github.ref == 'refs/heads/main'
with:
path: ${{ matrix.goos }}/${{ matrix.goarch }}/cheek
destination: cheek-scheduler/${{ matrix.goos }}/${{ matrix.goarch }}/
docker-build:
## only do this on main
needs:
- build
- version_tag
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: |
ghcr.io/datarootsio/cheek:latest
ghcr.io/datarootsio/cheek:${{ needs.version_tag.outputs.new_tag }}