adguard-exporter/.github/workflows/tag.yml

125 lines
3.3 KiB
YAML

name: Build/Push (tag)
on:
push:
tags:
- '*'
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.15
- run: go get -t -v ./...
- run: go test -v -race ./...
build:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Get the version
id: get_version
run: echo ::set-output name=TAG_NAME::${GITHUB_REF/refs\/tags\//}
- name: Build and push docker image
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64
push: true
tags: ebrianne/adguard-exporter:${{ steps.get_version.outputs.TAG_NAME }}
release:
runs-on: ubuntu-latest
needs: test
steps:
- name: Create release
id: create
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: false
outputs:
upload_url: ${{ steps.create.outputs.upload_url }}
upload:
runs-on: ubuntu-latest
needs: release
strategy:
matrix:
include:
- os: linux
arch: 386
- os: linux
arch: amd64
- os: linux
arch: arm
- os: linux
arch: arm64
- os: darwin
arch: amd64
- os: freebsd
arch: 386
- os: freebsd
arch: amd64
- os: windows
arch: 386
extension: '.exe'
- os: windows
arch: amd64
extension: '.exe'
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.15
- name: Download go dependencies
run: go get -t -v ./...
- name: Install the needed vendors
run: GO111MODULE=on go mod vendor
- name: Create release (${{ matrix.os }}-${{ matrix.arch }})
run: CGO_ENABLED=0 GOOS=${{ matrix.os }} GOARCH=${{ matrix.arch }} go build -a -ldflags '-s -w' -o adguard_exporter-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }} ./
- name: Upload release assets
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.upload_url }}${{ matrix.extension }}
asset_path: ./adguard_exporter-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }}
asset_name: adguard_exporter-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }}
asset_content_type: application/octet-stream