Skip to content

make sure docker build always runs. #165

make sure docker build always runs.

make sure docker build always runs. #165

Workflow file for this run

name: CI
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
# This workflow is triggered on pushes & pull requests
on:
pull_request:
branches:
- main
push:
branches: [ main ]
release:
types: [published]
jobs:
test:
name: Test
runs-on: ubuntu-latest
container: ghcr.io/packagrio/packagr:latest-golang
env:
STATIC: true
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Test
run: |
go install github.com/golang/mock/mockgen@v1.6.0
go generate ./...
go test -coverprofile=coverage.txt -covermode=atomic -v ./...
- name: Archive coverage
uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: coverage
path: ${{ github.workspace }}/coverage.txt
retention-days: 1
- name: Upload coverage report
uses: codecov/codecov-action@v2
if: success() || failure()
with:
files: ${{ github.workspace }}/coverage.txt
flags: unittests
fail_ci_if_error: true
verbose: true
docker:
if: always()
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
flavor: |
# only latest if push has a tag and we're building the "main" flavor
latest=${{ github.event_name == 'release' && github.ref_type == 'tag' }}
tags: |
# if this is a tag'd build, prefix it with the flavor (eg. main-v1.2.3 and sandbox-v1.2.3)
type=ref,event=tag
# if this is a main branch build, just tag it with the flavor (eg. main and sandbox)
type=raw,value=${{ github.ref_name }},enable=${{ github.ref_name == 'main' }}
# if this is a (non main) branch build, tag it with the flavor and branch name (eg. main-branch and sandbox-branch)
type=ref,event=branch,enable=${{ github.ref_name != 'main' }}
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
platforms: linux/amd64,linux/arm64
context: .
file: Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}