Release Build #11
Workflow file for this run
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: Release Build | |
on: | |
push: | |
tags: | |
- '*' | |
env: | |
APP_NAME: 'geoip-policyd' | |
MAINTAINER: 'croessner' | |
DESC: 'Policy server that blocks senders based on country and IP diversity.' | |
jobs: | |
build-artifact: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
goos: [linux] | |
goarch: [amd64, arm64] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: 1.22.x | |
- run: | | |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \ | |
go build -mod=vendor -ldflags="-s -X main.version=${GITHUB_REF#refs/heads/})-${GITHUB_SHA:0:8}" -o ${{ env.APP_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }} . | |
- name: Create artifact | |
run: | | |
os="${{ runner.os }}" | |
assets="${{ env.APP_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }}" | |
echo "$assets" | |
mkdir -p "dist/$assets" | |
cp -r ${{ env.APP_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }} LICENSE README.* "dist/$assets/" | |
( | |
cd dist | |
tar czf "$assets.tar.gz" "$assets" | |
ls -lah *.* | |
) | |
shell: bash | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: artifact-${{ matrix.goos }}-${{ matrix.goarch }} | |
path: | | |
dist/*.tar.gz | |
build-linux-packages: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
goos: [ linux ] | |
goarch: [ amd64, arm64 ] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-go@v5 | |
with: | |
go-version: 1.22.x | |
- run: | | |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \ | |
go build -mod=vendor -ldflags="-s -X main.version=${GITHUB_REF#refs/heads/})-${GITHUB_SHA:0:8}" -o ${{ env.APP_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }} | |
- name: Copy binaries | |
run: | | |
mkdir -p .debpkg/usr/sbin | |
mkdir -p .rpmpkg/usr/sbin | |
cp ${{ env.APP_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }} .debpkg/usr/sbin/ | |
cp ${{ env.APP_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }} .rpmpkg/usr/sbin/ | |
- uses: jiro4989/build-deb-action@v3 | |
with: | |
package: ${{ env.APP_NAME }} | |
package_root: .debpkg | |
maintainer: ${{ env.MAINTAINER }} | |
version: ${{ github.ref }} | |
arch: 'amd64' | |
desc: '${{ env.DESC }}' | |
- uses: jiro4989/build-rpm-action@v2 | |
with: | |
summary: '${{ env.DESC }}' | |
package: ${{ env.APP_NAME }} | |
package_root: .rpmpkg | |
maintainer: ${{ env.MAINTAINER }} | |
version: ${{ github.ref }} | |
arch: 'x86_64' | |
desc: '${{ env.DESC }}' | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: artifact-${{ matrix.goos }}-${{ matrix.goarch }}-deb | |
path: | | |
./*.deb | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: artifact-${{ matrix.goos }}-${{ matrix.goarch }}-rpm | |
path: | | |
./*.rpm | |
!./*-debuginfo-*.rpm | |
create-release: | |
runs-on: ubuntu-latest | |
needs: | |
- build-artifact | |
- build-linux-packages | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Generate changelog | |
run: | | |
wget https://github.com/git-chglog/git-chglog/releases/download/0.9.1/git-chglog_linux_amd64 | |
chmod +x git-chglog_linux_amd64 | |
mv git-chglog_linux_amd64 git-chglog | |
./git-chglog --output ./changelog $(git describe --tags $(git rev-list --tags --max-count=1)) | |
- name: Create Release | |
id: create-release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.geoip_policyd_RELEASE }} | |
with: | |
tag_name: ${{ github.ref }} | |
release_name: ${{ github.ref }} | |
body_path: ./changelog | |
draft: false | |
prerelease: false | |
- name: Write upload_url to file | |
run: echo '${{ steps.create-release.outputs.upload_url }}' > upload_url.txt | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: create-release | |
path: upload_url.txt | |
upload-release: | |
runs-on: ubuntu-latest | |
needs: create-release | |
strategy: | |
matrix: | |
include: | |
- os: ubuntu-latest | |
asset_name_suffix: linux.tar.gz | |
asset_content_type: application/gzip | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
name: artifact-linux-amd64 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: artifact-linux-arm64 | |
- uses: actions/download-artifact@v4 | |
with: | |
name: create-release | |
- id: vars | |
run: | | |
echo "::set-output name=upload_url::$(cat upload_url.txt)" | |
- name: Upload Release Asset | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.geoip_policyd_RELEASE }} | |
with: | |
upload_url: ${{ steps.vars.outputs.upload_url }} | |
asset_path: ${{ env.APP_NAME }}_${{ matrix.asset_name_suffix }} | |
asset_name: ${{ env.APP_NAME }}_${{ matrix.asset_name_suffix }} | |
asset_content_type: ${{ matrix.asset_content_type }} | |
upload-linux-packages: | |
runs-on: ubuntu-latest | |
needs: create-release | |
strategy: | |
matrix: | |
include: | |
- pkg: deb | |
asset_content_type: application/vnd.debian.binary-package | |
- pkg: rpm | |
asset_content_type: application/x-rpm | |
steps: | |
- uses: actions/download-artifact@v4 | |
with: | |
name: artifact-linux-amd64-${{ matrix.pkg }} | |
- uses: actions/download-artifact@v4 | |
with: | |
name: artifact-linux-arm64-${{ matrix.pkg }} | |
- uses: actions/download-artifact@v4 | |
with: | |
name: create-release | |
- id: vars | |
run: | | |
echo "::set-output name=upload_url::$(cat upload_url.txt)" | |
echo "::set-output name=asset_name::$(ls *.${{ matrix.pkg }} | head -n 1)" | |
- name: Upload Release Asset | |
id: upload-release-asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.geoip_policyd_RELEASE }} | |
with: | |
upload_url: ${{ steps.vars.outputs.upload_url }} | |
asset_path: ${{ steps.vars.outputs.asset_name }} | |
asset_name: ${{ steps.vars.outputs.asset_name }} | |
asset_content_type: ${{ matrix.asset_content_type }} |