Add build flags #60
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and release | |
on: | |
# Runs automatically when a tag beginning with 'v' (i.e. a versioned release) is pushed. | |
push: | |
tags: | |
- v* | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
build-release: | |
runs-on: ubuntu-20.04 | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/setup-go@v4 | |
with: | |
go-version: '1.21.4' | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false | |
- name: build binary | |
run: go build -ldflags "-X github.com/letsencrypt/unbound_exporter/util.BuildID=$(git rev-parse --short HEAD) -X github.com/letsencrypt/unbound_exporter/util.BuildBranch=$(git rev-parse --abbrev-ref HEAD) -X github.com/letsencrypt/unbound_exporter/util.BuildTime=$(date +%F-%T -u)" | |
- name: install nfpm | |
run: go install github.com/goreleaser/nfpm/v2/cmd/[email protected] | |
- name: build deb | |
run: nfpm package -p deb -t unbound_exporter.deb | |
- name: upload deb | |
uses: actions/upload-artifact@v3 | |
with: | |
name: unbound_exporter deb artifact | |
path: unbound_exporter.deb | |
push-release: | |
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/') | |
needs: build-release | |
runs-on: ubuntu-20.04 | |
# Overrides the org default of 'read'. This allows us to upload and post the | |
# resulting package file as part of a release. | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
persist-credentials: false | |
- name: Download release artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: unbound_exporter deb artifact | |
- name: rename | |
run: mv unbound_exporter.deb unbound_exporter-${GITHUB_REF_NAME}.x86_64.deb | |
- name: push release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# https://cli.github.com/manual/gh_release_create | |
run: gh release create "${GITHUB_REF_NAME}" unbound_exporter-${GITHUB_REF_NAME}.x86_64.deb |