54 lines
1.5 KiB
YAML
54 lines
1.5 KiB
YAML
on:
|
|
push:
|
|
pull_request:
|
|
|
|
env:
|
|
SHARE_DIR: /ci-share/${{ github.run_id }}-${{ github.run_attempt }}
|
|
GO_CACHE_DIR: /ci-share/cache/${{ github.repository }}
|
|
GOMODCACHE: /ci-share/cache/${{ github.repository }}/go-mod
|
|
GOCACHE: /ci-share/cache/${{ github.repository }}/go-build
|
|
|
|
jobs:
|
|
resolve-go:
|
|
runs-on: selfhosted
|
|
container:
|
|
options: -v tmp:/ci-share
|
|
outputs:
|
|
version: ${{ steps.goversion.outputs.version }}
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
|
|
- name: Read Go version from go.mod
|
|
id: goversion
|
|
run: echo "version=$(awk '/^go / {print $2; exit}' go.mod)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Prepare Go module cache
|
|
run: mkdir -p "$GO_CACHE_DIR" "$GOMODCACHE" "$GOCACHE"
|
|
|
|
- name: Stage repository for test job
|
|
run: |
|
|
rm -rf "$SHARE_DIR"
|
|
mkdir -p "$SHARE_DIR"
|
|
cp -a "${GITHUB_WORKSPACE}/." "$SHARE_DIR/"
|
|
|
|
test:
|
|
needs: resolve-go
|
|
runs-on: selfhosted
|
|
container:
|
|
image: golang:${{ needs.resolve-go.outputs.version }}
|
|
options: -v tmp:/ci-share
|
|
steps:
|
|
- name: Run tests
|
|
working-directory: ${{ env.SHARE_DIR }}
|
|
run: go test -v ./...
|
|
|
|
cleanup:
|
|
needs: [resolve-go, test]
|
|
if: always()
|
|
runs-on: selfhosted
|
|
container:
|
|
options: -v tmp:/ci-share
|
|
steps:
|
|
- name: Remove shared repository
|
|
run: rm -rf "$SHARE_DIR"
|