Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

[sc-102926]: add basic code coverage support (#72) #128

[sc-102926]: add basic code coverage support (#72)

[sc-102926]: add basic code coverage support (#72) #128

Workflow file for this run

name: CI
on:
push:
branches: [main]
tags:
- "v*"
pull_request:
workflow_dispatch:
jobs:
build:
name: Build and test
permissions:
contents: write
packages: read
runs-on: ubuntu-latest
env:
goreleaser-flags: ""
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# required for goreleaser to work properly.
fetch-depth: 0
- run: git fetch --force --tags
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Install cmetrics library
run: |
curl -L https://github.com/fluent/cmetrics/releases/download/${CMETRICS_RELEASE}/cmetrics_${CMETRICS_VERSION}_${ARCH}-headers.deb --output cmetrics_${CMETRICS_VERSION}_${ARCH}-headers.deb
curl -L https://github.com/fluent/cmetrics/releases/download/${CMETRICS_RELEASE}/cmetrics_${CMETRICS_VERSION}_${ARCH}.deb --output cmetrics_${CMETRICS_VERSION}_${ARCH}.deb
sudo dpkg -i *.deb
env:
CMETRICS_VERSION: "0.9.1"
CMETRICS_RELEASE: "v0.9.1"
ARCH: "amd64"
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "^1.22"
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Unit tests
run: go test -v -covermode=atomic -coverprofile=coverage.out ./...
shell: bash
- name: Install Syft for sboms
run: curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
shell: bash
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.CALYPTIA_GPG_KEY }}
passphrase: ${{ secrets.CALYPTIA_GPG_KEY_PASSPHRASE }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build artefacts on top of cross compile image.
run: |
make build-amd64
sudo rm -rf go
make build-arm64
shell: bash
env:
GORELEASER_IMAGE: ghcr.io/chronosphereio/calyptia-core-fluent-bit-template/goreleaser-cross:latest
GORELEASER_SNAPSHOT: ${{ github.event_name == 'pull_request' }}
# Note snapshot removal in v4: https://github.com/caarlos0/goreleaser-action-v4-auto-snapshot-example
- name: Set up snapshot build
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
run: echo "goreleaser-flags=--snapshot" >> $GITHUB_ENV
- name: Set up PR build
if: ${{ github.event_name == 'pull_request' }}
run: echo "goreleaser-flags=--skip=publish,sign,sbom --snapshot" >> $GITHUB_ENV
- name: Run GoReleaser with flags
uses: goreleaser/goreleaser-action@v6
with:
version: latest
distribution: goreleaser-pro
args: release --skip=validate --clean ${{ env.goreleaser-flags }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GORELEASER_KEY: ${{ secrets.GORELEASER_PRO_KEY }}