Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 162 additions & 0 deletions .github/scripts/release_installers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
"""Daily check that the desktop installers exist (release-installers.yml).

Looks at the newest published release of the repository and at the nightly
desktop build:

* the release must carry an installer for every platform the desktop build
makes (Windows `*Setup*.exe`, macOS `.dmg`, Linux `.AppImage`). When one is
missing and no desktop build is running, the release is built again
(build-desktop-app.yaml dispatched with `release_tag`), once per release.
* the newest nightly run of build-desktop-app.yaml must not have failed, or
failed to start.

What it finds goes to the job summary and to one issue, "Desktop installers
missing", opened or updated while something is wrong and closed once all is
well. The check fails when something is wrong that no rebuild is fixing yet.

Usage: python release_installers.py <owner/repo> <default branch>
(GH_TOKEN needs contents: read, actions: write, issues: write)
"""

import json
import os
import subprocess
import sys

WORKFLOW = "build-desktop-app.yaml"
ISSUE_TITLE = "Desktop installers missing"
PLATFORMS = {
"Windows": lambda n: n.endswith(".exe") and "Setup" in n,
"macOS": lambda n: n.endswith(".dmg"),
"Linux": lambda n: n.endswith(".AppImage"),
}
FAILED = {"failure", "startup_failure", "timed_out"}


def marker(tag):
"""Hidden note in the issue that a rebuild of `tag` was started."""
return f"<!-- rebuilt: {tag} -->"


def missing_platforms(asset_names):
"""Platforms without an installer among a release's asset names."""
return [p for p, match in PLATFORMS.items() if not any(match(n) for n in asset_names)]


def newest_release(releases):
"""The newest published release (prereleases count, drafts do not)."""
published = [r for r in releases if not r.get("draft") and r.get("published_at")]
return max(published, key=lambda r: r["published_at"], default=None)


def desktop_build_busy(runs):
"""Whether a release or manual desktop build is queued or running."""
return any(
r["status"] != "completed" and r["event"] in ("release", "workflow_dispatch")
for r in runs
)


def nightly_failed(runs):
"""The newest nightly run, when it failed (or failed to start)."""
nightly = [r for r in runs if r["event"] == "schedule"]
if nightly and nightly[0]["status"] == "completed" and nightly[0]["conclusion"] in FAILED:
return nightly[0]
return None


def rebuild_title(tag):
"""The run name of a desktop build that rebuilds the release `tag`."""
return f"Rebuild installers of {tag}"


def rebuilt(tag, runs, issue_body):
"""Whether the release `tag` was already rebuilt once (issue note or run)."""
return marker(tag) in (issue_body or "") or any(
r.get("event") == "workflow_dispatch" and r.get("display_title") == rebuild_title(tag)
for r in runs)


def plan(release, runs, issue_body):
"""What to report and whether to start a rebuild.

Returns (problems, rebuild, failing): lines for the report, the tag to
rebuild (or None), and whether the check should fail.
"""
problems, rebuild, failing = [], None, False
if release:
tag = release["tag_name"]
missing = missing_platforms([a["name"] for a in release.get("assets", [])])
if missing:
where = f"[{tag}]({release['html_url']})"
if desktop_build_busy(runs):
problems.append(f"{where} has no installer for {', '.join(missing)} yet; a desktop build is running.")
elif rebuilt(tag, runs, issue_body):
problems.append(f"{where} has no installer for {', '.join(missing)}, and its rebuild did not attach them. See the desktop build runs.")
failing = True
else:
problems.append(f"{where} has no installer for {', '.join(missing)}; its installers are being built again.")
rebuild = tag
failed = nightly_failed(runs)
if failed:
problems.append(f"The nightly desktop build [{failed['conclusion'].replace('_', ' ')}]({failed['html_url']}).")
failing = True
return problems, rebuild, failing


def gh(*args, data=None):
out = subprocess.run(
["gh", "api", *args], check=True, capture_output=True, text=True,
input=json.dumps(data) if data is not None else None,
).stdout
return json.loads(out) if out.strip() else None


def main(repo, branch):
releases = gh(f"repos/{repo}/releases?per_page=30")
# Releases, rebuilds and manual runs; pull request runs could push them
# off the page, so they are asked for by event.
runs = []
for event in ("schedule", "release", "workflow_dispatch"):
runs += gh(f"repos/{repo}/actions/workflows/{WORKFLOW}/runs?event={event}&per_page=30")["workflow_runs"]
runs.sort(key=lambda r: r["created_at"], reverse=True)
issues = gh(f"repos/{repo}/issues?state=open&per_page=100")
issue = next((i for i in issues if i["title"] == ISSUE_TITLE and "pull_request" not in i), None)

