ci: split go build job to improve runtime #1809
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copyright (c) 2024 Hemi Labs, Inc. | |
# Use of this source code is governed by the MIT License, | |
# which can be found in the LICENSE file. | |
# GitHub Actions workflow to lint, build and test. | |
name: "Go" | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
workflow_dispatch: | |
workflow_call: | |
concurrency: | |
group: "go-${{ github.workflow }}-${{ github.event.number || github.ref }}" | |
cancel-in-progress: "${{ github.event_name == 'pull_request' }}" | |
env: | |
GO_VERSION: "1.23.x" | |
permissions: | |
contents: read | |
jobs: | |
lint: | |
name: "Lint" | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Checkout repository" | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
fetch-depth: 0 | |
- name: "Setup Go ${{ matrix.go-version }}" | |
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | |
with: | |
go-version: "${{ env.GO_VERSION }}" | |
cache: true | |
- name: "golangci-lint" | |
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1 | |
with: | |
version: "v1.62" | |
build: | |
name: "Build" | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Checkout repository" | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: "Setup Go ${{ matrix.go-version }}" | |
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | |
with: | |
go-version: "${{ env.GO_VERSION }}" | |
cache: true | |
check-latest: true | |
- name: "Download and verify dependencies" | |
id: deps | |
run: make GOCACHE="$(go env GOCACHE)" go-deps | |
- name: "make build" | |
run: make GOCACHE="$(go env GOCACHE)" build | |
test: | |
name: "Test" | |
runs-on: "ubuntu-latest" | |
services: | |
postgres: | |
image: postgres:16.3-alpine3.20 | |
ports: | |
- 5432:5432 | |
env: | |
POSTGRES_PASSWORD: "postgres" | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- name: "Checkout repository" | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: "Setup Go ${{ matrix.go-version }}" | |
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | |
with: | |
go-version: "${{ env.GO_VERSION }}" | |
cache: true | |
check-latest: true | |
- name: "Download and verify dependencies" | |
id: deps | |
run: make GOCACHE="$(go env GOCACHE)" go-deps | |
- name: "make test (with E2E tests)" | |
env: | |
PGTESTURI: "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable" | |
HEMI_DOCKER_TESTS: "1" | |
run: make GOCACHE="$(go env GOCACHE)" test | |
test-race: | |
name: "Test (race)" | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Checkout repository" | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: "Setup Go ${{ matrix.go-version }}" | |
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | |
with: | |
go-version: "${{ env.GO_VERSION }}" | |
cache: true | |
check-latest: true | |
- name: "Download and verify dependencies" | |
id: deps | |
run: make GOCACHE="$(go env GOCACHE)" go-deps | |
- name: "make race" | |
run: make GOCACHE="$(go env GOCACHE)" race |