Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 201 additions & 0 deletions .github/workflows/build-and-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
---
name: Build and Package

'on':
workflow_call:
inputs:
platform:
description: Operating system family for the build.
required: true
type: string
runner:
description: GitHub-hosted runner label to target.
required: true
type: string
target:
description: Cargo build target triple.
required: true
type: string
artifact_label:
description: Suffix used when naming uploaded artefacts.
required: true
type: string
package_arch:
description: Package architecture label used for artefact naming.
required: false
type: string
target_key:
description: Release staging target key for macOS and Windows builds.
required: false
type: string
msi_arch:
description: WiX architecture identifier for Windows installer builds.
required: false
type: string
repo_name:
description: Repository name used when uploading artefacts.
required: true
type: string
bin_name:
description: Binary name extracted from Cargo metadata.
required: true
type: string
version:
description: Crate version extracted from Cargo metadata.
required: true
type: string
should_publish:
description: Whether artefacts should be published.
required: true
type: boolean
wix_extension_version:
description: WiX extension version required for Windows packaging.
required: false
type: string

jobs:
build-and-package:
name: Build and package ${{ inputs.platform }} (${{ inputs.target }})
runs-on: ${{ inputs.runner }}
env:
REPO_NAME: ${{ inputs.repo_name }}
BIN_NAME: ${{ inputs.bin_name }}
VERSION: ${{ inputs.version }}
steps:
- uses: >-
actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
# v4.1.2

- name: Install uv
if: inputs.platform != 'linux'
uses: >-
astral-sh/setup-uv@4cda7d73322c50eac316ad623a716f09a2db2ac7
# v3.1.2
with:
python-version: '3.11'

- name: Build release
uses: >-
leynos/shared-actions/.github/actions/rust-build-release@dd56f18c39f1e158eb04cd5b4fc9194aadb6b52b
with:
target: ${{ inputs.target }}
bin-name: ${{ inputs.bin_name }}
version: ${{ inputs.version }}

- name: Package Linux artefacts with dependencies
if: inputs.platform == 'linux'
uses: >-
leynos/shared-actions/.github/actions/linux-packages@dd56f18c39f1e158eb04cd5b4fc9194aadb6b52b
with:
project-dir: .
package-name: ${{ inputs.bin_name }}
bin-name: ${{ inputs.bin_name }}
target: ${{ inputs.target }}
version: ${{ inputs.version }}
formats: deb,rpm
man-paths: >-
dist/${{ inputs.bin_name }}_linux_${{ inputs.package_arch }}/${{ inputs.bin_name }}.1
outdir: dist
deb-depends: ninja-build
rpm-depends: ninja-build

- name: Prune packaging metadata
if: inputs.platform == 'linux'
shell: bash
run: rm -rf dist/.man dist/nfpm.yaml

- id: stage
if: inputs.platform != 'linux'
name: Stage artefacts
uses: ./.github/actions/stage
with:
config-file: .github/release-staging.toml
target: ${{ inputs.target_key }}

- id: normalize_windows_paths
if: inputs.platform == 'windows'
name: Normalise Windows paths
shell: bash
env:
BINARY_PATH: ${{ steps.stage.outputs.binary_path }}
LICENSE_PATH: ${{ steps.stage.outputs.license_path }}
run: |
set -euo pipefail
python .github/workflows/scripts/normalise_windows_paths.py

- id: package_windows
if: inputs.platform == 'windows'
name: Build Windows installer package
uses: >-
leynos/shared-actions/.github/actions/windows-package@dd56f18c39f1e158eb04cd5b4fc9194aadb6b52b
with:
product-name: ${{ inputs.bin_name }}
manufacturer: Leynos
install-dir-name: ${{ inputs.bin_name }}
application-path: ${{ steps.normalize_windows_paths.outputs.binary_path }}
license-rtf-path: ${{ steps.normalize_windows_paths.outputs.license_path }}
architecture: ${{ inputs.msi_arch }}
version: ${{ inputs.version }}
output-basename: ${{ inputs.bin_name }}
output-directory: dist
license-plaintext-path: LICENSE
upload-artifact: ${{ inputs.should_publish }}
wix-extension-version: ${{ inputs.wix_extension_version }}

- id: pkg
if: inputs.platform == 'macos'
name: Build macOS installer package
uses: >-
leynos/shared-actions/.github/actions/macos-package@dd56f18c39f1e158eb04cd5b4fc9194aadb6b52b
with:
name: ${{ inputs.bin_name }}
identifier: com.leynos.${{ inputs.bin_name }}
binary: ${{ steps.stage.outputs.binary_path }}
manpage: ${{ steps.stage.outputs.man_path }}
license-file: LICENSE
version: ${{ inputs.version }}

- name: Stamp architecture into package name
if: inputs.platform == 'macos'
shell: bash
env:
BIN_NAME: ${{ inputs.bin_name }}
VERSION: ${{ inputs.version }}
ARCHIVE_SUFFIX: ${{ inputs.artifact_label }}
PKG_PATH: ${{ steps.pkg.outputs.pkg-path }}
run: |
set -euo pipefail
dest="dist/${BIN_NAME}-${VERSION}-${ARCHIVE_SUFFIX}.pkg"
mkdir -p "$(dirname "$dest")"
mv "$PKG_PATH" "$dest"

- name: Upload Linux artefacts
if: inputs.platform == 'linux'
uses: >-
actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
# v4
with:
name: ${{ inputs.repo_name }}-${{ inputs.artifact_label }}
path: dist

- name: Upload Windows artefacts
if: inputs.platform == 'windows' && inputs.should_publish
uses: >-
actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
# v4
with:
name: ${{ inputs.repo_name }}-${{ inputs.artifact_label }}
path: |
${{ steps.stage.outputs.artifact_dir }}
${{ steps.package_windows.outputs.msi-path }}

- name: Upload macOS artefacts
if: inputs.platform == 'macos'
uses: >-
actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
# v4
with:
name: ${{ inputs.repo_name }}-${{ inputs.artifact_label }}
path: |
${{ steps.stage.outputs.artifact_dir }}
dist/${{ inputs.bin_name }}-${{ inputs.version }}-${{ inputs.artifact_label }}.pkg
Loading
Loading