-
Notifications
You must be signed in to change notification settings - Fork 20
129 lines (115 loc) · 3.51 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
name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ '*' ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GOLANGCI_LINT_VERSION: v1.62.0
GOTESTSUM_FORMAT: github-actions
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
name: Check out repository
- uses: actions/setup-go@v5
name: Set up Go
with:
go-version-file: go.mod
- uses: golangci/golangci-lint-action@v6
name: Install golangci-lint
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
args: --help
- run: make lint
name: Lint
test:
runs-on: ${{ matrix.os }}
name: Test (${{ matrix.os}}, Git ${{ matrix.git-version }})
strategy:
matrix:
os: ["ubuntu-latest", "windows-latest"]
git-version: ["system"]
include:
# On Linux, also test against specific versions built from source.
- {os: ubuntu-latest, git-version: "2.38.0"}
# On Windows, run without coverage.
- {os: windows-latest, no-cover: true}
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
# TODO: extract into separate action
- name: Determine Git cache directory
shell: bash
if: matrix.git-version != 'system'
run: |
echo "GIT_VERSION=$GIT_VERSION" >> "$GITHUB_ENV"
echo "GIT_CACHE_DIR=$HOME/.cache/git/$GIT_VERSION" >> "$GITHUB_ENV"
env:
GIT_VERSION: ${{ matrix.git-version }}
- name: Fill Git cache
if: matrix.git-version != 'system'
uses: actions/cache@v4
with:
path: ${{ env.GIT_CACHE_DIR }}
key: ${{ runner.os }}-git-${{ matrix.git-version }}
- name: Install Git
shell: bash
if: matrix.git-version != 'system'
run: |
if [[ ! -x "$GIT_CACHE_DIR/bin/git" ]]; then
URL=https://mirrors.edge.kernel.org/pub/software/scm/git/git-${GIT_VERSION}.tar.gz
echo "Downloading Git $GIT_VERSION from $URL"
sudo apt-get install \
dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext \
libz-dev libssl-dev
GIT_SRC_DIR=$(mktemp -d)
( mkdir -p "$GIT_SRC_DIR" &&
cd "$GIT_SRC_DIR" &&
(curl -sSL "$URL" | tar -xz --strip-components=1) &&
make prefix="$GIT_CACHE_DIR" &&
make prefix="$GIT_CACHE_DIR" install )
fi
if [[ ! -x "$GIT_CACHE_DIR/bin/git" ]]; then
echo "Failed to build Git $GIT_VERSION"
exit 1
fi
echo "$GIT_CACHE_DIR/bin" >> "$GITHUB_PATH"
- name: Report Git version
shell: bash
run:
git --version
- name: Test
run: make ${{ (matrix.no-cover == true) && 'test' || 'cover' }}
shell: bash
- name: Upload coverage
uses: codecov/[email protected]
if: ${{ matrix.no-cover != true }}
with:
files: ./cover.out
token: ${{ secrets.CODECOV_TOKEN }}
# Depends on lint and test.
# Stable name for branch protection to require
# instead of adding lint and test there directly.
ok:
name: OK
runs-on: ubuntu-latest
needs: [lint, test]
# Workaround for GitHub marking this job as skipped,
# and allowing a bad PR to merge anyway.
if: always()
steps:
- run: exit 1
if: >-
needs.lint.result != 'success' ||
needs.test.result != 'success'
- run: exit 0