-
Notifications
You must be signed in to change notification settings - Fork 53
160 lines (142 loc) · 4.72 KB
/
Copy pathci.yml
File metadata and controls
160 lines (142 loc) · 4.72 KB
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
name: CI
on:
push:
pull_request:
branches: [ master, main, dev ]
permissions:
contents: read
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
name: Test (${{ matrix.os }}, Go ${{ matrix.go-version }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go-version: [ '1.21.13', '1.26.7' ]
exclude:
# Go 1.21's internal linker omits LC_UUID, which current macOS
# runners require before they will execute test binaries.
- os: macos-latest
go-version: '1.21.13'
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: Verify dependencies
run: go mod verify
- name: Check formatting and module tidiness
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.26.7'
shell: bash
run: |
unformatted="$(git ls-files -z '*.go' | xargs -0 gofmt -l)"
test -z "${unformatted}"
go mod tidy
git diff --exit-code -- go.mod go.sum
- name: Run go vet
run: go vet ./...
- name: Run static analysis
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.26.7'
run: go run honnef.co/go/tools/cmd/staticcheck@v0.8.1 ./...
- name: Run unit tests
shell: bash
run: |
set +e
test_output="$(go test -v ./... 2>&1)"
test_status=$?
printf '%s\n' "${test_output}"
if [ "${test_status}" -ne 0 ]; then
diagnostic="$(printf '%s' "${test_output}" | tail -c 8000)"
diagnostic="${diagnostic//'%'/'%25'}"
diagnostic="${diagnostic//$'\r'/'%0D'}"
diagnostic="${diagnostic//$'\n'/'%0A'}"
echo "::error title=Unit tests failed::${diagnostic}"
exit "${test_status}"
fi
- name: Run race detector
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.26.7'
run: go test -race ./...
- name: Scan reachable dependencies for vulnerabilities
if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.26.7'
run: go run golang.org/x/vuln/cmd/govulncheck@v1.7.0 ./...
build:
name: Cross-Platform Build
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
- goos: linux
goarch: arm
goarm: 7
- goos: linux
goarch: arm
goarm: 6
- goos: linux
goarch: 386
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64
- goos: windows
goarch: amd64
- goos: windows
goarch: arm64
- goos: windows
goarch: 386
- goos: freebsd
goarch: amd64
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version: '1.26.7'
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOARM: ${{ matrix.goarm }}
CGO_ENABLED: 0
run: |
OUTPUT="transmission-telegram-${{ matrix.goos }}-${{ matrix.goarch }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
OUTPUT="${OUTPUT}.exe"
fi
go build -trimpath -v -o "${OUTPUT}" ./cmd/bot/
container:
name: Container Build
runs-on: ubuntu-latest
needs: test
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Build and inspect container
shell: bash
env:
DOCKER_BUILDKIT: 1
run: |
docker build --build-arg VERSION=ci --tag transmission-telegram:ci .
test "$(docker image inspect --format '{{.Config.User}}' transmission-telegram:ci)" = "1000:1000"
test "$(docker image inspect --format '{{index .Config.Labels "org.opencontainers.image.version"}}' transmission-telegram:ci)" = "ci"
startup_output="$(docker run --rm transmission-telegram:ci 2>&1 || true)"
grep -F "telegram bot token is required" <<< "${startup_output}"