Debian Codegraph @

.github/workflows/ci.yml

raw
1 name: ci
2
3 concurrency:
4 group: ${{ github.workflow }}-${{ github.ref }}
5 cancel-in-progress: true
6
7 on:
8 workflow_dispatch:
9 schedule:
10 - cron: '0 8 */6 * *' # every 6 days
11 push:
12 branches:
13 - master
14 pull_request:
15
16 env:
17 DESTDIR: ./bin
18 GO_VERSION: "1.23"
19
20 jobs:
21 validate:
22 runs-on: ubuntu-latest
23 strategy:
24 matrix:
25 target:
26 - lint-golangci-cross
27 - lint-gopls-cross
28 - validate-generated-files
29 - validate-gomod
30 - validate-shfmt
31 steps:
32 -
33 name: Set up Docker Buildx
34 uses: docker/setup-buildx-action@v3
35 -
36 name: Run
37 uses: docker/bake-action@v6
38 with:
39 targets: ${{ matrix.target }}
40
41 build:
42 runs-on: ubuntu-latest
43 strategy:
44 matrix:
45 target:
46 - build
47 - cross
48 steps:
49 -
50 name: Set up Docker Buildx
51 uses: docker/setup-buildx-action@v3
52 -
53 name: Run
54 uses: docker/bake-action@v6
55 with:
56 targets: ${{ matrix.target }}
57
58 test:
59 runs-on: ubuntu-latest
60 strategy:
61 matrix:
62 go:
63 - "1.23"
64 - "1.22"
65 - "1.21"
66 mode:
67 - "root"
68 - "noroot"
69 env:
70 GO_VERSION: ${{ matrix.go }}
71 steps:
72 -
73 name: Set up Docker Buildx
74 uses: docker/setup-buildx-action@v3
75 -
76 name: Test
77 uses: docker/bake-action@v6
78 with:
79 targets: test-${{ matrix.mode }}
80 -
81 name: Upload coverage
82 uses: codecov/codecov-action@v5
83 with:
84 directory: ${{ env.DESTDIR }}/coverage
85 flags: unit,${{ matrix.mode }},go-${{ matrix.go }}
86 token: ${{ secrets.CODECOV_TOKEN }}
87
88 test-os:
89 runs-on: ${{ matrix.os }}
90 strategy:
91 fail-fast: false
92 matrix:
93 os:
94 - macos-latest
95 - windows-latest
96 go:
97 - "1.23"
98 - "1.22"
99 - "1.21"
100 steps:
101 -
102 name: Checkout
103 uses: actions/checkout@v4
104 -
105 name: Set up Go
106 uses: actions/setup-go@v5
107 with:
108 go-version: ${{ matrix.go }}
109 -
110 name: Test
111 run: |
112 go test -coverprofile="coverage.txt" -covermode="atomic" ./...
113 go tool cover -func="coverage.txt"
114 -
115 name: Upload coverage
116 if: always()
117 uses: codecov/codecov-action@v5
118 with:
119 files: ./coverage.txt
120 env_vars: RUNNER_OS
121 flags: unit,go-${{ matrix.go }}
122 token: ${{ secrets.CODECOV_TOKEN }}
123
124 test-bsd-amd64:
125 runs-on: ubuntu-22.04
126 strategy:
127 fail-fast: false
128 matrix:
129 os:
130 - freebsd
131 - netbsd
132 - openbsd
133 steps:
134 -
135 name: Prepare
136 run: |
137 echo "VAGRANT_FILE=hack/Vagrantfile.${{ matrix.os }}" >> $GITHUB_ENV
138
139 # Sets semver Go version to be able to download tarball during vagrant setup
140 goVersion=$(curl --silent "https://go.dev/dl/?mode=json&include=all" | jq -r '.[].files[].version' | uniq | sed -e 's/go//' | sort -V | grep $GO_VERSION | tail -1)
141 echo "GO_VERSION=$goVersion" >> $GITHUB_ENV
142 -
143 name: Checkout
144 uses: actions/checkout@v4
145 -
146 name: Cache Vagrant boxes
147 uses: actions/cache@v4
148 with:
149 path: ~/.vagrant.d/boxes
150 key: ${{ runner.os }}-vagrant-${{ matrix.os }}-${{ hashFiles(env.VAGRANT_FILE) }}
151 restore-keys: |
152 ${{ runner.os }}-vagrant-${{ matrix.os }}-
153 -
154 name: Install vagrant
155 run: |
156 set -x
157 wget -O - https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
158 echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
159 sudo apt-get update
160 sudo apt-get install -y libvirt-dev libvirt-daemon libvirt-daemon-system vagrant vagrant-libvirt ruby-libvirt
161 sudo systemctl enable --now libvirtd
162 sudo chmod a+rw /var/run/libvirt/libvirt-sock
163 vagrant plugin install vagrant-libvirt
164 vagrant --version
165 -
166 name: Set up vagrant
167 run: |
168 ln -sf ${{ env.VAGRANT_FILE }} Vagrantfile
169 vagrant up --no-tty
170 -
171 name: Test
172 uses: nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3.0.2
173 with:
174 timeout_minutes: 20
175 max_attempts: 5
176 command: |
177 vagrant ssh -- "cd /vagrant; go test -buildvcs=false -coverprofile=coverage.txt -covermode=atomic ./..."
178 vagrant ssh -c "sudo cat /vagrant/coverage.txt" > coverage.txt
179 -
180 name: Upload coverage
181 if: always()
182 uses: codecov/codecov-action@v5
183 with:
184 files: ./coverage.txt
185 flags: unit,${{ matrix.os }}
186 token: ${{ secrets.CODECOV_TOKEN }}