Skip to content

Support preview from forked repositories 14 #5302

Support preview from forked repositories 14

Support preview from forked repositories 14 #5302

Workflow file for this run

name: Publish website
on:
schedule:
- cron: '0 */6 * * *'
push:
branches: [ main ]
workflow_dispatch:
pull_request:
types: [ opened, synchronize, reopened ]
defaults:
run:
shell: bash
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install packages
run: npm i
- name: Generate Site
run: npm run build
- name: Store PR id
if: github.event_name == 'pull_request'
run: |
mkdir pr
echo ${{ github.event.number }} > ./pr/pr-id.txt
- name: Upload PR id as artifact
uses: actions/upload-artifact@v4
if: github.event_name == 'pull_request'
with:
name: pr-id
path: pr
retention-days: 1
- name: Upload site as artifact
uses: actions/upload-artifact@v4
with:
name: site
path: build/site
retention-days: 1
preview:
runs-on: ubuntu-latest
needs: [ build ]
if: github.event_name == 'pull_request'
permissions:
pull-requests: write # Required to update PR status comment
steps:
- name: Download PR Artifact
uses: actions/download-artifact@v4
with:
name: site
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Download PR ID Artifact
uses: actions/download-artifact@v4
with:
name: pr-id
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Store PR id as variable
id: pr
run: |
echo "id=$(<pr-id.txt)" >> $GITHUB_OUTPUT
rm -f pr-id.txt
- name: Publishing to surge for preview
id: deploy
run: npx surge ./ --domain https://quarkiverse-docs-pr-${{ steps.pr.outputs.id }}-preview.surge.sh --token $SURGE_TOKEN
env:
SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
- name: Update PR status comment on success
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
🚀 PR Preview ${{ github.sha }} has been successfully built and deployed to https://quarkiverse-docs-pr-${{ steps.pr.outputs.id }}-preview.surge.sh
<!-- Sticky Pull Request Comment -->
body-include: '<!-- Sticky Pull Request Comment -->'
number: ${{ steps.pr.outputs.id }}
- name: Update PR status comment on failure
if: ${{ failure() }}
uses: actions-cool/maintain-one-comment@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
body: |
😭 Deploy PR Preview failed.
<img width="300" src="https://user-images.githubusercontent.com/507615/90250824-4e066700-de6f-11ea-8230-600ecc3d6a6b.png">
<!-- Sticky Pull Request Comment -->
body-include: '<!-- Sticky Pull Request Comment -->'
number: ${{ steps.pr.outputs.id }}
deploy:
# Only try and deploy on merged code
if: "github.repository == 'quarkiverse/quarkiverse-docs' && github.ref_name == 'main' && (github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch')"
needs: [ build ]
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
runs-on: ubuntu-latest
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4 # not needed for the code, but needed for the git config
- name: Download Built site
uses: actions/download-artifact@v4
with:
name: site
path: _site
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4