Skip to content

Merge pull request #39 from swoga/renovate/github.com-prometheus-comm… #87

Merge pull request #39 from swoga/renovate/github.com-prometheus-comm…

Merge pull request #39 from swoga/renovate/github.com-prometheus-comm… #87

Workflow file for this run

name: build
on:
push:
branches:
- main
tags:
- v*
env:
GO_VERSION: 1.19
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
if: ${{ !env.ACT }}
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Vet
run: go vet ./...
- name: Test
run: go test -v ./...
build-go:
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
os: [linux, windows]
arch: [386, amd64]
include:
- os: darwin
arch: amd64
- os: dragonfly
arch: amd64
- os: linux
arch: arm64
env:
OUTPUT_BINARY_EXT:
OUTPUT_ARCHIVE_EXT: .tar.gz
ARCHIVER: tar -cvzf
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Build
run: make build-go
- name: Prepare ENV for Windows
if: matrix.os == 'windows'
run: |
echo "OUTPUT_BINARY_EXT=.exe" >> $GITHUB_ENV
echo "OUTPUT_ARCHIVE_EXT=.zip" >> $GITHUB_ENV
echo "ARCHIVER=zip -r" >> $GITHUB_ENV
- name: Prepare ENV
run: |
echo "OUTPUT_BINARY=mikrotik-exporter${{ env.OUTPUT_BINARY_EXT }}" >> $GITHUB_ENV
echo "OUTPUT_ARCHIVE=mikrotik-exporter.${{ matrix.os }}-${{ matrix.arch }}${{ env.OUTPUT_ARCHIVE_EXT }}" >> $GITHUB_ENV
- name: Compress files
run: ${{ env.ARCHIVER }} ${{ env.OUTPUT_ARCHIVE }} ${{ env.OUTPUT_BINARY }} LICENSE
- name: Upload
uses: actions/upload-artifact@v3
with:
name: mikrotik-exporter.${{ matrix.os }}-${{ matrix.arch }}
path: ${{ env.OUTPUT_ARCHIVE }}
- name: Release
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1
with:
files: ${{ env.OUTPUT_ARCHIVE }}
build-container:
runs-on: ubuntu-latest
needs: build-go
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
name: mikrotik-exporter.linux-amd64
- name: Decompress
run: tar -xf mikrotik-exporter.linux-amd64.tar.gz
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Login to GHCR
if: ${{ !env.ACT }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to Quay
if: ${{ !env.ACT }}
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Login to Docker Hub
if: ${{ !env.ACT }}
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- if: startsWith(github.ref, 'refs/tags/')
run: echo "TAG=latest" >> $GITHUB_ENV
- name: Build
run: make build-container
- name: Push
if: ${{ !env.ACT }}
run: make push-container