Files
OrcaSlicer/.github/workflows/publish_release.yml
T
SoftFever 66fea0a150 Publish the Microsoft Store package from the release workflow (#18025)
Maintainers can tick "msstore_only" when running "Publish to draft release" to
send a build's x64 and arm64 MSIX packages to the Microsoft Store as one
submission, instead of uploading them in Partner Center by hand. With the
option off, the GitHub draft release is published as before.
2026-11-30 17:08:54 +08:00

269 lines
13 KiB
YAML

name: Publish to draft release
# Manually pulls the platform binaries produced by a "Build all" run and uploads
# them to an existing DRAFT release. Decoupled from the build so you can test a
# build first, then publish exactly that run's artifacts once you're happy.
# It also writes an ordered download table into the draft's release notes.
#
# With "msstore_only" ticked it instead sends that run's MSIX packages to the
# Microsoft Store and leaves the GitHub release alone (see the msstore job).
#
# Trigger: Actions tab -> "Publish to draft release" -> Run workflow.
# Locked to named publishers: the first step aborts unless the actor is one of the
# logins in the `RELEASE_PUBLISHER` repo variable, a comma-separated list. To
# change who may publish, set that variable:
# gh variable set RELEASE_PUBLISHER --body "<login>,<login>"
on:
workflow_dispatch:
inputs:
run_id:
description: 'Run ID of the "Build all" workflow to pull binaries from (the number in the Actions run URL)'
required: true
type: string
tag:
description: 'Tag of the draft release to upload to (e.g. v2.4.0-beta); not needed with msstore_only'
required: false
type: string
msstore_only:
description: 'Publish only the MSIX packages to the Microsoft Store, skipping the GitHub draft release'
required: false
type: boolean
default: false
permissions:
contents: write # upload release assets
actions: read # download artifacts from another run
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RUN_ID: ${{ inputs.run_id }}
jobs:
preflight:
name: Check publisher and source build
runs-on: ubuntu-latest
steps:
- name: Restrict to the release publishers
env:
PUBLISHERS: ${{ vars.RELEASE_PUBLISHER }}
run: |
if [ -z "$PUBLISHERS" ]; then
echo "::error::RELEASE_PUBLISHER repo variable is not set."
exit 1
fi
# Pad the space-separated list so only whole logins match.
if [[ " ${PUBLISHERS//,/ } " != *" ${{ github.actor }} "* ]]; then
echo "::error::Only $PUBLISHERS may run this workflow (you are @${{ github.actor }})."
exit 1
fi
echo "Authorized: @${{ github.actor }}"
- name: Verify source build run
run: |
info=$(gh run view "$RUN_ID" --repo "$GITHUB_REPOSITORY" --json workflowName,conclusion,headBranch)
name=$(echo "$info" | jq -r '.workflowName')
conclusion=$(echo "$info" | jq -r '.conclusion')
branch=$(echo "$info" | jq -r '.headBranch')
echo "Source run #$RUN_ID: '$name' on '$branch' (conclusion: $conclusion)"
if [ "$conclusion" != "success" ]; then
echo "::warning::Source run did not conclude 'success' ($conclusion). Some assets may be missing."
fi
publish:
name: Publish binaries to draft release
needs: preflight
if: ${{ !inputs.msstore_only }}
runs-on: ubuntu-latest
env:
TAG: ${{ inputs.tag }}
steps:
- name: Verify target is a draft release
run: |
if [ -z "$TAG" ]; then
echo "::error::Set the tag of the draft release to upload to."
exit 1
fi
if ! gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json isDraft >/dev/null 2>&1; then
echo "::error::Release '$TAG' not found. Create the draft (with this tag) first."
exit 1
fi
is_draft=$(gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json isDraft --jq '.isDraft')
if [ "$is_draft" != "true" ]; then
echo "::error::Release '$TAG' is published, not a draft. Aborting to avoid touching a live release."
exit 1
fi
- name: Download release artifacts from build run
run: |
# Windows_V* (not Windows_*) keeps the MSIX Store artifact out: the msstore job sends it to the Store, not GitHub releases.
gh run download "$RUN_ID" --repo "$GITHUB_REPOSITORY" --dir artifacts \
-p 'OrcaSlicer_Windows_V*' \
-p 'OrcaSlicer_Mac_universal_*' \
-p 'OrcaSlicer_Linux_ubuntu_*' \
-p 'OrcaSlicer-Linux-flatpak_*' \
-p 'PDB'
echo "Downloaded artifact folders:"
ls -1 artifacts
- name: Assemble release assets
run: |
set -euo pipefail
mkdir -p upload
# gh run download auto-extracts each artifact into a folder, so the inner
# binaries are already unzipped. Copy the inner binary for each platform.
# -type f is required (some artifact *folders* are named "*.flatpak").
# Windows installers (x64 + arm64): the .exe inside each installer
# artifact, NOT the orca-slicer.exe in the portable app folder. CPack
# now bakes the arch into the filename (…_x64.exe / …_arm64.exe), so
# copy them straight through.
find artifacts -type f -name '*.exe' -path '*OrcaSlicer_Windows_V*' ! -path '*_portable*' -exec cp -v {} upload/ \;
# macOS universal DMG (profile-validator DMG isn't downloaded).
find artifacts -type f -name '*.dmg' -path '*OrcaSlicer_Mac_universal_*' -exec cp -v {} upload/ \;
# Linux AppImage.
find artifacts -type f -name '*.AppImage' -exec cp -v {} upload/ \;
# Flatpak bundles (x86_64 + aarch64).
find artifacts -type f -name '*.flatpak' -exec cp -v {} upload/ \;
# Windows debug symbols (PDB archive, for developers).
find artifacts -type f -name 'Debug_PDB_*.7z' -exec cp -v {} upload/ \;
# Portable Windows builds (x64 + arm64) are unzipped folder artifacts;
# re-zip each to its released filename (these stay .zip on the release).
mapfile -t portable_dirs < <(find artifacts -maxdepth 1 -type d -name 'OrcaSlicer_Windows_*_portable')
if [ ${#portable_dirs[@]} -eq 0 ]; then
echo "::warning::Windows portable artifact not found."
fi
for portable_dir in "${portable_dirs[@]}"; do
( cd "$portable_dir" && zip -qr "$GITHUB_WORKSPACE/upload/$(basename "$portable_dir").zip" . )
echo "Zipped portable -> $(basename "$portable_dir").zip"
done
echo "Assets to upload:"
ls -lh upload
if [ -z "$(ls -A upload)" ]; then
echo "::error::No assets assembled. Check the run_id and that its artifacts haven't expired."
exit 1
fi
- name: Upload assets to draft release
run: |
gh release upload "$TAG" upload/* --repo "$GITHUB_REPOSITORY" --clobber
echo "Uploaded to draft release: $TAG"
gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name'
# GitHub lists release assets alphabetically by filename whatever order they
# are uploaded in, so the platform order users see comes from this table in
# the release notes. The table sits between the two markers: a rerun
# replaces it in place, and notes without markers get it appended. Text
# outside the markers is kept. Links use the tag's download URL, which only
# resolves once the draft is published.
- name: Write download table into release notes
run: |
set -euo pipefail
start='<!-- downloads:start -->'
end='<!-- downloads:end -->'
# Sort key and label of an asset, in the order the table lists them.
describe() {
case "$1" in
*Windows_Installer_*_x64.exe) echo "01|Windows installer (x64)" ;;
*Windows_Installer_*_arm64.exe) echo "02|Windows installer (ARM64)" ;;
*_x64_portable.zip) echo "03|Windows portable (x64)" ;;
*_arm64_portable.zip) echo "04|Windows portable (ARM64)" ;;
*.dmg) echo "05|macOS (Apple Silicon and Intel)" ;;
*_aarch64_*.AppImage) echo "07|Linux AppImage (aarch64)" ;;
*.AppImage) echo "06|Linux AppImage (x86_64)" ;;
*_x86_64.flatpak) echo "08|Linux Flatpak (x86_64)" ;;
*_aarch64.flatpak) echo "09|Linux Flatpak (aarch64)" ;;
Debug_PDB_*) echo "10|Windows debug symbols (for developers)" ;;
*) echo "99|$1" ;;
esac
}
{
echo "$start"
echo
echo "## Downloads"
echo
echo "| Platform | File |"
echo "| --- | --- |"
gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json assets --jq '.assets[].name' | while read -r name; do
echo "$(describe "$name")|$name"
done | sort | while IFS='|' read -r _ label name; do
echo "| $label | [$name](https://github.com/$GITHUB_REPOSITORY/releases/download/$TAG/$name) |"
done
echo
echo "$end"
} > table.md
gh release view "$TAG" --repo "$GITHUB_REPOSITORY" --json body --jq '.body' > notes.md
starts=$(grep -cF "$start" notes.md || true)
ends=$(grep -cF "$end" notes.md || true)
if [ "$starts" -ne "$ends" ] || [ "$starts" -gt 1 ]; then
echo "::error::The release notes must contain each download-table marker exactly once, or neither. Fix them by hand and rerun."
exit 1
fi
if [ "$starts" -eq 1 ]; then
awk -v start="$start" -v end="$end" '
index($0, start) { while ((getline line < "table.md") > 0) print line; skip = 1; next }
index($0, end) { skip = 0; next }
!skip
END { exit skip }
' notes.md > notes.new || { echo "::error::The download-table end marker must be on its own line, after the start marker."; exit 1; }
else
{ cat notes.md; echo; cat table.md; } > notes.new
fi
gh release edit "$TAG" --repo "$GITHUB_REPOSITORY" --notes-file notes.new
cat table.md
# The Store gets one bundle holding both architectures: msstore publish starts a
# new submission from the last published one and swaps in only the package of the
# same file type, so the x64 and arm64 packages have to travel together. It
# first deletes any pending submission, and fails if Partner Center refuses to.
# Credentials come from the PARTNER_CENTER_* secrets of the Microsoft Entra app
# linked to the Partner Center account; MSSTORE_PRODUCT_ID is the app's Store ID.
msstore:
name: Publish MSIX to the Microsoft Store
needs: preflight
if: ${{ inputs.msstore_only }}
runs-on: windows-latest
permissions:
actions: read # download artifacts from another run
steps:
- name: Download MSIX packages from build run
run: gh run download $env:RUN_ID --repo $env:GITHUB_REPOSITORY --dir artifacts -p 'OrcaSlicer_Windows_MSIX_*'
- name: Bundle the packages
run: |
$packages = Get-ChildItem artifacts -Recurse -Filter *.msix
foreach ($arch in 'x64', 'arm64') {
if (-not ($packages | Where-Object Name -like "*_$arch.msix")) {
throw "The $arch MSIX package is missing from run $env:RUN_ID."
}
}
New-Item -ItemType Directory bundle_in | Out-Null
$packages | Copy-Item -Destination bundle_in
$makeappx = Get-ChildItem "${env:ProgramFiles(x86)}\Windows Kits\10\bin\10.*\x64\makeappx.exe" |
Sort-Object { [version]$_.Directory.Parent.Name } -Descending |
Select-Object -First 1 -ExpandProperty FullName
& $makeappx bundle /d bundle_in /p OrcaSlicer.msixbundle /o
if ($LASTEXITCODE -ne 0) { throw "makeappx bundle failed with exit code $LASTEXITCODE" }
- name: Install the Microsoft Store CLI
uses: microsoft/microsoft-store-apppublisher@v1.4
- name: Publish the bundle to the Microsoft Store
env:
TENANT_ID: ${{ secrets.PARTNER_CENTER_TENANT_ID }}
SELLER_ID: ${{ secrets.PARTNER_CENTER_SELLER_ID }}
CLIENT_ID: ${{ secrets.PARTNER_CENTER_CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.PARTNER_CENTER_CLIENT_SECRET }}
PRODUCT_ID: ${{ vars.MSSTORE_PRODUCT_ID }}
run: |
if (-not $env:PRODUCT_ID) { throw "MSSTORE_PRODUCT_ID repo variable is not set." }
$PSNativeCommandUseErrorActionPreference = $true
msstore reconfigure --tenantId $env:TENANT_ID --sellerId $env:SELLER_ID --clientId $env:CLIENT_ID --clientSecret $env:CLIENT_SECRET
msstore publish OrcaSlicer.msixbundle -id $env:PRODUCT_ID