Skip to content
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

chore: Add "Deploy Preview" GitHub workflow #2079

Merged

Conversation

LekoArts
Copy link
Member

@LekoArts LekoArts commented Nov 8, 2023

Description

This PR adds a new GitHub workflow called preview. You'll be able to comment !preview on a PR to build playground/nextjs with the current state of your PR. This also includes clerk-js.

How it works:

  1. Build the monorepo packages
  2. Copy playground/nextjs to a temp dir and use secco to install monorepo packages (and rest of deps) inside newly copied test site
  3. Copy clerk-js/dist to public/clerk-js of test site and set env var to use that CLERK_JS_URL
  4. Build site with Vercel
  5. Upload site to Vercel
  6. Add comment to PR to point towards preview

Note: Only members of Clerk Vercel Team will be able to access the deploy preview

Parts of the logic are copied from https://github.com/clerk/clerk-docs/blob/main/.github/workflows/preview.yml

Checklist

  • npm test runs as expected.
  • npm run build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Packages affected

  • @clerk/backend
  • @clerk/chrome-extension
  • @clerk/clerk-js
  • @clerk/clerk-expo
  • @clerk/fastify
  • gatsby-plugin-clerk
  • @clerk/localizations
  • @clerk/nextjs
  • @clerk/clerk-react
  • @clerk/remix
  • @clerk/clerk-sdk-node
  • @clerk/shared
  • @clerk/themes
  • @clerk/types
  • build/tooling/chore

chore(repo): Add install site in isolation script

chore(repo): Globally install secco

chore(repo): Begin preview workflow

chore(repo): Use actions/core

chore(backend): Use cpy instead of rsync

chore(repo): Update nextjs playground

chore(repo): Add missing dep to nextjs playground

chore(repo): Update lock file
Copy link

changeset-bot bot commented Nov 8, 2023

🦋 Changeset detected

Latest commit: 60bc99f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@LekoArts LekoArts changed the title WIP: Deploy Preview chore: Add "Deploy Preview" GitHub workflow Nov 8, 2023
jobs:
preview:
if: ${{ startsWith(github.event.comment.body, '!preview') && github.repository == 'clerk/javascript' && github.event.issue.pull_request }}
runs-on: ${{ vars.RUNNER_NORMAL }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's not urgent so no need to spend more money than necessary

Comment on lines +22 to +23
VERCEL_ORG_ID: ${{ secrets.VERCEL_CLERK_PROD_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_JS_PREVIEW_PROJECT_ID }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Env vars that the Vercel API uses (kind of undocumented feature at this point)

echo "DATE=$(date -u +"%b %d, %Y %I:%M %p")" >> $GITHUB_ENV

- name: Install site in isolation
run: node scripts/install-site-in-isolation.mjs playground/nextjs
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we could easily swap this to another site

@@ -35,7 +35,7 @@
"publish:local": "npx yalc push --replace --sig",
"build:lib": "tsup --env.NODE_ENV production",
"build:tests": "tsc -p tsconfig.test.json",
"build:runtime": "rsync -r --include '*/' --include '*.js' --include '*.mjs' --exclude='*' src/runtime dist",
"build:runtime": "cpy 'src/runtime/**/*.{mjs,js,cjs}' dist/runtime",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was using https://github.com/nektos/act to test this workflow locally and rsync isn't installed in every linux distro. So I switched to a package that'll work everywhere (and is easier to grok)

},
"dependencies": {
"@clerk/backend": "latest",
"@clerk/clerk-react": "latest",
"@clerk/clerk-sdk-node": "latest",
"@clerk/nextjs": "latest",
"@clerk/shared": "latest",
"@clerk/themes": "latest",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clerk/themes is used but not actually installed

@LekoArts LekoArts marked this pull request as ready for review November 8, 2023 10:33
@LekoArts LekoArts requested a review from a team as a code owner November 8, 2023 10:33
Copy link
Member

@brkalow brkalow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 Looks great! No blocking comments. This will be a nice workflow improvement.

Should we add info on this to the contributing doc as well? Or do you want to stick to the internal notion page?


// Installing secco
await core.group('Installing secco (if not already installed)', async () => {
await $`command -v secco || (command -v sudo && sudo npm install -g secco@latest) || npm install -g secco@latest`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ why the need for sudo here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you run this locally (which it is designed for, you can fully run this locally) this is sometimes necessary in some environments. Ideally you already have it installed globally anyways then

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(passing thought) This feels like the beginning of a util that could be used locally to create playgrounds from our integration templates. 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you can already use it locally start to finish 👍

Comment on lines +76 to +78
- name: Copy clerk-js/dist into public/clerk-js of test site
run: |
cp -r $GITHUB_WORKSPACE/packages/clerk-js/dist $FULL_TMP_FOLDER/public/clerk-js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking 👍

Co-authored-by: Bryce Kalow <bryce@clerk.dev>
@LekoArts
Copy link
Member Author

LekoArts commented Nov 8, 2023

Should we add info on this to the contributing doc as well

I can do that in another PR, I saw some needed unrelated changes there

@LekoArts LekoArts added this pull request to the merge queue Nov 8, 2023
Merged via the queue into main with commit 267d950 Nov 8, 2023
@LekoArts LekoArts deleted the lekoarts/sdk-853-add-deploy-preview-for-clerkincjavascript branch November 8, 2023 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants