77 lines
2.5 KiB
YAML
77 lines
2.5 KiB
YAML
name: build
|
|
on: [push, pull_request]
|
|
jobs:
|
|
build:
|
|
strategy:
|
|
matrix:
|
|
go-version: [1.14.x, 1.15.x]
|
|
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
|
|
runs-on: ${{ matrix.os }}
|
|
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
- uses: actions/setup-go@v2
|
|
with:
|
|
go-version: ${{ matrix.go-version }}
|
|
id: go
|
|
|
|
- name: Build
|
|
run: go build -v
|
|
|
|
- name: Test
|
|
run: go test -v ./...
|
|
|
|
push:
|
|
runs-on: ubuntu-latest
|
|
needs: [build]
|
|
steps:
|
|
- uses: actions/checkout@v2
|
|
|
|
- name: Get Image Metadata
|
|
id: image_metadata
|
|
run: |
|
|
DOCKER_IMAGE=ghcr.io/${{ github.event.repository.full_name }}
|
|
# Always tag latest
|
|
TAGS=$DOCKER_IMAGE:latest
|
|
# Add version tag
|
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
VERSION=${GITHUB_REF#refs/tags/}
|
|
TAGS=$TAGS,$DOCKER_IMAGE:$VERSION
|
|
# Add major and minor tag i.e for version 1.2.3, tag 1.2 and 1
|
|
if [[ $VERSION =~ ^[0-9]\.[0-9]\.[0-9]$ ]]; then
|
|
MINOR=${VERSION%.*}
|
|
MAJOR=${MINOR%.*}
|
|
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR}"
|
|
fi
|
|
fi
|
|
echo "::set-output name=date::$(date +'%Y-%m-%dT%H:%M:%S')"
|
|
echo "::set-output name=tags::${TAGS}"
|
|
|
|
- name: Login to GHCR
|
|
uses: docker/login-action@v1
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ secrets.GHCR_USERNAME }}
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v1
|
|
|
|
- name: Build/Push To GHCR
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
context: .
|
|
file: Dockerfile
|
|
push: true
|
|
tags: ${{ steps.image_metadata.outputs.tags }}
|
|
labels: |
|
|
org.opencontainers.image.title=${{ github.event.repository.name }}
|
|
org.opencontainers.image.description=${{ github.event.repository.description }}
|
|
org.opencontainers.image.url=${{ github.event.repository.html_url }}
|
|
org.opencontainers.image.source=${{ github.event.repository.html_url }}
|
|
org.opencontainers.image.version=latest
|
|
org.opencontainers.image.created=${{ steps.image_metadata.outputs.date }}
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
|