Skip to content

Go

Go #84

Workflow file for this run

---
name: Go
on:
pull_request:
types:
- unlabeled # if GitHub Actions stuck, add and remove "not ready" label to force rebuild
- opened
- reopened
- synchronize
push:
branches:
- main
schedule:
- cron: "12 0 * * *"
# Do not run this workflow in parallel for any PR change.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: false
env:
GOPATH: /home/runner/go
GOCACHE: /home/runner/go/cache
GOLANGCI_LINT_CACHE: /home/runner/go/cache/lint
GOMODCACHE: /home/runner/go/mod
GOPROXY: https://proxy.golang.org
jobs:
short-test:
name: Short test
runs-on: ubuntu-22.04
timeout-minutes: 10
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # for `git describe` to work
lfs: false # LFS is used only by website
- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
cache-key: short-test
- name: Install Task
run: go generate -x
working-directory: tools
- name: Run init
run: bin/task init
- name: Run short unit tests
run: bin/task test-unit-short
# we don't want them on CI
- name: Clean test and fuzz caches
if: always()
run: go clean -testcache -fuzzcache
- name: Check dirty
run: |
git status
git diff --exit-code
test:
name: Test
runs-on: ubuntu-22.04
timeout-minutes: 10
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # for `git describe` to work
lfs: false # LFS is used only by website
- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
cache-key: test
- name: Install Task
run: go generate -x
working-directory: tools
- name: Start environment
run: bin/task env-up-detach
- name: Run init
run: bin/task init
- name: Regenerate and reformat
run: bin/task gen
- name: Build bin/ferretdb
run: bin/task build-host
- name: Wait for and setup environment
run: bin/task env-setup
- name: Run unit tests
run: bin/task test-unit
# The token is not required but should make uploads more stable.
# If secrets are unavailable (for example, for a pull request from a fork), it fallbacks to the tokenless uploads.
#
# Unfortunately, it seems that tokenless uploads fail too often.
# See https://github.com/codecov/codecov-action/issues/837.
#
# We also can't use ${{ vars.CODECOV_TOKEN }}: https://github.com/orgs/community/discussions/44322
- name: Upload coverage information to codecov
uses: codecov/codecov-action@v3
with:
token: 22159d7c-856d-4fe9-8fdb-5d9ecff35514
files: ./cover.txt
flags: unit
fail_ci_if_error: true
verbose: true
- name: Upload coverage information to coveralls
uses: coverallsapp/github-action@v2
with:
file: ./cover.txt
flag-name: unit
# we don't want them on CI
- name: Clean test and fuzz caches
if: always()
run: go clean -testcache -fuzzcache
- name: Check dirty
run: |
git status
git diff --exit-code
golangci-lint:
name: golangci-lint
runs-on: ubuntu-22.04
timeout-minutes: 10
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # for `golangci-lint run --new` to work
lfs: false # LFS is used only by website
- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
cache-key: lint
- name: Run linters
uses: FerretDB/github-actions/linters@main
fuzz-short:
name: Fuzz short
runs-on: ubuntu-22.04
timeout-minutes: 10
if: github.event_name != 'pull_request' || !contains(github.event.pull_request.labels.*.name, 'not ready')
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
path: source
fetch-depth: 0 # for `git describe` to work
lfs: false # LFS is used only by website
- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
cache-key: fuzz
- name: Install Task
run: go generate -x
working-directory: source/tools
# Use deploy key instead of Personal Access Token (PAT) to limit access to one repository.
# If secrets are not available (for example, for a pull request from a fork), GITHUB_TOKEN PAT is used automatically.
- name: Checkout collected fuzz corpus
uses: actions/checkout@v3
with:
repository: FerretDB/fuzz-corpus
ssh-key: ${{ secrets.FUZZ_CORPUS_DEPLOY_KEY }}
path: fuzz-corpus
fetch-depth: 0 # for commit and push to work
- name: Start environment
run: bin/task env-up-detach
working-directory: source
- name: Run init
run: bin/task init
working-directory: source
- name: Setup corpus
run: bin/task fuzz-corpus
working-directory: source
- name: Wait for and setup environment
run: bin/task env-setup
working-directory: source
# precompile tests with unset GOMAXPROCS
- name: Init fuzzers
run: bin/task fuzz-init
working-directory: source
# TODO https://github.com/FerretDB/FerretDB/issues/238
# TODO https://github.com/FerretDB/FerretDB/issues/344
- name: Run collected fuzzing corpus
run: bin/task fuzz FUZZTIME=1s
working-directory: source
env:
GOMAXPROCS: 1 # otherwise, oom-killer kills fuzzer too often
- name: Collect corpus
if: always()
run: |
bin/task fuzz-corpus
go run ./cmd/fuzztool corpus seed ../fuzz-corpus
working-directory: source
# `secrets` are not supported in `if`, so we have to do this trick with environment variable:
# https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability
# https://github.com/actions/runner/issues/520
- name: Push corpus
if: ${{ always() && env.KEY != '' }}
env:
KEY: ${{ secrets.FUZZ_CORPUS_DEPLOY_KEY }}
run: |
git config user.name ferretdb-bot
git config user.email ferretdb-bot@ferretdb.io
git add --all .
git diff-index --quiet HEAD || git commit --message 'Update corpus'
git fetch
git rebase origin/main
git push
working-directory: fuzz-corpus
- name: Collect Linux logs
if: failure()
run: |
mkdir -p /tmp/logs
ls -al /var/log/
sudo cp /var/log/syslog /tmp/logs/
sudo free > /tmp/logs/free.txt
sudo chmod 0666 /tmp/logs/*
working-directory: source
- name: Compress Linux logs before upload
if: failure()
run: zip -r -q -9 linux-logs.zip /tmp/logs
- name: Upload Linux logs
if: failure()
uses: actions/upload-artifact@v3
with:
name: linux-logs
path: linux-logs.zip
retention-days: 1
if-no-files-found: error
# we don't want them on CI
- name: Clean test and fuzz caches
if: always()
run: go clean -testcache -fuzzcache
- name: Check dirty
run: |
git status
git diff --exit-code
working-directory: source