Skip to content

Build dev-portal preview for PR Add broken link checker (taken from tutorials repo) (#165) #597

Build dev-portal preview for PR Add broken link checker (taken from tutorials repo) (#165)

Build dev-portal preview for PR Add broken link checker (taken from tutorials repo) (#165) #597

name: Build dev-portal Preview for PR
run-name: 'Build dev-portal preview for PR ${{ github.event.pull_request.title }} (#${{ github.event.pull_request.number }})'
on:
pull_request: {}
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
deploy-dev-portal-preview:
name: Deploy Dev Portal Preview
runs-on: ubuntu-latest
steps:
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Initial comment on PR
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # v2.9.0
with:
header: preview-notice
message: |
## Deploying Vercel Previews...
| Name | Status | Preview | Updated (UTC) |
| :--- | :----- | :------ | :------------ |
| Dev Portal | πŸ”„ Building ([Inspect](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})) | --- | --- |
| Unified Docs API | πŸ”„ Building ([Inspect](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})) | --- | --- |
- name: Checkout hashicorp/web-unified-docs
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
- name: Get Unified Docs Vercel Data
uses: ./.github/actions/get-vercel-preview-data
id: unified_docs_preview_url
with:
deployment_type: 'id'
project_id: ${{ secrets.VERCEL_UNIFIED_DOCS_PROJECT_ID }}
team_id: ${{ secrets.VERCEL_TEAM_ID }}
vercel_token: ${{ secrets.VERCEL_TOKEN }}
github_sha: ${{ github.event.pull_request.head.sha }} # the SHA of last commit on the PR branch
- name: Checkout hashicorp/dev-portal (Frontend)
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
repository: hashicorp/dev-portal
path: ./unified-docs-frontend-preview
- name: Setup Node.js
uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: 'unified-docs-frontend-preview/package-lock.json'
- name: Setup Vercel CLI
run: npm i --global vercel@latest
- run: vercel pull --yes --environment=preview --scope=hashicorp --token=${{ secrets.VERCEL_TOKEN }}
working-directory: unified-docs-frontend-preview
- name: Wait for Unified Docs API to be ready
uses: ./.github/actions/get-vercel-preview-data
id: check_unified_docs_preview_url
with:
deployment_type: 'check'
deployment_url: ${{ steps.unified_docs_preview_url.outputs.preview_url }}
team_id: ${{ secrets.VERCEL_TEAM_ID }}
vercel_token: ${{ secrets.VERCEL_TOKEN }}
num_of_checks: 3
mins_between_checks: 5
- name: Update comment with preview URL with Unified Docs API data
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # v2.9.0
with:
header: preview-notice
message: |
## Vercel Previews Deployed
| Name | Status | Preview | Updated (UTC) |
| :--- | :----- | :------ | :------------ |
| Dev Portal | πŸ”„ Building ([Inspect](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})) | --- | --- |
| Unified Docs API | βœ… Ready ([Inspect](${{ steps.unified_docs_preview_url.outputs.inspector_url }})) | [Visit Preview](${{ steps.unified_docs_preview_url.outputs.preview_url }}) | ${{ steps.unified_docs_preview_url.outputs.created_utc }} |
- name: inject env vars
run: |
cd unified-docs-frontend-preview
echo "HASHI_ENV=unified-docs-sandbox" >> .env
echo "UNIFIED_DOCS_API=${{ steps.unified_docs_preview_url.outputs.preview_url }}" >> .env
echo "IS_CONTENT_PREVIEW=true" >> .env
- name: Build dev-portal
uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0
with:
timeout_minutes: 10
max_attempts: 2
command: |
cd unified-docs-frontend-preview
vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy dev-portal preview
id: deploy_dev_portal_preview
run: |
DEV_PORTAL_PREVIEW_URL=$(vercel deploy --prebuilt --archive=tgz --scope=hashicorp --token=${{ secrets.VERCEL_TOKEN }})
echo "DEV_PORTAL_PREVIEW_URL=$DEV_PORTAL_PREVIEW_URL" >> $GITHUB_OUTPUT
echo "DEV_PORTAL_PREVIEW_URL=$DEV_PORTAL_PREVIEW_URL" >> $GITHUB_ENV
working-directory: unified-docs-frontend-preview
- name: Get Dev Portal Vercel Data
uses: ./.github/actions/get-vercel-preview-data
id: dev_portal_vercel_data
with:
deployment_type: 'url'
deployment_url: ${{ steps.deploy_dev_portal_preview.outputs.DEV_PORTAL_PREVIEW_URL }}
team_id: ${{ secrets.VERCEL_TEAM_ID }}
vercel_token: ${{ secrets.VERCEL_TOKEN }}
- name: Update comment with preview URL with all data
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # v2.9.0
with:
header: preview-notice
message: |
## Vercel Previews Deployed
| Name | Status | Preview | Updated (UTC) |
| :--- | :----- | :------ | :------------ |
| Dev Portal | βœ… Ready ([Inspect](${{ steps.dev_portal_vercel_data.outputs.inspector_url }})) | [Visit Preview](${{ steps.deploy_dev_portal_preview.outputs.DEV_PORTAL_PREVIEW_URL }}) | ${{ steps.dev_portal_vercel_data.outputs.created_utc }} |
| Unified Docs API | βœ… Ready ([Inspect](${{ steps.unified_docs_preview_url.outputs.inspector_url }})) | [Visit Preview](${{ steps.unified_docs_preview_url.outputs.preview_url }}) | ${{ steps.unified_docs_preview_url.outputs.created_utc }} |