Skip to content

Instantly share code, notes, and snippets.

@tonyhb
Last active February 19, 2021 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyhb/b69fc4b1ae6ece3a560781a20f64a8f7 to your computer and use it in GitHub Desktop.
Save tonyhb/b69fc4b1ae6ece3a560781a20f64a8f7 to your computer and use it in GitHub Desktop.
Randomize go package specs on github actions
name: Build & Test
on:
push:
branches: [ develop, master ]
pull_request:
branches: [ develop, master ]
jobs:
test-golang:
runs-on: "..."
container: golang:1.15-buster
env:
N: 8
strategy:
fail-fast: false
matrix:
# Use the matrix to split tests into 8 parallel executions.
parallel: [ 0, 1, 2, 3, 4, 5, 6, 7 ]
steps:
- uses: actions/checkout@v2
- name: Run unit tests
run: |
# List all packages we need to test, using the checksum as randomizer.
echo "$HASH" > .seed
go list -f '{{ if len .TestGoFiles }} {{ .Dir }} {{end}}' ./... | shuf --random-source=.seed > .files
# Calculate how many lines we need to split over our 8 matrixes.
LINES=$(wc -l < .files)
PER_SPLIT=$((($LINES + $N - 1) / $N))
split --lines=$PER_SPLIT -x .files
go test $(cat ./x0${{ matrix.parallel}})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment