Skip to content

sec: fix error management #1062

sec: fix error management

sec: fix error management #1062

Workflow file for this run

name: Test and build
on:
pull_request:
types: [opened]
push:
jobs:
tests:
name: Test
strategy:
matrix:
go_version: ['1.20']
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Use golang ${{ matrix.go_version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go_version }}
- name: Go version
run: go version
- name: Go get dependencies
run: go get -v -t -d ./...
- name: Run tests
run: make coverage
- name: Send the coverage output
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
test-latest:
name: Test latest
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Use golang ${{ matrix.go_version }}
uses: actions/setup-go@v4
with:
check-latest: true
- name: Go version
run: go version
- name: Go get dependencies
run: go get -v -t -d ./...
- name: Run tests
run: make coverage
- name: Send the coverage output
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: coverage.out
bench:
name: Benchmark
runs-on: ${{ matrix.os }}
strategy:
matrix:
go_version: ['1.20']
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go_version }}
- name: Run benchmark
run: make bench | tee output.txt
- name: Download previous benchmark data
uses: actions/cache/restore@v3
with:
path: ./cache
key: ${{ runner.os }}-benchmark
- name: Store benchmark result
uses: benchmark-action/github-action-benchmark@v1
with:
tool: 'go'
output-file-path: ./output.txt
external-data-json-path: ./cache/benchmark-data.json
comment-on-alert: false
fail-on-alert: true
# only execute this step when cache was restored
# do not fail hard here, as the key might not exist
- name: Clear cache
shell: bash
if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
env:
GH_TOKEN: ${{ github.token }}
run: |
gh extension install actions/gh-actions-cache
gh actions-cache delete '${{ runner.os }}-benchmark' --confirm
continue-on-error: true
- name: Update benchmark data
if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
uses: actions/cache/save@v3
with:
path: ./cache
key: ${{ runner.os }}-benchmark
build:
name: Build docker image
needs: tests
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') || github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/rond-authz/rond
docker.io/rondauthz/rond
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
labels: |
org.opencontainers.image.documentation=https://rond-authz.io
org.opencontainers.image.vendor=rond authz
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Docker Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.BOT_DOCKER_USERNAME }}
password: ${{ secrets.BOT_DOCKER_TOKEN }}
- name: Prepare build cache
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: |
BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}