forked from gocolly/colly
-
Notifications
You must be signed in to change notification settings - Fork 0
191 lines (179 loc) · 5.32 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
---
name: CI
on:
push:
branches:
- '**'
pull_request:
jobs:
test:
name: Test ${{matrix.go}}
runs-on: [ubuntu-latest]
strategy:
fail-fast: false
max-parallel: 4
matrix:
go: [
"1.22",
"1.21",
"1.20",
"1.19",
]
steps:
- name: Checkout branch
uses: actions/checkout@v2
- name: Setup go
uses: actions/setup-go@v2
with:
go-version: ${{matrix.go}}
- name: Test
run: |
go install golang.org/x/lint/golint@latest
OUT="$(go get -a)"; test -z "$OUT" || (echo "$OUT" && return 1)
OUT="$(gofmt -l -d ./)"; test -z "$OUT" || (echo "$OUT" && return 1)
golint -set_exit_status
go vet -v ./...
go test -race -v -coverprofile=coverage.txt -covermode=atomic ./...
build:
name: Build ${{matrix.go}}
runs-on: [ubuntu-latest]
strategy:
fail-fast: false
max-parallel: 4
matrix:
go: [
"1.22",
"1.21",
"1.20",
"1.19",
]
steps:
- name: Checkout branch
uses: actions/checkout@v2
- name: Setup go
uses: actions/setup-go@v2
with:
go-version: ${{matrix.go}}
- name: Build
run: |
go install golang.org/x/lint/golint@latest
OUT="$(go get -a)"; test -z "$OUT" || (echo "$OUT" && return 1)
OUT="$(gofmt -l -d ./)"; test -z "$OUT" || (echo "$OUT" && return 1)
golint -set_exit_status
go build
codecov:
name: Codecov
runs-on: [ubuntu-latest]
needs:
- test
- build
steps:
- name: Run Codecov
run: bash <(curl -s https://codecov.io/bash)
# Increments to the next tag on master only, bumps version based on the recent commits
new_tag:
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' && github.event_name == 'push'
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Get next version
id: new_git_tag
run: |
go install github.com/caarlos0/svu@latest
NEW_TAG=$(svu next --force-patch-increment)
echo "Using the next tag of ${NEW_TAG} for this release"
echo "new_tag=$NEW_TAG" >> $GITHUB_ENV
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT
outputs:
new_tag: ${{ steps.new_git_tag.outputs.new_tag }}
# Creates a new release page on GitHub when master changes
create_release:
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' && github.event_name == 'push'
runs-on: ubuntu-latest
needs: new_tag
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.new_tag.outputs.new_tag }}
release_name: Release ${{ needs.new_tag.outputs.new_tag }}
draft: false
prerelease: false
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
# In this Release section, we are re-building the binaries because eventually we can include the new git tag as their
# version string when saying 'colly --version'
build_and_upload:
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' && github.event_name == 'push'
runs-on: ubuntu-latest
needs: [test, new_tag, create_release]
strategy:
matrix:
include:
- target: linux-i386
goos: linux
goarch: 386
- target: linux-x86_64
goos: linux
goarch: amd64
- target: linux-armv6
goos: linux
goarch: arm
goarm: 6
- target: linux-armv7
goos: linux
goarch: arm
goarm: 7
- target: linux-arm64
goos: linux
goarch: arm64
- target: linux-riscv64
goos: linux
goarch: riscv64
- target: darwin-x86_64
goos: darwin
goarch: amd64
- target: darwin-arm64
goos: darwin
goarch: arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Build binaries
env:
TARGET: ${{ matrix.target }}
GOARCH: ${{ matrix.goarch }}
GOOS: ${{ matrix.goos }}
GOARM: ${{ matrix.goarm }}
run: |
OUT_DIR=dist/colly-$TARGET
mkdir -p $OUT_DIR
go build -o $OUT_DIR/colly ./cmd/colly
- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./dist/colly-${{ matrix.target }}/colly
asset_name: colly-${{ matrix.target }}/colly
asset_content_type: application/octet-stream