Repository navigation
ci(app-preview): open a pull request when deepnote.com serves a new app client #632
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
Open
tkislan
wants to merge
5
commits into
main
Choose a base branch
from
tomaskislan/blu-6770-check-that-the-app-previews-bundled
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+122
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b5837d9
ci(app-preview): open a pull request when deepnote.com serves a new a…
tkislan b022495
ci(app-preview): run the app client sync on pushes to this branch to …
tkislan 0c98f3f
ci(app-preview): drop the workflows permission from the app client sy…
tkislan 180f4fb
ci(app-preview): remove the temporary push trigger from the app clien…
tkislan 627a6a6
docs(agents): leave the app client sync branch and its pull requests …
tkislan 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
| 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." | ||
| 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)} | ||
|
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 | ||
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.
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.