Repository navigation
143 lines (119 loc) · 4.26 KB
/
Copy pathtest.yml
File metadata and controls
143 lines (119 loc) · 4.26 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
name: Test
on:
workflow_dispatch:
push:
branches: [main]
pull_request:
branches: [main]
# Cancel testing of a previous commit for the same branch.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
main:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- uses: jdx/mise-action@v5
- run: git reset --hard # Work around https://github.com/jdx/mise/discussions/8270.
- uses: powerman/.github/.github/actions/cache-go-and-tools@main
- run: mise run ci
# mise runs tasks on Windows by cmd, so tasks which run scripts have own commands there.
# Some tools of mise.toml may be unavailable on Windows,
# so only tools needed to build and test Go scripts are installed.
windows:
runs-on: windows-latest
timeout-minutes: 10
env:
MISE_AUTO_INSTALL: false # Do not install other tools of mise.toml on `mise run`.
steps:
- uses: actions/checkout@v7
- uses: jdx/mise-action@v5
with:
install_args: go gotestsum usage
- run: git reset --hard # Work around https://github.com/jdx/mise/discussions/8270.
- uses: powerman/.github/.github/actions/cache-go-and-tools@main
- run: mise run scripts:test
- run: mise run lint:docs
# Testing on available native platforms.
# Go scripts don't need mise: they are built and run by Go alone.
native:
strategy:
matrix:
include:
- {os: ubuntu-24.04-arm} # Linux ARM64
- {os: macos-15-intel} # macOS AMD64
- {os: macos-latest} # macOS ARM64
- {os: windows-11-arm} # Windows ARM64
runs-on: ${{ matrix.os }}
timeout-minutes: 10
env:
SCRIPTS_BIN: ${{ github.workspace }}/.cache/scripts
KONGUSAGE_TEST_SKIP_USAGE: 1 # Tool usage of mise.toml is not installed here.
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v7
- uses: actions/setup-go@v7
with:
go-version-file: 'scripts/go.mod'
cache-dependency-path: 'scripts/go.sum'
- run: go -C scripts test -timeout=60s -race ./...
if: matrix.os != 'windows-11-arm'
- run: go -C scripts test -timeout=60s ./...
if: matrix.os == 'windows-11-arm'
- run: go -C scripts build -o "$SCRIPTS_BIN/" ./...
- run: '"$SCRIPTS_BIN/lint-docs"'
# Testing on available docker QEMU platforms (Linux only).
qemu:
strategy:
matrix:
include:
- {arch: arm, v: v7}
- {arch: ppc64le}
- {arch: s390x}
- {arch: riscv64}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
with:
platforms: ${{ matrix.arch }}
- uses: powerman/.github/.github/actions/cache-go-and-tools@main
with:
key: qemu-${{ matrix.arch }}${{ matrix.v && format('-{0}', matrix.v) || '' }}
- name: Run tests
env:
PLATFORM: linux/${{ matrix.arch }}${{ matrix.v && format('/{0}', matrix.v) || '' }}
run: |
mkdir -p ~/go ~/.cache/go-build
V=$(awk '$1=="toolchain"{v=$2}$1=="go"&&!v{v=$2}END{sub(/^go/,"",v);print v}' scripts/go.mod)
docker run --rm --platform "$PLATFORM" \
-w /workspace \
-v "$PWD:/workspace" \
-v "$HOME/.cache/go-build:/root/.cache/go-build" \
-v "$HOME/go:/go" \
-e KONGUSAGE_TEST_SKIP_USAGE=1 \
-e SCRIPTS_BIN=/workspace/.cache/scripts \
"golang:${V}-alpine" sh -e -c '
apk add --no-cache git >/dev/null
git config --global --add safe.directory /workspace
go -C scripts test -timeout=60s ./...
go -C scripts build -o "$SCRIPTS_BIN/" ./...
"$SCRIPTS_BIN/lint-docs"
'
# Aggregate job for branch protection.
test:
needs: [main, windows, native, qemu]
runs-on: ubuntu-latest
if: always()
steps:
- name: Fail if any dependency failed, cancelled or skipped
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped')
run: exit 1