release = newest_release(releases)
problems, rebuild, failing = plan(release, runs, (issue["body"] or "") if issue else "")

if rebuild:
gh("-X", "POST", f"repos/{repo}/actions/workflows/{WORKFLOW}/dispatches", "--input", "-",
data={"ref": branch, "inputs": {"release_tag": rebuild}})

summary = os.environ.get("GITHUB_STEP_SUMMARY")
text = "\n".join(f"- {p}" for p in problems) or (
f"Every desktop installer of {release['tag_name']} is there." if release else "No release yet.")
if summary:
with open(summary, "a", encoding="utf-8") as f:
f.write(text + "\n")
print(text)

if problems:
notes = ((issue["body"] or "") if issue else "").split("\n")
kept = [n for n in notes if n.startswith("<!-- rebuilt: ")]
if rebuild:
kept.append(marker(rebuild))
body = (
"The daily check (`release-installers.yml`) found:\n\n" + text +
"\n\nIt closes this issue once the newest release has every installer and the nightly desktop build works.\n\n" +
"\n".join(kept)
)
if issue:
gh("-X", "PATCH", f"repos/{repo}/issues/{issue['number']}", "--input", "-", data={"body": body})
else:
gh("-X", "POST", f"repos/{repo}/issues", "--input", "-", data={"title": ISSUE_TITLE, "body": body})
elif issue:
gh("-X", "POST", f"repos/{repo}/issues/{issue['number']}/comments", "--input", "-", data={"body": text})
gh("-X", "PATCH", f"repos/{repo}/issues/{issue['number']}", "--input", "-", data={"state": "closed"})
return 1 if failing else 0


if __name__ == "__main__":
sys.exit(main(sys.argv[1], sys.argv[2]))
32 changes: 24 additions & 8 deletions .github/workflows/build-desktop-app.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
name: Build desktop app
run-name: ${{ inputs.release_tag && format('Rebuild installers of {0}', inputs.release_tag) || github.event.pull_request.title || github.event.release.name || github.workflow }}
# One run builds the Electron app for Windows, macOS (Apple Silicon) and Linux,
# and a release gets all installers attached.
#
# The macOS job takes 35-45 minutes on a runner pool shared by every OpenMS
# repository, so the full build runs only where it can find something new:
# release, manual run always
# release, manual run always (a manual run with `release_tag` builds that
# release's tag and attaches its installers, as a
# release does; release-installers.yml starts one daily
# for a release whose installers are missing)
# nightly when the default branch moved since the last successful build
# pull request when it changes packaging (electron/, this workflow,
# openms.yml, requirements, settings.json, app.py) or
Expand All @@ -30,6 +34,10 @@ on:
description: 'OpenMS for this run: a release ("3.5.0") or "[owner/repo@]ref" to build. Empty uses the default below.'
type: string
default: ""
release_tag:
description: 'Build this release again from its tag and attach the installers to it, e.g. v2.6.0. Empty builds the branch.'
type: string
default: ""

permissions:
contents: read
Expand All @@ -39,7 +47,7 @@ permissions:
# Adding some other label to a PR gets a group of its own, so it never cancels
# a build that is running.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}${{ github.event.action == 'labeled' && github.event.label.name != 'desktop-build' && '-label' || '' }}
group: ${{ github.workflow }}-${{ github.ref }}${{ inputs.release_tag && format('-{0}', inputs.release_tag) || '' }}${{ github.event.action == 'labeled' && github.event.label.name != 'desktop-build' && '-label' || '' }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

env:
Expand Down Expand Up @@ -70,6 +78,7 @@ jobs:
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
ref: ${{ inputs.release_tag && format('refs/tags/{0}', inputs.release_tag) || '' }}
sparse-checkout: app.yaml
sparse-checkout-cone-mode: false
- id: decide
Expand All @@ -80,15 +89,20 @@ jobs:
LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
ACTION: ${{ github.event.action }}
ADDED: ${{ github.event.label.name }}
RELEASE_TAG: ${{ inputs.release_tag }}
run: |
set -euo pipefail
if [ -n "$RELEASE_TAG" ] && ! gh api "repos/$GITHUB_REPOSITORY/releases/tags/$RELEASE_TAG" --jq .tag_name >/dev/null; then
echo "::error::no release with the tag $RELEASE_TAG"
exit 1
fi
run=false
case "$EVENT" in
release|workflow_dispatch) run=true ;;
schedule)
head=$GITHUB_SHA
last=$(gh api "repos/$GITHUB_REPOSITORY/actions/workflows/build-desktop-app.yaml/runs?status=success&per_page=20" \
--jq '[.workflow_runs[] | select(.event != "pull_request")][0].head_sha // ""')
--jq '[.workflow_runs[] | select(.event == "schedule")][0].head_sha // ""')
[ "$head" != "$last" ] && run=true || echo "main unchanged since the last successful build"
;;
pull_request)
Expand Down Expand Up @@ -180,6 +194,7 @@ jobs:
- name: Checkout
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
ref: ${{ inputs.release_tag && format('refs/tags/{0}', inputs.release_tag) || '' }}
persist-credentials: false

