Skip to content

Send diffs for presence #3701

Send diffs for presence

Send diffs for presence #3701

Workflow file for this run

# From https://turbo.build/repo/docs/ci/github-actions
name: JS CI
on:
push:
pull_request:
types: [opened, synchronize]
jobs:
build:
name: Build & Test packages
timeout-minutes: 15
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: client/.turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Enable corepack
working-directory: client
run: corepack enable
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
cache-dependency-path: client
- name: Install dependencies
working-directory: client
run: pnpm i
- name: Build packages
working-directory: client
run: pnpm run build-packages
- name: Build sandbox
working-directory: client
run: pnpm run build-sandbox
- name: Run tests
working-directory: client
run: pnpm run test
- name: Run benchmarks
working-directory: client
run: pnpm run bench
detect_docs:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
outputs:
did_change: ${{ steps.detect-change.outputs.did_change }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ github.event_name == 'pull_request' && 2 || 0 }}
- name: Get changed files
id: changed-files
run: |
if ${{ github.event_name == 'pull_request' }}; then
echo "changed_files=$(git diff --name-only -r HEAD^1 HEAD | xargs)" >> $GITHUB_OUTPUT
else
echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT
fi
- name: Detect docs changes
id: detect-change
run: |
changeArr=($(echo ${{ steps.changed-files.outputs.changed_files }}))
echo "did_change=False" >> $GITHUB_OUTPUT
for file in ${changeArr[*]}
do
if echo $file | grep -E 'docs'; then
echo "did_change=True" >> $GITHUB_OUTPUT
break
fi
done
publish-docs:
name: Publish algolia changes
runs-on: ubuntu-latest
needs: [ build, detect_docs ]
if: needs.detect_docs.outputs.did_change == 'True'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: client/.turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Enable corepack
working-directory: client
run: corepack enable
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
cache-dependency-path: client
- name: Install dependencies
working-directory: 'client'
run: pnpm i
- name: Reindex Algolia
env:
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
working-directory: 'client'
run: node ./www/scripts/index-docs.mjs
vercel-preview:
name: Deploy to vercel preview
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: client/.turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Enable corepack
working-directory: client
run: corepack enable
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
cache-dependency-path: client
- name: Install Vercel CLI
run: npm install --g vercel@canary
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Set branch name
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
else
echo "BRANCH_NAME=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Deploy Project Artifacts to Vercel
run: |
vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }} >deployment-url.txt
code=$?
if [ $code -eq 0 ]; then
deploymentUrl=`cat deployment-url.txt`
safeBranch=$(echo $BRANCH_NAME | sed 's/[^a-zA-Z0-9-]/-/g')
aliasUrl="instant-www-js-$safeBranch-jsv.vercel.app"
echo "ALIAS_URL=$aliasUrl" >> $GITHUB_ENV
echo "aiasing $deploymentUrl to $aliasUrl"
vercel alias $deploymentUrl $aliasUrl --token=${{ secrets.VERCEL_TOKEN }} --scope jsv
else
echo "There was an error"
fi
- name: Comment on PR with deploy preview url
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
with:
script: |
const url = process.env.ALIAS_URL;
const body = `View Vercel preview at [${url}](https://${url}).`;
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
// Check if the comment already exists
const comment = comments.find((comment) => comment.body === body);
if (!comment) {
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
});
} else {
console.log("Already commented", comment);
}
vercel-prod-deploy:
name: Deploy to vercel production
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Cache turbo build setup
uses: actions/cache@v4
with:
path: client/.turbo
key: ${{ runner.os }}-turbo-${{ github.sha }}
restore-keys: |
${{ runner.os }}-turbo-
- name: Enable corepack
working-directory: client
run: corepack enable
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
cache-dependency-path: client
- name: Install Vercel CLI
run: npm install --g vercel@canary
- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}