Skip to content

Lab06

Lab06 #15

Workflow file for this run

name: go-ci
on:
push:
branches: [ "main", "master", "lab*" ]
paths:
- "app_go/**"
- ".github/workflows/go-ci.yml"
pull_request:
paths:
- "app_go/**"
- ".github/workflows/go-ci.yml"
concurrency:
group: go-ci-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: app_go
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: app_go/go.mod
cache: true
cache-dependency-path: app_go/go.sum
- name: fmt check (print files)
run: |
echo "Go version:"
go version
files="$(gofmt -l .)"
if [ -n "$files" ]; then
echo "::error::gofmt wants to reformat these files:"
echo "$files"
exit 1
fi
- name: vet
run: go vet ./...
- name: test + coverage
run: go test ./... -coverprofile=coverage.out
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
files: app_go/coverage.out
flags: app_go
# Docker push if tests passed
docker:
needs: [test]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/lab'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
id: buildx
- name: Set tags
run: |
echo "CALVER=$(date -u +'%Y.%m.%d')" >> $GITHUB_ENV
echo "SHA_SHORT=${GITHUB_SHA::7}" >> $GITHUB_ENV
- uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- uses: docker/build-push-action@v6
with:
context: ./app_go
push: true
builder: ${{ steps.buildx.outputs.name }}
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
${{ secrets.DOCKER_USERNAME }}/app-go:${{ env.CALVER }}
${{ secrets.DOCKER_USERNAME }}/app-go:sha-${{ env.SHA_SHORT }}
${{ secrets.DOCKER_USERNAME }}/app-go:latest