Skip to content

test: improve storage package coverage to 88.5% (#77) #126

test: improve storage package coverage to 88.5% (#77)

test: improve storage package coverage to 88.5% (#77) #126

Workflow file for this run

name: CI
on:
push:
branches:
- main
tags:
- "v*.*.*"
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
permissions: write-all
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
env:
REGISTRY: ghcr.io
jobs:
test:
runs-on: ubuntu-latest
if: github.event_name != 'pull_request' || (!github.event.pull_request.draft && !contains(github.event.pull_request.title, 'WIP'))
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
cache: true
- name: Run tests
run: go test -coverprofile=cover.out ./...
- name: Build
run: go build -o ocap-webserver ./cmd/ocap-webserver
- name: Archive code coverage results
uses: actions/upload-artifact@v6
with:
name: code-coverage
path: cover.out
- name: Download artifact (main.breakdown)
id: download-main-breakdown
uses: dawidd6/action-download-artifact@v12
if: github.event_name == 'pull_request'
with:
branch: main
workflow_conclusion: success
name: main.breakdown
if_no_artifact_found: warn
- name: Check test coverage
id: coverage
uses: vladopajic/go-test-coverage/action/source@v2
with:
profile: cover.out
git-token: ${{ github.ref_name == 'main' && secrets.GITHUB_TOKEN || '' }}
git-branch: badges
breakdown-file-name: ${{ github.ref_name == 'main' && 'main.breakdown' || '' }}
diff-base-breakdown-file-name: ${{ steps.download-main-breakdown.outputs.found_artifact == 'true' && 'main.breakdown' || '' }}
- name: Upload artifact (main.breakdown)
uses: actions/upload-artifact@v6
if: github.ref_name == 'main'
with:
name: main.breakdown
path: main.breakdown
if-no-files-found: error
code_coverage:
name: "Code coverage report"
if: github.event_name == 'pull_request' && !github.event.pull_request.draft
runs-on: ubuntu-latest
needs: test
permissions:
contents: read
actions: read
pull-requests: write
steps:
- uses: fgrosse/[email protected]
with:
coverage-artifact-name: "code-coverage"
coverage-file-name: "cover.out"
docker-build-and-push-image:
runs-on: ubuntu-latest
if: github.event_name == 'push'
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- name: Docker meta
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/ocap2/web
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Log in to the Container registry
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
push: true
build-args: |
build_commit=${{ github.sha }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
windows-build:
runs-on: ubuntu-latest
if: github.event_name == 'push'
permissions:
contents: read
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- name: Install cross compile dependencies
run: sudo apt-get install -y gcc-mingw-w64 gcc-multilib
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5
with:
go-version-file: 'go.mod'
- name: Build windows binary
run: CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ GOOS=windows GOARCH=amd64 go build -ldflags "-X github.com/OCAP2/web/internal/server.BuildDate=`date -u +'%Y-%m-%dT%H:%M:%SZ'` -X github.com/OCAP2/web/internal/server.BuildCommit=$GITHUB_SHA" -o ocap-webserver.exe ./cmd/ocap-webserver
- name: Upload windows binary
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f
with:
name: webserver
path: ocap-webserver.exe