fix: set environment for workflow #5
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
name: CI-workflow | |
on: | |
push: | |
branches: ["main"] | |
tags: ["v*.*.*"] | |
env: | |
REGISTRY: docker.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
run-tests: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
go-version: ["1.23.x"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ matrix.go-version }} | |
- name: Setup go-task | |
run: go install github.com/go-task/task/v3/cmd/task@latest | |
- name: Setup golangci-lint | |
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest | |
- name: Install dependencies | |
run: go mod download | |
- name: Build | |
run: task build | |
- name: Lint with golangci-lint | |
run: golangci-lint run ./... | |
# - name: Test with go | |
# run: go test ./... -json > TestResults-${{ matrix.go-version }}.json | |
# - name: Upload test results | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: go-results-${{ matrix.go-version }} | |
# path: TestResults-${{ matrix.go-version }}.json | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
environment: prod | |
needs: run-tests | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
- name: Log in to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
no-cache: true | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
- name: Update DockerHub Description | |
uses: peter-evans/dockerhub-description@v4 | |
with: | |
username: ${{ github.actor }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
repository: ${{ github.repository }} | |
short-description: ${{ github.event.repository.description }} | |
enable-url-completion: true | |
- name: Generate artifact attestation | |
uses: actions/attest-build-provenance@v2 | |
with: | |
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} | |
subject-digest: ${{ steps.push.outputs.digest }} | |
push-to-registry: true |