1
0
mirror of https://github.com/nshttpd/mikrotik-exporter synced 2026-07-21 22:24:49 +02:00
Files
2026-05-30 22:08:45 -04:00

82 lines
2.0 KiB
YAML

name: CI
on:
pull_request:
push:
branches:
- trunk
tags:
- "v*"
env:
GO_VERSION: "1.25"
jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Run tests
run: go test ./...
build-and-push-images:
name: Build and push images
runs-on: ubuntu-latest
needs: [test]
if: github.event_name == 'push' && (github.ref == 'refs/heads/trunk' || startsWith(github.ref, 'refs/tags/v'))
permissions:
contents: read
packages: write
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Set up ko
uses: ko-build/setup-ko@v0.8
- name: Determine Version and Tags
id: versioning
run: |
SHORTSHA=$(git rev-parse --short HEAD)
echo "SHORTSHA=${SHORTSHA}" >> $GITHUB_ENV
# Determine the container tag version
if [[ "${{ github.ref_type }}" == "tag" ]]; then
VERSION_TAG="${{ github.ref_name }}"
else
VERSION_TAG="${SHORTSHA}"
fi
echo "VERSION_TAG=${VERSION_TAG}" >> $GITHUB_ENV
# Determine the appVersion to embed in the binary
if [[ "${{ github.ref_type }}" == "tag" ]]; then
APP_VERSION="${{ github.ref_name }}"
else
FILE_VERSION=$(cat VERSION)
APP_VERSION="${FILE_VERSION}-${SHORTSHA}"
fi
echo "APP_VERSION=${APP_VERSION}" >> $GITHUB_ENV
- name: Build and Push with ko
run: |
export KO_DOCKER_REPO="ghcr.io/${{ github.repository }}"
ko build . --tags="${{ env.VERSION_TAG }}"
env:
VERSION: ${{ env.APP_VERSION }}
SHORTSHA: ${{ env.SHORTSHA }}