Files
nyaterm/.github/workflows/main-snapshot.yml
T

263 lines
10 KiB
YAML

name: Main Snapshot
on:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: main-snapshot
cancel-in-progress: true
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: '0'
SNAPSHOT_TAG: main-snapshot
jobs:
prepare:
name: Resolve and test main
runs-on: ubuntu-24.04
timeout-minutes: 60
outputs:
main_sha: ${{ steps.metadata.outputs.main_sha }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Resolve main commit
id: metadata
shell: bash
run: |
set -euo pipefail
main_sha="$(git ls-remote "https://github.com/${GITHUB_REPOSITORY}.git" refs/heads/main | awk '{print $1}')"
[[ -n "${main_sha}" ]] || { echo 'failed to resolve main' >&2; exit 1; }
echo "main_sha=${main_sha}" >> "${GITHUB_OUTPUT}"
- name: Checkout main commit
uses: actions/checkout@v4
with:
ref: ${{ steps.metadata.outputs.main_sha }}
persist-credentials: false
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Resolve workspace version
id: version
shell: bash
run: |
version="$(python3 -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["workspace"]["package"]["version"])')"
echo "version=${version}" >> "${GITHUB_OUTPUT}"
- name: Verify build configuration
env:
NYATERM_GITHUB_GIST_CLIENT_ID: ${{ vars.NYATERM_GITHUB_GIST_CLIENT_ID }}
shell: bash
run: |
if [[ -z "${NYATERM_GITHUB_GIST_CLIENT_ID:-}" ]]; then
echo 'NYATERM_GITHUB_GIST_CLIENT_ID repository variable is required' >&2
exit 1
fi
- name: Set up Rust
uses: ./.github/actions/setup-rust
with:
cache-key: main-snapshot-preflight
- name: Install Linux system dependencies
uses: ./.github/actions/install-linux-deps
- name: Test workspace
run: cargo test --workspace --locked --no-fail-fast
- name: Test packaging and release helpers
run: >-
python -m unittest
scripts.tests.test_check_release_assets
scripts.tests.test_prepare_conpty
scripts.tests.test_package_native
scripts.tests.test_verify_native_package
scripts.tests.test_generate_release_metadata
scripts.tests.test_bump_version
- name: Check workflow syntax
run: >-
docker run --rm
-v "${PWD}:/repo"
-w /repo
rhysd/actionlint:1.7.7
package:
name: Package ${{ matrix.label }}
needs: prepare
runs-on: ${{ matrix.os }}
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
include:
- { label: macos-arm64, os: macos-15, target: aarch64-apple-darwin }
- { label: macos-x64, os: macos-15-intel, target: x86_64-apple-darwin }
- { label: linux-x64, os: ubuntu-22.04, target: x86_64-unknown-linux-gnu }
- { label: linux-arm64, os: ubuntu-22.04-arm, target: aarch64-unknown-linux-gnu }
- { label: windows-x64, os: windows-2025, target: x86_64-pc-windows-msvc }
- { label: windows-arm64, os: windows-2025, target: aarch64-pc-windows-msvc }
steps:
- name: Checkout main commit
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.main_sha }}
persist-credentials: false
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Set up Rust
uses: ./.github/actions/setup-rust
with:
targets: ${{ matrix.target }}
cache-key: main-snapshot-${{ matrix.target }}
cache-on-failure: 'true'
save-cache: always
- name: Install Linux system dependencies
if: runner.os == 'Linux'
uses: ./.github/actions/install-linux-deps
with:
extra_packages: curl file patchelf desktop-file-utils dpkg-dev rpm
- name: Install AppImage tooling
if: runner.os == 'Linux'
shell: bash
env:
TARGET: ${{ matrix.target }}
run: bash scripts/ci/install-appimagetool.sh "${TARGET}"
- name: Install NSIS
if: runner.os == 'Windows'
shell: pwsh
run: ./scripts/ci/install-nsis.ps1
- name: Prepare bundled ConPTY
if: runner.os == 'Windows'
run: python scripts/release/prepare_conpty.py
- name: Package native application
if: runner.os != 'Windows'
shell: bash
env:
APPIMAGE_EXTRACT_AND_RUN: ${{ runner.os == 'Linux' && '1' || '' }}
NYATERM_ARTIFACT_VERSION: main-snapshot
NYATERM_GITHUB_GIST_CLIENT_ID: ${{ vars.NYATERM_GITHUB_GIST_CLIENT_ID }}
NYATERM_VERSION: ${{ needs.prepare.outputs.version }}
TARGET: ${{ matrix.target }}
run: python scripts/release/package_native.py "${TARGET}"
- name: Package native application (Windows MSVC)
if: runner.os == 'Windows'
shell: pwsh
env:
NYATERM_ARTIFACT_VERSION: main-snapshot
NYATERM_GITHUB_GIST_CLIENT_ID: ${{ vars.NYATERM_GITHUB_GIST_CLIENT_ID }}
NYATERM_VERSION: ${{ needs.prepare.outputs.version }}
TARGET: ${{ matrix.target }}
run: |
# Git Bash prepends Git's /usr/bin/link.exe, shadowing MSVC's linker.
# Preserve the PATH configured by ilammy/msvc-dev-cmd for Rust builds.
$linker = (Get-Command link.exe -CommandType Application -ErrorAction Stop | Select-Object -First 1).Source
if ($linker -notmatch '\\VC\\Tools\\MSVC\\[^\\]+\\bin\\HostX64\\(x64|arm64)\\link\.exe$') {
throw "Expected Visual Studio MSVC linker, got: $linker"
}
Write-Host "Using MSVC linker: $linker"
python scripts/release/package_native.py "$env:TARGET"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Verify native package
shell: bash
env:
TARGET: ${{ matrix.target }}
VERSION: ${{ needs.prepare.outputs.version }}
run: >-
python scripts/release/verify_native_package.py
--target "${TARGET}" --version "${VERSION}"
--artifact-version main-snapshot --dist dist
# Run host tests even when the package contains ARM64 executables.
- name: Configure MSVC for host tests
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: amd64
- name: Test portable updater against packaged ZIP
if: runner.os == 'Windows'
shell: pwsh
env:
TARGET: ${{ matrix.target }}
run: |
$arch = if ($env:TARGET -eq 'aarch64-pc-windows-msvc') { 'arm64' } else { 'x64' }
$env:NYATERM_TEST_PORTABLE_ARCH = if ($arch -eq 'arm64') { 'aarch64' } else { 'x86_64' }
$env:NYATERM_TEST_PORTABLE_ARCHIVE = (Resolve-Path "dist/NyaTerm_main-snapshot_windows_${arch}_portable.zip").Path
cargo test -p nyaterm-desktop --lib --locked portable_release_archive_round_trip -- --ignored
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: main-snapshot-${{ matrix.label }}
path: dist/*
if-no-files-found: error
retention-days: 7
publish:
name: Publish main snapshot
needs: [prepare, package]
runs-on: ubuntu-24.04
timeout-minutes: 20
permissions:
contents: write
steps:
- name: Checkout main commit
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare.outputs.main_sha }}
persist-credentials: false
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Download package artifacts
uses: actions/download-artifact@v4
with:
pattern: main-snapshot-*
path: release-assets
merge-multiple: true
- name: Validate snapshot assets
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: >-
python3 scripts/ci/check_release_assets.py --dist release-assets
--version "${VERSION}" --artifact-version main-snapshot
- name: Move snapshot tag
shell: bash
env:
GH_TOKEN: ${{ github.token }}
MAIN_SHA: ${{ needs.prepare.outputs.main_sha }}
run: |
set -euo pipefail
if gh api "repos/${GITHUB_REPOSITORY}/git/ref/tags/${SNAPSHOT_TAG}" >/dev/null 2>&1; then
gh api --method PATCH "repos/${GITHUB_REPOSITORY}/git/refs/tags/${SNAPSHOT_TAG}" -f sha="${MAIN_SHA}" -F force=true >/dev/null
else
gh api --method POST "repos/${GITHUB_REPOSITORY}/git/refs" -f ref="refs/tags/${SNAPSHOT_TAG}" -f sha="${MAIN_SHA}" >/dev/null
fi
- name: Create or update snapshot release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
MAIN_SHA: ${{ needs.prepare.outputs.main_sha }}
run: |
set -euo pipefail
cat > release-notes.md <<EOF
Manually triggered snapshot of the main branch.
Source commit: ${MAIN_SHA}
This prerelease is overwritten after every successful snapshot build and is intended for testing only.
EOF
if gh release view "${SNAPSHOT_TAG}" --repo "${GITHUB_REPOSITORY}" >/dev/null 2>&1; then
gh release edit "${SNAPSHOT_TAG}" --repo "${GITHUB_REPOSITORY}" --title 'NyaTerm Main Snapshot' --notes-file release-notes.md --prerelease
while IFS= read -r asset; do
[[ -z "${asset}" ]] || gh release delete-asset "${SNAPSHOT_TAG}" "${asset}" --repo "${GITHUB_REPOSITORY}" --yes
done < <(gh release view "${SNAPSHOT_TAG}" --repo "${GITHUB_REPOSITORY}" --json assets --jq '.assets[].name')
else
gh release create "${SNAPSHOT_TAG}" --repo "${GITHUB_REPOSITORY}" --target "${MAIN_SHA}" --title 'NyaTerm Main Snapshot' --notes-file release-notes.md --prerelease
fi
gh release upload "${SNAPSHOT_TAG}" release-assets/* --repo "${GITHUB_REPOSITORY}" --clobber