From b5837d92f17fa2806ccb2f2b4432c473de2d07f7 Mon Sep 17 00:00:00 2001 From: tomas Date: Wed, 25 Nov 2026 20:20:45 +0000 Subject: [PATCH 1/5] ci(app-preview): open a pull request when deepnote.com serves a new app client A daily workflow downloads https://deepnote.com/static/app-client/v1.js and, when it differs from resources/appPreview/v1.js, opens a draft pull request with the served file. While only the bot has committed to that pull request, later changes rebuild its branch from main; otherwise the run fails and leaves it alone. --- .github/workflows/actions.lock | 8 ++ .github/workflows/sync-app-client.yml | 114 ++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 .github/workflows/sync-app-client.yml diff --git a/.github/workflows/actions.lock b/.github/workflows/actions.lock index 64ecd49b7..b0fde878d 100644 --- a/.github/workflows/actions.lock +++ b/.github/workflows/actions.lock @@ -23,6 +23,9 @@ workflows: - 'actions/setup-node@v7.1.0' - 'actions/setup-python@v7.1.0' - 'actions/upload-artifact@v7.0.2' + '.github/workflows/sync-app-client.yml': + - 'actions/checkout@v7.0.1' + - 'actions/create-github-app-token@v3.4.0' '.github/workflows/verify-actions-lock.yml': - 'actions/checkout@v7.0.1' dependencies: @@ -36,6 +39,11 @@ dependencies: commit: 'sha1-3d3c42e5aac5ba805825da76410c181273ba90b1' owner_id: 44036562 repo_id: 197814629 + 'actions/create-github-app-token@v3.4.0': + ref: 'v3.4.0' + commit: 'sha1-f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc' + owner_id: 44036562 + repo_id: 642580244 'actions/download-artifact@v8.0.2': ref: 'v8.0.2' commit: 'sha1-9000827ccba6bdab643e8b6fd33ac0654aef8333' diff --git a/.github/workflows/sync-app-client.yml b/.github/workflows/sync-app-client.yml new file mode 100644 index 000000000..285389487 --- /dev/null +++ b/.github/workflows/sync-app-client.yml @@ -0,0 +1,114 @@ +name: Sync Deepnote app client + +on: + schedule: + - cron: '0 8 * * *' + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + +jobs: + sync: + name: Sync the bundled app client + runs-on: ubuntu-latest + timeout-minutes: 10 + env: + BRANCH: automation/sync-app-client + CLIENT_PATH: resources/appPreview/v1.js + CLIENT_URL: https://deepnote.com/static/app-client/v1.js + TITLE: 'chore(app-preview): update the bundled Deepnote app client' + steps: + - name: Checkout + uses: actions/checkout@v7.0.1 + with: + ref: main + persist-credentials: false + + # Pushes and pull requests made with GITHUB_TOKEN don't trigger CI or E2E, and E2E running the new client is the point. + - name: Create GitHub App token + id: app-token + uses: actions/create-github-app-token@v3.4.0 + with: + client-id: ${{ vars.GH_TOKEN_APP_CLIENT_ID }} + private-key: ${{ secrets.GH_TOKEN_APP_PRIVATE_KEY }} + permission-contents: write + permission-pull-requests: write + # Rebuilding the branch on a newer main carries main's workflow changes, which GitHub refuses to push without it. + permission-workflows: write + + - name: Open or update the pull request + env: + APP_SLUG: ${{ steps.app-token.outputs.app-slug }} + GH_TOKEN: ${{ steps.app-token.outputs.token }} + run: | + set -euo pipefail + + new_client="$RUNNER_TEMP/v1.js" + content_type=$(curl --fail --silent --show-error --location --retry 3 --max-time 60 \ + --output "$new_client" --write-out '%{content_type}' "$CLIENT_URL") + case "$content_type" in + text/javascript* | application/javascript*) ;; + *) + echo "::error::$CLIENT_URL answered with '$content_type', not JavaScript" + exit 1 + ;; + esac + + bot_name="${APP_SLUG}[bot]" + bot_email="$(gh api "users/$bot_name" --jq .id)+$bot_name@users.noreply.github.com" + git config user.name "$bot_name" + git config user.email "$bot_email" + gh auth setup-git + + pr=$(gh pr list --base main --head "$BRANCH" --state open \ + --json number,headRefOid,isCrossRepository \ + --jq '.[] | select(.isCrossRepository | not) | "\(.number) \(.headRefOid)"') + pr_number=${pr% *} + pr_head=${pr#* } + + only_bot_commits() { + local emails + emails=$(gh api --paginate "repos/$GITHUB_REPOSITORY/pulls/$pr_number/commits" \ + --jq '.[].commit | .author.email, .committer.email') || exit + ! grep --quiet --invert-match --line-regexp --fixed-strings "$bot_email" <<< "$emails" + } + + if cmp --silent "$new_client" "$CLIENT_PATH"; then + echo "main already has the client that $CLIENT_URL serves." + if [[ -n "$pr_number" ]] && only_bot_commits; then + gh pr close "$pr_number" --delete-branch --comment "main already has the client that $CLIENT_URL serves." + fi + exit 0 + fi + + if [[ -n "$pr_number" ]]; then + git fetch --quiet --depth=1 origin "$pr_head" + if git show "$pr_head:$CLIENT_PATH" | cmp --silent - "$new_client"; then + echo "#$pr_number already has the client that $CLIENT_URL serves." + exit 0 + fi + if ! only_bot_commits; then + echo "::error::$CLIENT_URL serves a new client, but #$pr_number has commits from someone other than $bot_name, so it is left as is. Update $CLIENT_PATH there by hand." + exit 1 + fi + fi + + git switch --quiet --create "$BRANCH" + cp "$new_client" "$CLIENT_PATH" + git commit --quiet --all --message "$TITLE" + # An empty lease requires the branch not to exist. + lease=${pr_head:-$(git ls-remote origin "refs/heads/$BRANCH" | cut -f1)} + git push --force-with-lease="refs/heads/$BRANCH:$lease" origin "HEAD:refs/heads/$BRANCH" + + if [[ -z "$pr_number" ]]; then + gh pr create --draft --base main --head "$BRANCH" --title "$TITLE" --body-file - < Date: Wed, 25 Nov 2026 21:24:18 +0000 Subject: [PATCH 2/5] ci(app-preview): run the app client sync on pushes to this branch to test it Temporary: remove this trigger before merging. --- .github/workflows/sync-app-client.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/sync-app-client.yml b/.github/workflows/sync-app-client.yml index 285389487..c3d5bd85b 100644 --- a/.github/workflows/sync-app-client.yml +++ b/.github/workflows/sync-app-client.yml @@ -1,6 +1,8 @@ name: Sync Deepnote app client on: + push: + branches: [tomaskislan/blu-6770-check-that-the-app-previews-bundled] schedule: - cron: '0 8 * * *' workflow_dispatch: From 0c98f3f15396a7497ec2e252b57c748f49be6aa4 Mon Sep 17 00:00:00 2001 From: tomas Date: Thu, 26 Nov 2026 10:25:27 +0000 Subject: [PATCH 3/5] ci(app-preview): drop the workflows permission from the app client sync token --- .github/workflows/sync-app-client.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/sync-app-client.yml b/.github/workflows/sync-app-client.yml index c3d5bd85b..2c197bc73 100644 --- a/.github/workflows/sync-app-client.yml +++ b/.github/workflows/sync-app-client.yml @@ -40,8 +40,6 @@ jobs: private-key: ${{ secrets.GH_TOKEN_APP_PRIVATE_KEY }} permission-contents: write permission-pull-requests: write - # Rebuilding the branch on a newer main carries main's workflow changes, which GitHub refuses to push without it. - permission-workflows: write - name: Open or update the pull request env: From 180f4fb4a69343490ea0fefbde73af6bdd1c5ce1 Mon Sep 17 00:00:00 2001 From: tomas Date: Thu, 26 Nov 2026 11:30:39 +0000 Subject: [PATCH 4/5] ci(app-preview): remove the temporary push trigger from the app client sync --- .github/workflows/sync-app-client.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/sync-app-client.yml b/.github/workflows/sync-app-client.yml index 2c197bc73..da49df4e6 100644 --- a/.github/workflows/sync-app-client.yml +++ b/.github/workflows/sync-app-client.yml @@ -1,8 +1,6 @@ name: Sync Deepnote app client on: - push: - branches: [tomaskislan/blu-6770-check-that-the-app-previews-bundled] schedule: - cron: '0 8 * * *' workflow_dispatch: From 627a6a664422b5c6e17adba0bde30b28bb4e53fa Mon Sep 17 00:00:00 2001 From: tomas Date: Thu, 26 Nov 2026 11:30:39 +0000 Subject: [PATCH 5/5] docs(agents): leave the app client sync branch and its pull requests to the workflow --- AGENTS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index b0c261e58..cea3b76d9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -176,6 +176,8 @@ Update only the documentation your change actually affects. Keep each pull request as simple and clean as possible: one purpose per pull request, the smallest diff that achieves it, and no drive-by refactors, formatting churn, or unrelated changes to inherited upstream code. +The `automation/sync-app-client` branch and its pull requests belong to `.github/workflows/sync-app-client.yml`, which may overwrite or delete them. Don't push to that branch or build on it; make related changes in a separate pull request. + ## Common Tasks ### Adding Tests