- name: Take the app's values from app.yaml
Expand All @@ -192,7 +207,7 @@ jobs:

- name: Set version and offline deployment in settings.json
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_TAG: ${{ github.event.release.tag_name || inputs.release_tag }}
run: |
# Only release builds carry a tag; other builds keep settings.json's
# version. The tag's version without its prefix (`OpenDDA-1.3.0` is
Expand Down Expand Up @@ -267,7 +282,7 @@ jobs:
with:
node-version: '22'
# Release installers are built from a clean npm install, without a restored cache.
cache: ${{ github.event_name != 'release' && 'npm' || '' }}
cache: ${{ github.event_name != 'release' && !inputs.release_tag && 'npm' || '' }}
cache-dependency-path: electron/package-lock.json

- name: Install Electron dependencies
Expand All @@ -281,7 +296,7 @@ jobs:
# notarized dmg on macOS, an AppImage on Linux (electron/scripts/package.sh).
id: package
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_TAG: ${{ github.event.release.tag_name || inputs.release_tag }}
INSTALLER_VERSION: ${{ needs.scope.outputs.installer_version }}
SYNOPSIS: ${{ needs.scope.outputs.synopsis }}
MACOS_CERTIFICATE: ${{ secrets.MACOS_CERTIFICATE }}
Expand Down Expand Up @@ -389,6 +404,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.release_tag && format('refs/tags/{0}', inputs.release_tag) || '' }}
persist-credentials: false

- name: Download the OpenMS build (Windows)
Expand Down Expand Up @@ -537,7 +553,7 @@ jobs:
# The app's installers do not wait for the command line tools: a release
# gets those only when they were packaged and, built from a branch, passed
# their test.
if: github.event_name == 'release' && !cancelled() && needs.build.result == 'success'
if: (github.event_name == 'release' || inputs.release_tag) && !cancelled() && needs.build.result == 'success'
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -559,7 +575,7 @@ jobs:
- name: Upload installers as release assets
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_TAG: ${{ github.event.release.tag_name || inputs.release_tag }}
run: gh release upload "$RELEASE_TAG" dist/* --clobber -R "$GITHUB_REPOSITORY"

# The release's container images, built after its installers are attached
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/release-installers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Check every day that the desktop installers exist.
#
# Runs in the template and in every app made from it. The newest published
# release must carry an installer for Windows, macOS and Linux, and the newest
# nightly run of build-desktop-app.yaml must not have failed. A release that
# lacks installers is built again once (build-desktop-app.yaml dispatched with
# its tag, which attaches them); whatever is still wrong is listed in one issue,
# "Desktop installers missing", which is closed once all is well, and fails
# this check. The logic is .github/scripts/release_installers.py.
#
# An app without desktop installers (`deploy.desktop: []` in app.yaml) skips it.
name: Release installers

on:
schedule:
- cron: "23 7 * * *" # daily, 07:23 UTC, after the nightly desktop build
workflow_dispatch:

permissions:
contents: read

concurrency:
group: release-installers
cancel-in-progress: false

jobs:
check:
runs-on: ubuntu-latest
permissions:
contents: read
actions: write
issues: write
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
sparse-checkout: |
app.yaml
.github/scripts/release_installers.py
sparse-checkout-cone-mode: false
- name: Check the installers
env:
GH_TOKEN: ${{ github.token }}
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
run: |
set -euo pipefail
if [ -f app.yaml ] && [ "$(yq -o=json -I=0 '.deploy.desktop' app.yaml)" = "[]" ]; then
echo "deploy.desktop is empty in app.yaml: no desktop installers to check" >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
python3 .github/scripts/release_installers.py "$GITHUB_REPOSITORY" "$DEFAULT_BRANCH"
Loading
Loading