Skip to content

feat: MVP's out 🚀 #17

feat: MVP's out 🚀

feat: MVP's out 🚀 #17

Workflow file for this run

name: CI
# yamllint disable-line rule:truthy
on:
release:
types: [published]
push:
branches:
- master
tags:
- '*'
paths:
- .github/workflows/integration.yml
- .golangci.yaml
- .goreleaser.yaml
- container-structure-test.yaml
- Dockerfile
- .dockerignore
- go.mod
- go.sum
- '**.go'
pull_request:
branches:
- master
paths:
- .github/workflows/integration.yml
- .golangci.yaml
- .goreleaser.yaml
- container-structure-test.yaml
- Dockerfile
- .dockerignore
- go.mod
- go.sum
- '**.go'
env:
GOLANG_VERSION: "1.20"
GOLANG_FLAGS: -race -mod=readonly
WORK_DIR: /usr/src
jobs:
metadata:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: calculate version
uses: paulhatch/semantic-version@v5.0.3
id: version
with:
branch: HEAD
bump_each_commit: false
change_path: >-
cmd/handler
internal
go.mod
go.sum
major_pattern: /^BREAKING CHANGE:|^[^()!:]+(?:\([^()!:]+\))?!:/
minor_pattern: /^feat(?:\([^()!:]+\))?:/
search_commit_body: true
user_format_type: csv
version_format: ${major}.${minor}.${patch}-rc.${increment}+${current_commit}
- name: generate container meta
id: meta
uses: docker/metadata-action@v4
with:
context: workflow
images: ${{ github.repository }}
flavor: |
latest=true
# yamllint disable rule:line-length
labels: |
org.opencontainers.image.documentation=https://github.com/${{ github.repository }}/blob/master/README.md
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.url=https://hub.docker.com/r/${{ github.repository }}
# yamllint enable rule:line-length
tags: |
type=ref,event=branch
type=ref,event=pr
type=raw,value=${{ env.BRANCH }}
type=semver,pattern={{version}}
github-token: ${{ github.token }}
outputs:
major: ${{ steps.version.outputs.major }}
minor: ${{ steps.version.outputs.minor }}
patch: ${{ steps.version.outputs.patch }}
increment: ${{ steps.version.outputs.increment }}
version_type: ${{ steps.version.outputs.version_type }}
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.version_tag }}
revision: ${{ steps.version.outputs.current_commit }}
authors: ${{ steps.version.outputs.authors }}
container-labels: ${{ steps.meta.outputs.labels }}
container-tags: ${{ steps.meta.outputs.tags }}
build:
runs-on: ubuntu-latest
needs: metadata
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup golang
uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: set golang environment variables
uses: wwmoraes/actions/golang/env@master
- name: cache modules
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${GOMODCACHE}
key: ${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
${{ runner.os }}-modules-
- name: download modules
run: go mod download
- name: cache build
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${GOCACHE}
key: ${{ runner.os }}-build-${{ hashFiles('**/*.go') }}
restore-keys: |
${{ runner.os }}-build-${{ hashFiles('**/*.go') }}
${{ runner.os }}-build-
- name: generate
run: go generate ./...
env:
VERSION: ${{ needs.metadata.outputs.version }}
- name: build
uses: wwmoraes/actions/golang/build@master
lint:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup golang
uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: set golang environment variables
uses: wwmoraes/actions/golang/env@master
- name: cache modules
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${GOMODCACHE}
key: ${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
${{ runner.os }}-modules-
- name: download modules
run: go mod download
- name: cache lint
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${HOME}/.cache/golangci-lint
key: ${{ runner.os }}-lint-${{ hashFiles('.golangci.yaml') }}
restore-keys: |
${{ runner.os }}-lint-${{ hashFiles('.golangci.yaml') }}
${{ runner.os }}-lint-
- name: lint
uses: wwmoraes/actions/golang/lint@master
id: lint
with:
work-dir: ${{ env.WORK_DIR }}
version: v1.46-alpine
- name: upload lint report
uses: actions/upload-artifact@v2
if: always()
with:
name: lint-report
path: ${{ steps.lint.outputs.report-file }}
test:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: setup golang
uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: set golang environment variables
uses: wwmoraes/actions/golang/env@master
- name: cache modules
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${GOMODCACHE}
key: ${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
${{ runner.os }}-modules-
- name: download modules
run: go mod download
- name: cache test
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${GOCACHE}
key: ${{ runner.os }}-test-${{ hashFiles('**/*.go') }}
restore-keys: |
${{ runner.os }}-test-${{ hashFiles('**/*.go') }}
${{ runner.os }}-test-
- name: test
uses: wwmoraes/actions/golang/test@master
id: test
- name: security scan
uses: anchore/scan-action@v3
with:
path: .
fail-build: true
- name: upload coverage report
uses: actions/upload-artifact@v2
if: always()
with:
name: coverage-report
path: ${{ steps.test.outputs.cover-profile }}
- name: upload test report
uses: actions/upload-artifact@v2
if: always()
with:
name: test-report
path: ${{ steps.test.outputs.report-file }}
report:
runs-on: ubuntu-latest
needs: [lint, test]
steps:
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: download lint report
uses: actions/download-artifact@v2
with:
name: lint-report
- name: download test report
uses: actions/download-artifact@v2
with:
name: test-report
- name: download coverage report
uses: actions/download-artifact@v2
with:
name: coverage-report
release:
runs-on: ubuntu-latest
needs: [metadata, build, lint, test]
if: >-
github.event_name == 'push'
&& startsWith(github.ref, 'refs/tags/')
steps:
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: setup golang
uses: actions/setup-go@v3
with:
go-version: ${{ env.GOLANG_VERSION }}
- name: set golang environment variables
uses: wwmoraes/actions/golang/env@master
- name: cache modules
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${GOMODCACHE}
key: ${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
restore-keys: |
${{ runner.os }}-modules-${{ hashFiles('go.sum') }}
${{ runner.os }}-modules-
- name: cache build
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${GOCACHE}
key: ${{ runner.os }}-build-${{ hashFiles('**/*.go') }}
restore-keys: |
${{ runner.os }}-build-${{ hashFiles('**/*.go') }}
${{ runner.os }}-build-
- name: generate
run: go generate ./...
env:
VERSION: ${{ needs.metadata.outputs.version }}
- name: run goreleaser
uses: goreleaser/goreleaser-action@v3
with:
version: ${{ needs.metadata.outputs.version }}
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
runs-on: ubuntu-latest
needs: [metadata, build, lint, test]
env:
# runner context is not available here...
GRYPE_DB_CACHE_TEMP_PATH: .cache/grype/db/
steps:
- name: checkout
uses: actions/checkout@v2
- name: set up QEMU
uses: docker/setup-qemu-action@v2
- name: set up docker buildx
uses: docker/setup-buildx-action@v2
- name: cache buildx
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${{ runner.temp }}/.buildx-cache
# yamllint disable-line rule:line-length
key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile', '.dockerignore') }}
# yamllint disable rule:line-length
restore-keys: |
${{ runner.os }}-buildx-${{ hashFiles('Dockerfile', '.dockerignore') }}
${{ runner.os }}-buildx-
# yamllint enable rule:line-length
- name: build single-arch test image
uses: docker/build-push-action@v3
env:
DOCKER_BUILDKIT: 0
BUILDKIT_INLINE_CACHE: 1
with:
push: false
load: true
labels: ${{ needs.metadata.outputs.container-labels }}
cache-to: |
type=local,mode=max,dest=${{ runner.temp }}/.buildx-cache-new
cache-from: |
type=local,src=${{ runner.temp }}/.buildx-cache
${{ needs.metadata.outputs.container-tags }}
${{ github.repository }}:${{ github.ref_name }}
${{ github.repository }}:test
tags: ${{ github.repository }}:test
build-args: |
GOLANG_VERSION=${{ env.GOLANG_VERSION }}
VERSION=${{ github.ref_name }}
# fix to prevent ever-growing caches
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf ${{ runner.temp }}/.buildx-cache
mv ${{ runner.temp }}/.buildx-cache-new ${{ runner.temp }}/.buildx-cache
- name: test structure
uses: brpaz/structure-tests-action@v1.1.2
with:
image: ${{ github.repository }}:test
configFile: container-structure-test.yaml
- name: cache grype
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${{ runner.temp }}/${{ env.GRYPE_DB_CACHE_TEMP_PATH }}
key: ${{ runner.os }}-grype-${{ hashFiles('.grype.yaml') }}
restore-keys: |
${{ runner.os }}-grype-${{ hashFiles('.grype.yaml') }}
${{ runner.os }}-grype-
- name: grype scan
uses: anchore/scan-action@v3
with:
image: ${{ github.repository }}:test
fail-build: true
publish-docker:
runs-on: ubuntu-latest
needs: [metadata, docker]
if: github.event_name == 'release'
steps:
- name: checkout
uses: actions/checkout@v2
- name: set up QEMU
uses: docker/setup-qemu-action@v2
- name: set up docker buildx
uses: docker/setup-buildx-action@v2
- name: cache buildx
uses: pat-s/always-upload-cache@v2.1.5
with:
path: ${{ runner.temp }}/.buildx-cache
# yamllint disable-line rule:line-length
key: ${{ runner.os }}-buildx-${{ hashFiles('Dockerfile', '.dockerignore') }}
# yamllint disable rule:line-length
restore-keys: |
${{ runner.os }}-buildx-${{ hashFiles('Dockerfile', '.dockerignore') }}
${{ runner.os }}-buildx-
# yamllint enable rule:line-length
- name: login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: build multi-arch image
uses: docker/build-push-action@v3
env:
DOCKER_BUILDKIT: 1
BUILDKIT_INLINE_CACHE: 1
with:
push: false
load: true
platforms: linux/amd64,linux/arm/v7,linux/arm64
labels: ${{ needs.metadata.outputs.container-labels }}
cache-to: |
type=local,mode=max,dest=${{ runner.temp }}/.buildx-cache-new
cache-from: |
type=local,src=${{ runner.temp }}/.buildx-cache
${{ needs.metadata.outputs.container-tags }}
${{ github.repository }}:${{ github.ref_name }}
${{ github.repository }}:latest
build-args: |
GOLANG_VERSION=${{ env.GOLANG_VERSION }}
VERSION=${{ needs.metadata.outputs.version }}
tags: ${{ needs.metadata.outputs.container-tags }}
# fix to prevent ever-growing caches
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf ${{ runner.temp }}/.buildx-cache
mv ${{ runner.temp }}/.buildx-cache-new ${{ runner.temp }}/.buildx-cache
- name: test release
uses: brpaz/structure-tests-action@v1.1.2
with:
image: ${{ github.repository }}:test
configFile: container-structure-test.yaml
- name: security scan
uses: anchore/scan-action@v3
with:
image: ${{ github.repository }}:test
fail-build: true
- name: push multi-arch image
uses: docker/build-push-action@v3
env:
DOCKER_BUILDKIT: 1
BUILDKIT_INLINE_CACHE: 1
with:
push: true
platforms: linux/amd64,linux/arm/v7,linux/arm64
labels: ${{ needs.metadata.outputs.container-labels }}
cache-to: |
type=local,mode=max,dest=${{ runner.temp }}/.buildx-cache-new
cache-from: |
type=local,src=${{ runner.temp }}/.buildx-cache
${{ needs.metadata.outputs.container-tags }}
${{ github.repository }}:master
${{ github.repository }}:latest
build-args: |
GOLANG_VERSION=${{ env.GOLANG_VERSION }}
VERSION=${{ needs.metadata.outputs.version }}
tags: ${{ needs.metadata.outputs.container-tags }}
# fix to prevent ever-growing caches
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf ${{ runner.temp }}/.buildx-cache
mv ${{ runner.temp }}/.buildx-cache-new ${{ runner.temp }}/.buildx-cache
- name: update DockerHub description
uses: meeDamian/sync-readme@v1.0.6
with:
pass: ${{ secrets.DOCKER_PASSWORD }}
description: true