-
Notifications
You must be signed in to change notification settings - Fork 54
150 lines (141 loc) · 4.37 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
146
147
148
149
150
name: build
on: [push, pull_request]
env:
GO_VERSION: 1.17.8
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: pre-commit/action@v2.0.3
git-describe:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Fetch tags
run: git fetch --force --tags
- run: git describe --always
- run: git describe --tags
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: Run unit tests
run: go test -v -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... ./...
- name: Report coverage
run: go tool cover -func=coverage.txt
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Fetch tags
run: git fetch --force --tags
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: Set binary name
run: echo "BINARY_NAME=htmltest-${{ matrix.os }}-$(echo $GITHUB_REF | cut -d'/' -f 3)-$(echo $GITHUB_SHA | cut -c1-8)" >> $GITHUB_ENV
- name: Build
run: go build -ldflags "-X main.date=`date -u +%Y-%m-%dT%H:%M:%SZ` -X main.version=`git describe --tags`" -o bin/$BINARY_NAME -x main.go
- name: Upload binary
uses: actions/upload-artifact@v2
with:
name: ${{ env.BINARY_NAME }}
path: bin/${{ env.BINARY_NAME }}
- name: Print usage and version
run: |
bin/$BINARY_NAME -h # Print usage
bin/$BINARY_NAME -v # Print version
- name: Test running binary against fixtures
run: |
bin/$BINARY_NAME -c htmldoc/fixtures/conf.yaml -l0 # Run config
bin/$BINARY_NAME htmldoc/fixtures/documents/dir1 # Run on dir
bin/$BINARY_NAME htmltest/fixtures/links/head_link_href.html # Run on file
fmt:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: gofmt
run: test -z "$(gofmt -d .)"
goreleaser:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: [ test, build ]
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Fetch tags
run: git fetch --force --tags
- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker-build:
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
needs: [ test, build ]
env:
DOCKER_REPO: wjdp/htmltest
steps:
- name: Checkout repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Fetch tags
run: git fetch --force --tags
- name: Set GIT_VERSION
run: echo "GIT_VERSION=$(git describe --tags)" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
push: true
tags: ${{ env.DOCKER_REPO }}:${{ env.GIT_VERSION }}
cache-from: ${{ env.DOCKER_REPO }}:latest
build-args: |
VERSION=${{ env.GIT_VERSION }}
GO_VERSION=${{ env.GO_VERSION }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}