Skip to content

Refactor: Update architecture setting in build-stable workflow #24

Refactor: Update architecture setting in build-stable workflow

Refactor: Update architecture setting in build-stable workflow #24

Workflow file for this run

name: Release Build
on:
push:
tags:
- 'v*'
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/"
cp systemd/geoip-policyd.service "dist/$assets/"
cp systemd/geoip-policyd "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 .debpkg/usr/lib/systemd/system
mkdir -p .debpkg/etc/default
mkdir -p .debpkg/usr/share/doc/${{ env.APP_NAME }}
cp ${{ env.APP_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }} .debpkg/usr/sbin/
cp systemd/${{ env.APP_NAME }}.service .debpkg/usr/lib/systemd/system/
cp systemd/${{ env.APP_NAME }} .debpkg/etc/default/
cp LICENSE README.md .debpkg/usr/share/doc/${{ env.APP_NAME }}/
- uses: jiro4989/build-deb-action@v3
with:
package: ${{ env.APP_NAME }}
package_root: .debpkg
maintainer: ${{ env.MAINTAINER }}
version: ${{ github.ref }}
arch: '${{ matrix.goarch }}'
desc: '${{ env.DESC }}'
# TODO: RPM packages
- uses: actions/upload-artifact@v4
with:
name: artifact-${{ matrix.goos }}-${{ matrix.goarch }}-deb
path: |
./*.deb
create-release:
runs-on: ubuntu-latest
needs:
- build-artifact
- build-linux-packages
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: List files in current directory after checkout
run: ls -l
- 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: List files in current directory after changelog generation
run: ls -l
- name: Create Release
id: create-release
uses: softprops/action-gh-release@v2
with:
body_path: ./changelog
repository: croessner/${{ env.APP_NAME }}
token: ${{ secrets.GEOIP_POLICYD_RELEASE }}
name: Release ${{ github.ref_name }}
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:
goos: [ linux ]
goarch: [ amd64, arm64 ]
include:
- os: ubuntu-latest
asset_suffix: .tar.gz
asset_content_type: application/gzip
steps:
- uses: actions/download-artifact@v4
with:
name: artifact-${{ matrix.goos }}-${{ matrix.goarch }}
- 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.goos }}-${{ matrix.goarch }}${{ matrix.asset_suffix }}
asset_name: ${{ env.APP_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.asset_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
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 }}