Skip to content

Merge pull request #218 from gui-cs/backmerge/v2.2.5 #166

Merge pull request #218 from gui-cs/backmerge/v2.2.5

Merge pull request #218 from gui-cs/backmerge/v2.2.5 #166

Workflow file for this run

name: Release
# Publishes Terminal.Gui.Editor to NuGet.
#
# Triggers:
# 1. Push of a `v*` tag (canonical release path, e.g. v2.1.0)
# → Version = tag with leading `v` stripped.
# 2. Push to `develop` (rolling pre-release smoke test)
# → Version = <Version> from Directory.Build.props + ".<github.run_number>"
# e.g. 2.1.1-develop.7
#
# The package version is declared in Directory.Build.props.
# The computed value overrides that base via `-p:Version=...`.
on:
push:
tags: ['v*']
branches: [develop]
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
jobs:
resolve-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.v.outputs.version }}
steps:
- uses: actions/checkout@v5
- name: Compute version
id: v
shell: bash
run: |
if [ "${{ github.ref_type }}" = "tag" ]; then
# Tag form: v2.1.0 → 2.1.0
VERSION="${GITHUB_REF_NAME#v}"
elif [ "${{ github.ref }}" = "refs/heads/develop" ]; then
# Read base from Directory.Build.props (e.g. "2.1.1-develop"), append run number.
BASE=$(sed -n 's|.*<Version>\(.*\)</Version>.*|\1|p' Directory.Build.props | head -1)
if [ -z "$BASE" ]; then
echo "::error::Could not read <Version> from Directory.Build.props."
exit 1
fi
VERSION="${BASE}.${GITHUB_RUN_NUMBER}"
else
echo "::error::Unsupported trigger: event=${{ github.event_name }} ref=${{ github.ref }}"
exit 1
fi
if [ -z "$VERSION" ]; then
echo "::error::Could not resolve version."
exit 1
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "## Release" >> "$GITHUB_STEP_SUMMARY"
echo "- version: \`$VERSION\`" >> "$GITHUB_STEP_SUMMARY"
echo "- trigger: \`${{ github.event_name }}\` (\`${{ github.ref }}\`)" >> "$GITHUB_STEP_SUMMARY"
build-and-test:
needs: resolve-version
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
env:
VERSION: ${{ needs.resolve-version.outputs.version }}
# Tells Terminal.Gui drivers to skip real-terminal probing/IO
# so the ANSI driver runs on Windows runners without a TTY.
DisableRealDriverIO: "1"
steps:
- uses: actions/checkout@v5
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
dotnet-quality: 'preview'
- name: Restore
run: dotnet restore Terminal.Gui.Editor.slnx
- name: Build
run: dotnet build Terminal.Gui.Editor.slnx --no-restore -c Release -p:Version=${{ env.VERSION }}
- name: Terminal.Gui.Editor.Tests
run: dotnet run --project tests/Terminal.Gui.Editor.Tests --no-build -c Release
- name: Terminal.Gui.Editor.IntegrationTests
run: dotnet run --project tests/Terminal.Gui.Editor.IntegrationTests --no-build -c Release
pack-and-publish:
needs: [resolve-version, build-and-test]
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.resolve-version.outputs.version }}
steps:
- uses: actions/checkout@v5
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
dotnet-quality: 'preview'
- name: Pack Terminal.Gui.Editor
run: dotnet pack src/Terminal.Gui.Editor -c Release -p:Version=${{ env.VERSION }} -o packages/
- name: Upload packages
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: packages/*.nupkg
retention-days: 30
- name: Push to NuGet
run: >
dotnet nuget push packages/*.nupkg
--api-key ${{ secrets.NUGET_API_KEY }}
--source https://api.nuget.org/v3/index.json
--skip-duplicate
# Notify downstream repos (gui-cs/clet) so they can rebuild against the new Editor version.
# Uses a PAT stored as CLET_DISPATCH_TOKEN with `repo` scope on gui-cs/clet.
notify-downstream:
needs: [resolve-version, pack-and-publish]
runs-on: ubuntu-latest
continue-on-error: true # Non-blocking: missing secret shouldn't fail the release
env:
VERSION: ${{ needs.resolve-version.outputs.version }}
CLET_DISPATCH_TOKEN: ${{ secrets.CLET_DISPATCH_TOKEN }}
steps:
- name: Skip dispatch (no token configured)
if: ${{ env.CLET_DISPATCH_TOKEN == '' }}
run: echo "::warning::CLET_DISPATCH_TOKEN is not set; skipping downstream dispatch."
- name: Wait for NuGet flat-container to index the version
if: ${{ env.CLET_DISPATCH_TOKEN != '' }}
run: |
VER="${{ env.VERSION }}"
for i in $(seq 1 60); do
if curl -fsS https://api.nuget.org/v3-flatcontainer/terminal.gui.editor/index.json \
| jq -r '.versions[]' | grep -qx "$VER"; then
echo "Indexed on flat-container: $VER (after $((i*10))s)"
exit 0
fi
echo "Waiting for $VER on NuGet flat-container ($i/60, 10s each)..."
sleep 10
done
echo "::error::Timed out after 10min waiting for $VER on flat-container"
exit 1
- name: Dispatch to gui-cs/clet
if: ${{ env.CLET_DISPATCH_TOKEN != '' }}
uses: actions/github-script@v7
with:
github-token: ${{ env.CLET_DISPATCH_TOKEN }}
script: |
const ref = context.ref;
const isMain = ref === 'refs/heads/main' || ref.startsWith('refs/tags/v');
const isDevelop = ref === 'refs/heads/develop';
const eventType = isMain ? 'editor-main-published' : isDevelop ? 'editor-develop-published' : null;
if (!eventType) {
console.log(`Skipping downstream dispatch for ref=${ref}`);
return;
}
await github.rest.repos.createDispatchEvent({
owner: 'gui-cs',
repo: 'clet',
event_type: eventType,
client_payload: { tge_version: process.env.VERSION }
});
console.log(`Dispatched ${eventType} with tge_version=${process.env.VERSION} to gui-cs/clet`);
notify-failure:
needs: [resolve-version, build-and-test, pack-and-publish]
if: failure()
runs-on: ubuntu-latest
permissions:
issues: write
env:
VERSION: ${{ needs.resolve-version.outputs.version }}
steps:
- uses: actions/github-script@v7
with:
script: |
await github.rest.issues.create ({
owner: context.repo.owner,
repo: context.repo.repo,
title: `Release v${process.env.VERSION} failed`,
body: `The release workflow for \`${process.env.VERSION}\` failed.\n\nSee [workflow run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}) for details.`,
labels: ['release-failure']
});