diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 81cabe5..62a4884 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,15 +1,21 @@ name: Go -on: [push, pull_request] +on: + push: + branches: + - master + - feat-* + - ci + tags: + - v* + +env: + GO_VERSION: "1.22" + GHCR_REGISTRY_IMAGE: ghcr.io/${{ github.repository }} jobs: lint: runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - go-version: ["1.21", "1.22"] - name: Lint ${{ matrix.go-version == '1.22' && '(latest)' || '(old)' }} steps: - uses: actions/checkout@v4 @@ -17,12 +23,9 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: ${{ matrix.go-version }} + go-version: ${{ env.GO_VERSION }} cache: true - - name: Install libolm - run: sudo apt-get install libolm-dev libolm3 - - name: Install goimports run: | go install golang.org/x/tools/cmd/goimports@latest @@ -34,5 +37,62 @@ jobs: - name: Lint run: pre-commit run -a - - name: Build - run: go build + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ${{ env.GO_VERSION }} + cache: true + + - name: Install libolm + run: sudo apt-get install libolm-dev libolm3 + + - name: Set up gotestfmt + uses: GoTestTools/gotestfmt-action@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Run tests + run: | + go test -v -json ./... -cover | gotestfmt + + + build-docker: + runs-on: ubuntu-latest + steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to docker registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Docker metadata + uses: docker/metadata-action@v5 + id: meta + with: + images: ${{ env.GHCR_REGISTRY_IMAGE }} + tags: | + type=ref,event=branch + type=ref,event=tag + type=sha,format=long + type=raw,latest + + - name: Docker Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: Dockerfile.ci + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=${{ env.GHCR_REGISTRY_IMAGE }}:latest + cache-to: type=inline