diff --git a/.github/workflows/notify-clet.yml b/.github/workflows/notify-clet.yml index 77e9afe0a3..84e5fb40e6 100644 --- a/.github/workflows/notify-clet.yml +++ b/.github/workflows/notify-clet.yml @@ -3,39 +3,72 @@ name: Notify clet # Fires repository_dispatch to gui-cs/clet so that every TG develop NuGet # publish and every TG release tag drives a matching clet build/publish. # See gui-cs/clet#30 and gui-cs/clet D-020 for context. +# +# Design notes: +# - The version comes from the `published-version` artifact uploaded by +# publish.yml. This is deterministic — no NuGet search-API race. +# - We then poll NuGet's flat-container API (the endpoint that +# `dotnet restore` actually hits) until the package is downloadable. +# The flat-container is updated soon after publish; the search API +# (queried by `dotnet package search`) lags by minutes, which broke +# this workflow once before — see gui-cs/clet workflow run 25406348354. +# - Channel is derived from the SemVer suffix: contains '-' ⇒ develop. on: - release: - types: [published] - # Hooks the workflow that publishes the develop NuGet. workflow_run: workflows: ["Publish Terminal.Gui to Nuget"] types: [completed] permissions: contents: read + actions: read # required to download artifacts from the triggering run jobs: notify-clet: runs-on: ubuntu-latest - # On release: always fire. - # On workflow_run: only fire on success (don't ship a clet build if the - # TG develop publish itself failed). - if: ${{ github.event_name == 'release' || github.event.workflow_run.conclusion == 'success' }} + if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - - name: Determine TG version + - name: Download published-version artifact + uses: actions/download-artifact@v4 + with: + name: published-version + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: Determine version + channel id: version run: | - if [ "${{ github.event_name }}" = "release" ]; then - echo "tg_version=${{ github.event.release.tag_name }}" >> "$GITHUB_OUTPUT" - echo "event_type=tg-released" >> "$GITHUB_OUTPUT" - else - # Develop channel. Read the just-published version straight from NuGet. - TG_VER=$(dotnet package search "Terminal.Gui" --prerelease --format json | jq -r '.searchResult[0].packages[0].latestVersion') - echo "tg_version=$TG_VER" >> "$GITHUB_OUTPUT" + TG_VER=$(cat version.txt | tr -d '[:space:]') + if [ -z "$TG_VER" ]; then + echo "::error::Empty version.txt from upstream publish workflow" + exit 1 + fi + echo "tg_version=$TG_VER" >> "$GITHUB_OUTPUT" + if [[ "$TG_VER" == *-* ]]; then echo "event_type=tg-develop-published" >> "$GITHUB_OUTPUT" + echo "Channel: develop ($TG_VER)" + else + echo "event_type=tg-released" >> "$GITHUB_OUTPUT" + echo "Channel: release ($TG_VER)" fi - - uses: peter-evans/repository-dispatch@v3 + + - name: Wait for NuGet flat-container to index the version + run: | + VER="${{ steps.version.outputs.tg_version }}" + for i in $(seq 1 60); do + if curl -fsS https://api.nuget.org/v3-flatcontainer/terminal.gui/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 + uses: peter-evans/repository-dispatch@v3 with: token: ${{ secrets.CLET_DISPATCH_PAT }} repository: gui-cs/clet diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8b61789300..51ff221a77 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -71,6 +71,21 @@ jobs: - name: Publish Terminal.Gui.${{ steps.gitversion.outputs.SemVer }} to NuGet.org run: dotnet nuget push Terminal.Gui/bin/Release/Terminal.Gui.${{ steps.gitversion.outputs.SemVer }}.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_API_KEY }} + + # Deterministic version handoff to notify-clet.yml. Avoids the NuGet + # search-API indexing lag that caused gui-cs/clet to skip TG develop.37 + # (see clet workflow run 25406348354). notify-clet.yml downloads this + # artifact via workflow_run + actions/download-artifact and then polls + # NuGet flat-container until the version is restorable. + - name: Record published version for notify-clet + run: echo "${{ steps.gitversion.outputs.SemVer }}" > version.txt + + - name: Upload published-version artifact + uses: actions/upload-artifact@v4 + with: + name: published-version + path: version.txt + retention-days: 7 # - name: Delist old NuGet packages # if: startsWith(github.ref, 'refs/tags/v')