-
Notifications
You must be signed in to change notification settings - Fork 4
fix: prevent install/update 404 on releases caught mid-publish #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| name: Promote release | ||
|
|
||
| # Platform build workflows (windows-installer, linux-installer, | ||
| # release-pythinker-cli) create the GitHub Release as a PRERELEASE so it stays | ||
| # out of the date-based /releases/latest endpoint (which ignores make_latest) | ||
| # until every asset has uploaded. This workflow waits for all expected assets, | ||
| # then clears `prerelease` and marks the release latest — the single point | ||
| # where a version becomes resolvable by the install scripts and in-app updater. | ||
| # | ||
| # It runs on the tag push (not `release: published`, which a GITHUB_TOKEN-created | ||
| # release never fires) so promotion always happens. workflow_dispatch allows a | ||
| # manual re-promote, e.g. after re-running a single platform build that | ||
| # re-marked the release as prerelease. | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "v[0-9]+.[0-9]+.[0-9]+" | ||
| workflow_dispatch: | ||
| inputs: | ||
| tag: | ||
| description: "Release tag to promote (e.g. v0.25.0)" | ||
| required: true | ||
| type: string | ||
|
|
||
| # Serialize promotion per tag so a tag push and a manual re-promote can't race. | ||
| concurrency: | ||
| group: promote-release-${{ inputs.tag || github.ref_name }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| promote: | ||
| runs-on: ubuntu-latest | ||
| # Only this job mutates the release; notify-failure stays read-only. | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Resolve and validate tag | ||
| id: tag | ||
| env: | ||
| REF_NAME: ${{ github.ref_name }} | ||
| INPUT_TAG: ${{ inputs.tag }} | ||
| EVENT_NAME: ${{ github.event_name }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [ "$EVENT_NAME" = "workflow_dispatch" ]; then | ||
| tag="$INPUT_TAG" | ||
| else | ||
| tag="$REF_NAME" | ||
| fi | ||
| # Defend against injection: only ever act on a strict vMAJOR.MINOR.PATCH tag. | ||
| if ! printf '%s' "$tag" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+$'; then | ||
| echo "::error::Refusing to promote: invalid tag '$tag'" | ||
| exit 1 | ||
| fi | ||
| echo "tag=$tag" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Wait for all release assets | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| TAG: ${{ steps.tag.outputs.tag }} | ||
| REPO: ${{ github.repository }} | ||
| run: | | ||
| set -euo pipefail | ||
| required=( | ||
| "PythinkerSetup-" | ||
| "_amd64.deb" | ||
| "_arm64.deb" | ||
| ".x86_64.rpm" | ||
| ".aarch64.rpm" | ||
| "x86_64-unknown-linux-gnu.tar.gz" | ||
| "aarch64-unknown-linux-gnu.tar.gz" | ||
| "aarch64-apple-darwin.tar.gz" | ||
| "x86_64-apple-darwin.tar.gz" | ||
| ) | ||
| echo "Polling for all release assets on $TAG..." | ||
| all_present=false | ||
| for i in $(seq 1 40); do | ||
| assets=$(gh api "repos/$REPO/releases/tags/$TAG" --jq '[.assets[].name] | join(" ")' 2>/dev/null || echo "") | ||
| all_present=true | ||
| for p in "${required[@]}"; do | ||
| if [[ "$assets" != *"$p"* ]]; then | ||
| all_present=false | ||
| break | ||
| fi | ||
| done | ||
| if [[ "$all_present" == "true" ]]; then | ||
| echo "All assets present (attempt $i)" | ||
| break | ||
| fi | ||
| echo "Attempt $i/40: assets not ready, retrying in 30s..." | ||
| sleep 30 | ||
| done | ||
| if [[ "$all_present" != "true" ]]; then | ||
| echo "::error::Release assets not fully uploaded after 20 minutes" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Promote release (clear prerelease, mark latest) | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| TAG: ${{ steps.tag.outputs.tag }} | ||
| REPO: ${{ github.repository }} | ||
| run: | | ||
| set -euo pipefail | ||
| release_id=$(gh api "repos/$REPO/releases/tags/$TAG" --jq '.id') | ||
| gh api -X PATCH "repos/$REPO/releases/$release_id" -F prerelease=false -f make_latest=true | ||
| echo "Promoted $TAG: prerelease=false, make_latest=true (all platform assets present)." | ||
|
|
||
| - name: Trigger pythinker-home sync | ||
| env: | ||
| DISPATCH_TOKEN: ${{ secrets.PYTHINKER_HOME_REPO_DISPATCH_TOKEN }} | ||
| SOURCE_REPO: ${{ github.repository }} | ||
| RELEASE_TAG: ${{ steps.tag.outputs.tag }} | ||
| run: | | ||
| set -euo pipefail | ||
| if [ -z "${DISPATCH_TOKEN:-}" ]; then | ||
| echo "::notice::Skipping pythinker-home sync: PYTHINKER_HOME_REPO_DISPATCH_TOKEN is not configured" | ||
| exit 0 | ||
| fi | ||
| payload=$(jq -n \ | ||
| --arg source_repo "$SOURCE_REPO" \ | ||
| --arg tag "$RELEASE_TAG" \ | ||
| '{"event_type":"sync-pythinker-products","client_payload":{"source_repo":$source_repo,"tag":$tag}}') | ||
| curl --fail-with-body \ | ||
| -X POST \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "Authorization: Bearer $DISPATCH_TOKEN" \ | ||
| https://api.github.com/repos/TechMatrix-labs/pythinker-home/dispatches \ | ||
| -d "$payload" | ||
|
|
||
| notify-failure: | ||
| name: Notify on failure | ||
| runs-on: ubuntu-latest | ||
| needs: promote | ||
| if: failure() | ||
| permissions: | ||
| contents: read | ||
| steps: | ||
| - name: Post Slack alert | ||
| env: | ||
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} | ||
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | ||
| REPO: ${{ github.repository }} | ||
| TAG: ${{ inputs.tag || github.ref_name }} | ||
| run: | | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| set -euo pipefail | ||
| if [ -z "${SLACK_WEBHOOK_URL:-}" ]; then | ||
| exit 0 | ||
| fi | ||
| payload=$(jq -n \ | ||
| --arg run_url "$RUN_URL" \ | ||
| --arg repo "$REPO" \ | ||
| --arg tag "$TAG" \ | ||
| '{"text":":red_circle: *Release promotion failed*","attachments":[{"color":"danger","fields":[{"title":"Repo","value":$repo,"short":true},{"title":"Tag","value":$tag,"short":true},{"title":"Run","value":"<\($run_url)|View logs>","short":false}]}]}') | ||
| curl --fail-with-body -X POST \ | ||
| -H "Content-Type: application/json" \ | ||
| -d "$payload" \ | ||
| "$SLACK_WEBHOOK_URL" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.