Skip to content

WIP

WIP #1

Workflow file for this run

name: release
on:
push:
tags:
- 'v*'
jobs:
test_build:
name: test_build
runs-on: ubuntu-22.04
steps:
- name: clone
uses: actions/checkout@main
- name: install depends
run: |
go mod download
mkdir artifacts
- name: Setup Go
uses: actions/setup-go@main
with:
go-version: 1.22
- name: build
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" -o artifacts/custom-exporter
create_release:
name: create_release
runs-on: ubuntu-22.04
needs: [test_build]
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
upload_release:
needs: [create_release]
name: build_and_release
runs-on: ubuntu-22.04
strategy:
matrix:
arch: [amd64, arm64, arm7]
steps:
- name: clone
uses: actions/checkout@main
- name: install depends
run: |
go mod download
mkdir artifacts
- name: Setup Go
uses: actions/setup-go@main
with:
go-version: 1.22
- name: build
run: |
export CGO_ENABLED=0
export GOOS=linux
export GOARCH=${{ matrix.arch }}
if [[ "${{ matrix.arch }}" == "arm7" ]]; then
export GOARM=7
export GOARCH=arm
fi
go build -ldflags="-s -w" -o artifacts/custom-exporter-${{ matrix.arch }} .
- name: Upload release
id: upload-release-asset
uses: actions/upload-release-asset@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./artifacts/custom-exporter-${{ matrix.arch }}
asset_name: custom-exporter-${{ matrix.arch }}
asset_content_type: application/x-elf
container_image:
name: container_image
runs-on: ubuntu-22.04
needs: [upload_release]
steps:
- name: Checkout code
uses: actions/checkout@main
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: ghcr.io/${{ github.repository_owner }}/custom-exporter:latest