chore(Header): use style-guide header #48
Workflow file for this run
This file contains 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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json | |
name: PR Deploy Preview | |
# Preview PRs via actions/deploy-pages is not available so using JamesIves/github-pages-deploy-action | |
# https://github.com/orgs/community/discussions/7730 | |
on: | |
pull_request: | |
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
permissions: | |
contents: write | |
pull-requests: write | |
id-token: write | |
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
concurrency: | |
group: 'deploy-pages' | |
cancel-in-progress: false | |
jobs: | |
deploy-preview: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: npm | |
- name: Install dependencies | |
run: npm ci | |
- name: Build | |
env: | |
# Deploying to a root domain | |
BASE_PATH: /_pr/${{ github.event.pull_request.number }} | |
run: | | |
npm run build | |
touch build/.nojekyll | |
- name: Deploy to GitHub Pages | |
uses: JamesIves/github-pages-deploy-action@881db5376404c5c8d621010bcbec0310b58d5e29 | |
with: | |
folder: build | |
target-folder: _pr/${{ github.event.pull_request.number }} | |
- name: Update Job Summary | |
run: | | |
echo "## Preview URL" >> $GITHUB_STEP_SUMMARY | |
echo "🚀 [https://www.frequency.xyz/_pr/${{ github.event.pull_request.number }}](https://www.frequency.xyz/_pr/${{ github.event.pull_request.number }})" >> $GITHUB_STEP_SUMMARY | |
- name: Comment PR | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const prNumber = context.issue.number; | |
const sha = context.sha; | |
const deploymentUrl = `https://www.frequency.xyz/_pr/${prNumber}/`; | |
const commitUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/commit/${sha}`; | |
const body = `🚀 Preview deployment for this PR is going up! Remember you might need to hard refresh to get the new content.\n\nPreview URL: [${deploymentUrl}](${deploymentUrl})\nCommit: [${sha.substr(0, 7)}](${commitUrl})`; | |
const comments = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
}); | |
const existingComment = comments.data.find(comment => | |
comment.user.login === 'github-actions[bot]' && | |
comment.body.includes('Preview deployment for this PR is ready!') | |
); | |
if (existingComment) { | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: existingComment.id, | |
body: body, | |
}); | |
} else { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: prNumber, | |
body: body, | |
}); | |
} |