Skip to content

Add repository parameter to GitHub release creation step #5

Add repository parameter to GitHub release creation step

Add repository parameter to GitHub release creation step #5

Workflow file for this run

name: Build and release
on:
push:
branches:
- "**"
tags:
- "**"
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- name: Linux x86_64
os: ubuntu-24.04
package: linux-x86_64
mads_asset: "*Linux-x86_64.tar.gz"
- name: Linux aarch64
os: ubuntu-24.04-arm
package: linux-aarch64
mads_asset: "*Linux-aarch64.tar.gz"
- name: macOS Universal
os: macos-15
package: macos-universal
mads_asset: "*Darwin-universal.sh"
cmake_osx_architectures: "arm64;x86_64"
- name: Windows x86_64
os: windows-2022
package: windows-x86_64
mads_asset: "*Windows-AMD64.exe"
steps:
- name: Check out sources
uses: actions/checkout@v4
- name: Install Linux build dependencies
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y \
clang \
cmake \
extra-cmake-modules \
libgl1-mesa-dev \
libssl-dev \
libwayland-dev \
libx11-dev \
libxcursor-dev \
libxext-dev \
libxi-dev \
libxinerama-dev \
libxkbcommon-dev \
libxrandr-dev \
ninja-build \
pkg-config \
wayland-protocols \
xorg-dev
- name: Set up MSVC
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64
- name: Install MADS on Linux
if: runner.os == 'Linux'
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/mads-release" "$RUNNER_TEMP/mads"
curl -fsSL \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "User-Agent: mads-chat-ci" \
"https://api.github.com/repos/pbosetti/MADS/releases/latest" \
-o "$RUNNER_TEMP/mads-release/latest.json"
asset_url="$(
python3 - "$RUNNER_TEMP/mads-release/latest.json" "${{ matrix.mads_asset }}" <<'PY'
import fnmatch
import json
import sys
with open(sys.argv[1], encoding="utf-8") as handle:
release = json.load(handle)
for asset in release["assets"]:
if fnmatch.fnmatch(asset["name"], sys.argv[2]):
print(asset["url"])
break
else:
raise SystemExit(f"No MADS release asset matches {sys.argv[2]}")
PY
)"
curl -fL \
-H "Accept: application/octet-stream" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "User-Agent: mads-chat-ci" \
"$asset_url" \
-o "$RUNNER_TEMP/mads-release/mads.tar.gz"
archive="$RUNNER_TEMP/mads-release/mads.tar.gz"
tar -xzf "$archive" -C "$RUNNER_TEMP/mads"
agent_header="$(find "$RUNNER_TEMP/mads" -type f -path '*/include/agent.hpp' -print -quit)"
if [ -z "$agent_header" ]; then
echo "Could not find MADS headers after extracting $archive" >&2
exit 1
fi
mads_root="${agent_header%/include/agent.hpp}"
test -f "$mads_root/lib/libMadsCore.so"
echo "MADS_ROOT=$mads_root" >> "$GITHUB_ENV"
echo "$mads_root/bin" >> "$GITHUB_PATH"
- name: Install MADS on macOS
if: runner.os == 'macOS'
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
mkdir -p "$RUNNER_TEMP/mads-release" "$RUNNER_TEMP/mads"
curl -fsSL \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "User-Agent: mads-chat-ci" \
"https://api.github.com/repos/pbosetti/MADS/releases/latest" \
-o "$RUNNER_TEMP/mads-release/latest.json"
asset_url="$(
python3 - "$RUNNER_TEMP/mads-release/latest.json" "${{ matrix.mads_asset }}" <<'PY'
import fnmatch
import json
import sys
with open(sys.argv[1], encoding="utf-8") as handle:
release = json.load(handle)
for asset in release["assets"]:
if fnmatch.fnmatch(asset["name"], sys.argv[2]):
print(asset["url"])
break
else:
raise SystemExit(f"No MADS release asset matches {sys.argv[2]}")
PY
)"
installer="$RUNNER_TEMP/mads-release/mads.sh"
curl -fL \
-H "Accept: application/octet-stream" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "User-Agent: mads-chat-ci" \
"$asset_url" \
-o "$installer"
sh "$installer" --skip-license --prefix="$RUNNER_TEMP/mads" --exclude-subdir
agent_header="$(find "$RUNNER_TEMP/mads" -type f -path '*/include/agent.hpp' -print -quit)"
if [ -z "$agent_header" ]; then
echo "Could not find MADS headers after running $installer" >&2
exit 1
fi
mads_root="${agent_header%/include/agent.hpp}"
test -f "$mads_root/lib/libMadsCore.dylib"
echo "MADS_ROOT=$mads_root" >> "$GITHUB_ENV"
echo "$mads_root/bin" >> "$GITHUB_PATH"
- name: Install MADS on Windows
if: runner.os == 'Windows'
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
New-Item -ItemType Directory -Force "$env:RUNNER_TEMP\mads-release", "$env:RUNNER_TEMP\mads" | Out-Null
$headers = @{
Authorization = "Bearer $env:GH_TOKEN"
Accept = "application/vnd.github+json"
"X-GitHub-Api-Version" = "2022-11-28"
"User-Agent" = "mads-chat-ci"
}
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/pbosetti/MADS/releases/latest" -Headers $headers
$asset = $release.assets |
Where-Object { $_.name -like "${{ matrix.mads_asset }}" } |
Select-Object -First 1
if (-not $asset) {
throw "No MADS release asset matches ${{ matrix.mads_asset }}"
}
$installer = "$env:RUNNER_TEMP\mads-release\mads.exe"
$downloadHeaders = @{
Authorization = "Bearer $env:GH_TOKEN"
Accept = "application/octet-stream"
"X-GitHub-Api-Version" = "2022-11-28"
"User-Agent" = "mads-chat-ci"
}
Invoke-WebRequest -Uri $asset.url -Headers $downloadHeaders -OutFile $installer
$installRoot = "$env:RUNNER_TEMP\mads"
$process = Start-Process `
-FilePath $installer `
-ArgumentList "/VERYSILENT", "/SUPPRESSMSGBOXES", "/NORESTART", "/SP-", "/CURRENTUSER", "/DIR=$installRoot" `
-Wait `
-PassThru
if ($process.ExitCode -ne 0) {
throw "MADS installer failed with exit code $($process.ExitCode)"
}
$agentHeader = Get-ChildItem $installRoot -Recurse -Filter agent.hpp |
Where-Object { $_.FullName -match '\\include\\agent\.hpp$' } |
Select-Object -First 1
if (-not $agentHeader) {
throw "Could not find MADS headers after running $installer"
}
$madsRoot = Split-Path (Split-Path $agentHeader.FullName -Parent) -Parent
$madsImportLibrary = Join-Path $madsRoot "lib\MadsCore.lib"
if (-not (Test-Path $madsImportLibrary)) {
throw "Could not find $madsImportLibrary"
}
"MADS_ROOT=$madsRoot" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"$madsRoot\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Configure
if: runner.os != 'Windows'
env:
CC: clang
CXX: clang++
CMAKE_OSX_ARCHITECTURES: ${{ matrix.cmake_osx_architectures }}
run: |
extra_args=()
if [ -n "${CMAKE_OSX_ARCHITECTURES:-}" ]; then
extra_args+=("-DCMAKE_OSX_ARCHITECTURES=$CMAKE_OSX_ARCHITECTURES")
fi
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="$PWD/package" \
-DMADS_ROOT="$MADS_ROOT" \
"${extra_args[@]}"
- name: Configure
if: runner.os == 'Windows'
shell: pwsh
run: |
cmake -S . -B build -G Ninja `
-DCMAKE_BUILD_TYPE=Release `
"-DCMAKE_INSTALL_PREFIX=$env:GITHUB_WORKSPACE\package" `
"-DMADS_ROOT=$env:MADS_ROOT"
- name: Build
run: cmake --build build --config Release --parallel
- name: Install
run: cmake --install build --config Release
- name: Create tarball
if: runner.os != 'Windows'
run: |
set -euo pipefail
version="${GITHUB_REF_NAME:-${GITHUB_SHA::7}}"
safe_version="$(printf '%s' "$version" | tr '/\\ ' '---')"
bundle="$RUNNER_TEMP/mads-chat-${{ matrix.package }}"
mkdir -p "$bundle/bin" dist
cp "package/bin/mads-chat" "$bundle/bin/"
cp "RELEASE_INSTALL.md" "$bundle/"
tar -czf "dist/mads-chat-${safe_version}-${{ matrix.package }}.tar.gz" -C "$bundle" .
- name: Create tarball
if: runner.os == 'Windows'
shell: pwsh
run: |
$version = if ($env:GITHUB_REF_NAME) { $env:GITHUB_REF_NAME } else { $env:GITHUB_SHA.Substring(0, 7) }
$safeVersion = $version -replace '[\\/ ]+', '-'
$bundle = "$env:RUNNER_TEMP\mads-chat-${{ matrix.package }}"
New-Item -ItemType Directory -Force "$bundle\bin", "$env:GITHUB_WORKSPACE\dist" | Out-Null
Copy-Item "$env:GITHUB_WORKSPACE\package\bin\mads-chat.exe" "$bundle\bin\"
Copy-Item "$env:GITHUB_WORKSPACE\RELEASE_INSTALL.md" "$bundle\"
tar -czf "$env:GITHUB_WORKSPACE\dist\mads-chat-$safeVersion-${{ matrix.package }}.tar.gz" -C "$bundle" .
- name: Upload tarball
uses: actions/upload-artifact@v4
with:
name: mads-chat-${{ matrix.package }}
path: dist/*.tar.gz
if-no-files-found: error
release:
name: Create GitHub release
if: startsWith(github.ref, 'refs/tags/')
needs: build
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: Download tarballs
uses: actions/download-artifact@v4
with:
pattern: mads-chat-*
path: dist
merge-multiple: true
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release create "$GITHUB_REF_NAME" dist/*.tar.gz \
--repo "$GITHUB_REPOSITORY" \
--title "$GITHUB_REF_NAME" \
--generate-notes \
--verify-tag