Skip to content

Update GitHub Actions workflow to grant write permissions for contents #94

Update GitHub Actions workflow to grant write permissions for contents

Update GitHub Actions workflow to grant write permissions for contents #94

Workflow file for this run

name: Build flAPI
permissions:
contents: write
packages: write
issues: write
pull-requests: write
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
# -------------------------------------------------------------------------------------------------
# Linux Matrix Build (AMD64 + ARM64)
# -------------------------------------------------------------------------------------------------
linux-build:
runs-on: ubuntu-24.04
strategy:
matrix:
arch: [amd64, arm64]
env:
BUILD_ARCH: ${{ matrix.arch }}
BUILD_IMAGE: flapi_build_${{ matrix.arch }}
FLAPI_CROSS_COMPILE: ${{ matrix.arch == 'arm64' && 'arm64' || '' }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
- name: Setup Ccache
uses: hendrikmuhs/ccache-action@main
with:
key: ${{ github.job }}-${{ matrix.arch }}
- name: Build Docker image
shell: bash
run: |
docker build \
-t ${BUILD_IMAGE} \
-f .github/docker/linux_${BUILD_ARCH}/Dockerfile .
- name: Run build in docker
shell: bash
run: |
docker run \
${{ matrix.arch == 'arm64' && format('-e FLAPI_CROSS_COMPILE="{0}"', matrix.arch) || '' }} \
-v `pwd`:/build_dir \
-v ~/.ccache:/ccache_dir \
${BUILD_IMAGE} \
bash -c 'make clean && make release'
- uses: actions/upload-artifact@v4
with:
name: flapi-linux-${{ matrix.arch }}
path: build/release/flapi
if-no-files-found: error
# -------------------------------------------------------------------------------------------------
# Docker Build and Push Multi-Arch
# -------------------------------------------------------------------------------------------------
docker-build:
needs: [linux-build]
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Prepare
run: echo "REPO_OWNER=$(echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.REPO_OWNER }}/flapi
tags: |
type=raw,value=latest
type=sha,format=long
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Prepare artifacts
run: |
mkdir -p binaries/amd64 binaries/arm64
cp artifacts/flapi-linux-amd64/flapi binaries/amd64/
cp artifacts/flapi-linux-arm64/flapi binaries/arm64/
chmod +x binaries/amd64/flapi binaries/arm64/flapi
- name: Build and push multi-arch image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-contexts: |
build=binaries
# -------------------------------------------------------------------------------------------------
# macOS Universal
# -------------------------------------------------------------------------------------------------
osx-universal:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Ccache
uses: hendrikmuhs/ccache-action@main
with:
key: ${{ github.job }}
- name: Install dependencies
shell: bash
run: brew install ninja autoconf make libtool pkg-config automake autoconf-archive
- name: Build
run: make release
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: flapi-macos-universal
path: build/universal/flapi
if-no-files-found: error
retention-days: 90
publish-binaries:
needs: [linux-build, osx-universal]
runs-on: ubuntu-24.04
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Download Linux Artifacts
uses: actions/download-artifact@v4
with:
name: flapi-linux-amd64
path: ./artifacts/linux/amd64
- name: Download Linux ARM64 Artifacts
uses: actions/download-artifact@v4
with:
name: flapi-linux-arm64
path: ./artifacts/linux/arm64
- name: Download macOS Artifacts
uses: actions/download-artifact@v4
with:
name: flapi-macos-universal
path: ./artifacts/macos
- name: Publish to GitHub Packages
run: |
gh release create ${{ github.sha }} \
./artifacts/linux/amd64/flapi#flapi-linux-amd64 \
./artifacts/linux/arm64/flapi#flapi-linux-arm64 \
./artifacts/macos/flapi#flapi-macos-universal \
--title "flAPI Release ${{ github.sha }}" \
--notes "Automated release of flAPI binaries."