Skip to content

Merge pull request #10 from ntt0601zcoder/fix/template-resolution #2

Merge pull request #10 from ntt0601zcoder/fix/template-resolution

Merge pull request #10 from ntt0601zcoder/fix/template-resolution #2

Workflow file for this run

# Cross-compile binaries for every supported OS/arch and (when a v* tag is pushed)
# attach them to a GitHub Release.
#
# Triggers:
# - workflow_dispatch — manual run from the Actions tab. Produces downloadable
# artifacts only (no Release is created). Useful for ad-hoc test builds.
# - push tag matching v* — full build + GitHub Release creation with checksums.
# Tag from CLI: git tag v0.1.0 && git push origin v0.1.0
#
# This workflow does NOT run on every push/PR — release builds are expensive and
# rarely needed. Day-to-day correctness is covered by CI.
name: Release
on:
workflow_dispatch:
inputs:
version:
description: "Version label baked into archive filenames (e.g. v0.1.0-rc1). Leave empty to use commit SHA."
required: false
default: ""
push:
tags:
- "v*"
permissions:
contents: write
packages: read # pull the GHCR builder image to cross-build the cgo transcoder
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
build:
name: Build ${{ matrix.os }}/${{ matrix.arch }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- os: linux
arch: amd64
archive: tar.gz
- os: linux
arch: arm64
archive: tar.gz
- os: darwin
arch: amd64
archive: tar.gz
- os: darwin
arch: arm64
archive: tar.gz
- os: windows
arch: amd64
archive: zip
ext: ".exe"
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
cache: true
- name: Determine version label
id: version
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF_NAME}"
elif [[ -n "${{ inputs.version }}" ]]; then
VERSION="${{ inputs.version }}"
else
VERSION="dev-${GITHUB_SHA::8}"
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "stage=open-streamer-${{ matrix.os }}-${{ matrix.arch }}" >> "$GITHUB_OUTPUT"
- name: Build binary
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
CGO_ENABLED: "0"
run: |
mkdir -p stage/${{ steps.version.outputs.stage }}/bin
BUILT_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
# ldflags -X target = module import path (go.mod) + /pkg/version,
# so a fork stamps versions without editing this workflow.
VPKG=$(go list -m)/pkg/version
go build \
-trimpath \
-ldflags="-s -w \
-X ${VPKG}.Version=${{ steps.version.outputs.version }} \
-X ${VPKG}.Commit=${GITHUB_SHA} \
-X ${VPKG}.BuiltAt=${BUILT_AT}" \
-o stage/${{ steps.version.outputs.stage }}/bin/open-streamer${{ matrix.ext }} \
./cmd/server
- name: Stage Linux extras (systemd unit + installer)
if: matrix.os == 'linux'
run: |
DST=stage/${{ steps.version.outputs.stage }}
mkdir -p "$DST/build"
cp build/install.sh "$DST/build/"
cp build/open-streamer.service "$DST/build/"
chmod +x "$DST/build/install.sh" "$DST/bin/open-streamer"
# ── Native transcoder (cgo + libav 8) ─────────────────────────────────
# Only linux/amd64 for now: the transcoder is built by cross-compiling
# inside the prebuilt builder image and bundling every libav .so the
# binary dlopens (Dockerfile.transcoder `export` stage → binary + lib/).
# arm64 / darwin / windows transcoder builds are staged as follow-ups —
# each needs its own builder + per-OS shared-lib bundling. The server
# binary itself still ships for every matrix platform.
- name: Set up Buildx (transcoder build)
if: matrix.os == 'linux' && matrix.arch == 'amd64'
uses: docker/setup-buildx-action@v4
- name: Log in to GHCR (pull builder image)
if: matrix.os == 'linux' && matrix.arch == 'amd64'
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build native transcoder + bundle libav (linux/amd64)
if: matrix.os == 'linux' && matrix.arch == 'amd64'
uses: docker/build-push-action@v7
with:
context: .
file: Dockerfile.transcoder
target: export
build-args: |
BUILDER_IMAGE=ghcr.io/${{ github.repository_owner }}/open-streamer-builder:v1
VERSION=${{ steps.version.outputs.version }}
COMMIT=${{ github.sha }}
outputs: type=local,dest=transcoder-out
- name: Stage transcoder into archive (linux/amd64)
if: matrix.os == 'linux' && matrix.arch == 'amd64'
run: |
DST=stage/${{ steps.version.outputs.stage }}
cp transcoder-out/open-streamer-transcoder "$DST/bin/"
chmod +x "$DST/bin/open-streamer-transcoder"
mkdir -p "$DST/lib"
cp -a transcoder-out/lib/. "$DST/lib/"
echo "→ staged transcoder + $(ls "$DST/lib" | wc -l) bundled libs"
- name: Stage docs and version metadata
run: |
DST=stage/${{ steps.version.outputs.stage }}
cp README.md LICENSE "$DST/"
# VERSION file lets users (and ops scripts) identify what's installed
# without invoking the binary.
{
echo "version=${{ steps.version.outputs.version }}"
echo "commit=${GITHUB_SHA}"
echo "built_at=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
echo "os=${{ matrix.os }}"
echo "arch=${{ matrix.arch }}"
} > "$DST/VERSION"
- name: Create tar.gz archive
if: matrix.archive == 'tar.gz'
run: |
ARCHIVE="open-streamer-${{ steps.version.outputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.tar.gz"
tar -C stage -czf "$ARCHIVE" "${{ steps.version.outputs.stage }}"
echo "ARCHIVE=$ARCHIVE" >> "$GITHUB_ENV"
- name: Create zip archive
if: matrix.archive == 'zip'
run: |
ARCHIVE="open-streamer-${{ steps.version.outputs.version }}-${{ matrix.os }}-${{ matrix.arch }}.zip"
(cd stage && zip -r "../$ARCHIVE" "${{ steps.version.outputs.stage }}")
echo "ARCHIVE=$ARCHIVE" >> "$GITHUB_ENV"
- name: Upload archive as workflow artifact
uses: actions/upload-artifact@v7
with:
name: open-streamer-${{ matrix.os }}-${{ matrix.arch }}
path: ${{ env.ARCHIVE }}
if-no-files-found: error
retention-days: 14
release:
name: Publish GitHub Release
needs: build
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Download all build artifacts
uses: actions/download-artifact@v8
with:
path: dist
# Only the platform archives — exclude the *.dockerbuild provenance
# artifact that docker/build-push-action uploads from the transcoder
# build (download-artifact can't fetch it; it fails the whole step).
pattern: open-streamer-*
merge-multiple: true
- name: Generate SHA256 checksums
run: |
cd dist
sha256sum *.tar.gz *.zip > SHA256SUMS
cat SHA256SUMS
- name: Create GitHub Release
uses: softprops/action-gh-release@v3
with:
files: |
dist/*.tar.gz
dist/*.zip
dist/SHA256SUMS
generate_release_notes: true
fail_on_unmatched_files: true