preview #347
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
name: preview | |
on: | |
workflow_run: | |
workflows: ["build"] | |
types: | |
- requested | |
- completed | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
preview: | |
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: build-artifacts-${{ github.event.workflow_run.id }} | |
path: ./dist | |
run-id: ${{ github.event.workflow_run.id }} | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Find PR number | |
id: pr | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const response = await github.rest.search.issuesAndPullRequests({ | |
q: 'repo:${{ github.repository }} is:pr sha:${{ github.event.workflow_run.head_sha }}', | |
per_page: 1, | |
}) | |
const items = response.data.items | |
if (items.length < 1) { | |
console.error('No PRs found') | |
return | |
} | |
const pullRequestNumber = items[0].number | |
console.info("Pull request number is", pullRequestNumber) | |
return pullRequestNumber | |
# deploy | |
- name: Deploy to Cloudflare Pages | |
id: cloudflare-publish | |
uses: cloudflare/pages-action@v1.5.0 | |
with: | |
branch: ${{ steps.pr.outputs.result }} | |
projectName: connect | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
apiToken: ${{ secrets.CLOUDFLARE_PAGES_TOKEN }} | |
directory: dist | |
- name: Comment URL on PR | |
uses: thollander/actions-comment-pull-request@v2 | |
with: | |
message: | | |
<!-- _(run_id **${{ github.run_id }}**)_ --> | |
Welcome to connect! Make sure to: | |
* read the [contributing guidelines](https://github.com/commaai/connect?tab=readme-ov-file#contributing) | |
* mark your PR as a draft until it's ready to review | |
* post the preview on [Discord](https://discord.comma.ai); feedback from users will speedup the PR review | |
deployed preview: https://${{ steps.pr.outputs.result }}.connect-d5y.pages.dev | |
comment_tag: run_id | |
pr_number: ${{ steps.pr.outputs.result }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |