mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-28 07:56:30 +01:00
127 lines
4.6 KiB
YAML
127 lines
4.6 KiB
YAML
name: build
|
|
|
|
on:
|
|
pull_request:
|
|
branches: master
|
|
push:
|
|
branches: master
|
|
tags: v*
|
|
|
|
jobs:
|
|
go:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
-
|
|
name: Prepare
|
|
id: prepare
|
|
run: |
|
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
echo ::set-output name=tag_name::${GITHUB_REF#refs/tags/}
|
|
fi
|
|
-
|
|
# https://github.com/actions/setup-go
|
|
name: Set up Go
|
|
uses: actions/setup-go@master
|
|
with:
|
|
go-version: 1.12.10
|
|
-
|
|
name: Set GOPATH
|
|
# temporary fix (see https://github.com/actions/setup-go/issues/14)
|
|
run: |
|
|
echo "##[set-env name=GOPATH;]$(dirname $GITHUB_WORKSPACE)"
|
|
echo "##[add-path]$(dirname $GITHUB_WORKSPACE)/bin"
|
|
-
|
|
# https://github.com/actions/checkout
|
|
name: Checkout
|
|
uses: actions/checkout@v1
|
|
-
|
|
# https://github.com/goreleaser/goreleaser-action
|
|
name: GoReleaser
|
|
uses: goreleaser/goreleaser-action@v1
|
|
with:
|
|
version: latest
|
|
args: release --skip-publish --rm-dist
|
|
-
|
|
# https://github.com/softprops/action-gh-release
|
|
name: GitHub Release
|
|
uses: softprops/action-gh-release@v1
|
|
if: success() && startsWith(github.ref, 'refs/tags/')
|
|
with:
|
|
draft: true
|
|
files: |
|
|
dist/checksums.txt
|
|
dist/*.tar.gz
|
|
dist/*.zip
|
|
name: ${{ steps.prepare.outputs.tag_name }}
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
docker:
|
|
runs-on: ubuntu-latest
|
|
needs: go
|
|
steps:
|
|
-
|
|
name: Prepare
|
|
id: prepare
|
|
run: |
|
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
echo ::set-output name=version::${GITHUB_REF#refs/tags/v}
|
|
else
|
|
echo ::set-output name=version::snapshot
|
|
fi
|
|
echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
|
echo ::set-output name=docker_platforms::linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x
|
|
echo ::set-output name=docker_username::crazymax
|
|
echo ::set-output name=docker_image::crazymax/${{ github.event.repository.name }}
|
|
-
|
|
# https://github.com/crazy-max/ghaction-docker-buildx
|
|
name: Set up Docker Buildx
|
|
uses: crazy-max/ghaction-docker-buildx@v1
|
|
with:
|
|
version: latest
|
|
-
|
|
# https://github.com/actions/checkout
|
|
name: Checkout
|
|
uses: actions/checkout@v1
|
|
-
|
|
name: Docker Buildx (no push)
|
|
run: |
|
|
docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
|
|
--output "type=image,push=false" \
|
|
--build-arg "VERSION=${{ steps.prepare.outputs.version }}" \
|
|
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
|
|
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
|
|
--build-arg "VERSION=${{ steps.prepare.outputs.version }}" \
|
|
--tag "${{ steps.prepare.outputs.docker_image }}:latest" \
|
|
--tag "${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \
|
|
--file Dockerfile .
|
|
-
|
|
name: Docker Login
|
|
if: success() && startsWith(github.ref, 'refs/tags/v')
|
|
env:
|
|
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
|
run: |
|
|
echo "${DOCKER_PASSWORD}" | docker login --username "${{ steps.prepare.outputs.docker_username }}" --password-stdin
|
|
-
|
|
name: Docker Buildx (push)
|
|
if: success() && startsWith(github.ref, 'refs/tags/v')
|
|
run: |
|
|
docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
|
|
--output "type=image,push=true" \
|
|
--build-arg "VERSION=${{ steps.prepare.outputs.version }}" \
|
|
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
|
|
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
|
|
--build-arg "VERSION=${{ steps.prepare.outputs.version }}" \
|
|
--tag "${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}" \
|
|
--tag "${{ steps.prepare.outputs.docker_image }}:latest" \
|
|
--file Dockerfile .
|
|
-
|
|
name: Docker Check Manifest
|
|
if: always() && startsWith(github.ref, 'refs/tags/v')
|
|
run: |
|
|
docker run --rm mplatform/mquery ${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}
|
|
-
|
|
name: Clear
|
|
if: always() && startsWith(github.ref, 'refs/tags/v')
|
|
run: |
|
|
rm -f ${HOME}/.docker/config.json
|