Skip to content
Open
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
8 changes: 8 additions & 0 deletions .github/workflows/actions.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand Down
112 changes: 112 additions & 0 deletions .github/workflows/sync-app-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
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

- 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."
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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)}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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 - <<EOF
$CLIENT_URL serves a different client than the copy the app preview bundles. This replaces \`$CLIENT_PATH\` with the served file, byte for byte, so the app preview's E2E tests run the new client against the preview's local API. If they fail, the new client may need a new local API route.

[\`sync-app-client.yml\`]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/blob/main/.github/workflows/sync-app-client.yml) rebuilds this branch from main whenever the served client changes again, until someone else pushes a commit to it. From then on, update \`$CLIENT_PATH\` here by hand.
EOF
fi
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading