update go 1.21 #8
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
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
name: Test, Build and Save | |
jobs: | |
check_skip_flags: | |
runs-on: ubuntu-latest | |
outputs: | |
head-commit-message: ${{ steps.get_head_commit_message.outputs.HEAD_COMMIT_MSG }} | |
steps: | |
- name: Get repo | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Print head git commit message | |
id: get_head_commit_message | |
run: echo "HEAD_COMMIT_MSG=$(git show -s --format=%s)" >> $GITHUB_OUTPUT | |
test: | |
needs: [check_skip_flags] | |
if: "!contains(needs.check_skip_flags.outputs.head-commit-message, '[skip-test]')" | |
strategy: | |
matrix: | |
go-version: [1.20.x] | |
os: [ubuntu-latest, macos-latest] | |
runs-on: ${{ matrix.os }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Setup | |
uses: actions/setup-go@v4 | |
with: | |
go-version: ${{ matrix.go-version }} | |
- name: Display Go version | |
run: go version | |
- name: Test | |
run: go test -v ./... | |
- name: Get coverage report | |
run: go test -coverprofile=coverage.out ./... | |
- name: Convert coverage report (HTML) | |
run: go tool cover -html=coverage.out -o coverage_go${{ matrix.go-version }}_${{ matrix.os }}.html | |
- name: Archive code coverage | |
uses: actions/upload-artifact@v3 | |
with: | |
name: code-coverage | |
path: ./coverage*.html | |
retention-days: 10 | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
docker: | |
needs: [test] | |
if: "!contains(needs.check_skip_flags.outputs.head-commit-message, '[skip-docker]')" | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Log in to the Container registry | |
uses: docker/[email protected] | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/[email protected] | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=schedule | |
type=ref,event=pr,prefix=${{github.head_ref}}-pr- | |
type=raw,value=latest,enable=${{ endsWith(GitHub.ref, 'main') }} | |
type=semver,pattern={{raw}} | |
type=sha,format=long | |
- name: Build and push Docker image | |
uses: docker/[email protected] | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} |