Skip to content

Add url-card shortcode #3102

Add url-card shortcode

Add url-card shortcode #3102

Workflow file for this run

on:
pull_request:
branches: [main, prerelease]
issue_comment:
types: [created]
name: Deploy Preview
concurrency:
# Use github.event.pull_request.number on pull requests, so it's unique per pull request
# Use github.event.issue.number on issue comments, so it's unique per comment
# Use github.ref on other branches, so it's unique per branch
group: ${{ github.workflow }}-${{ (github.event.pull_request && format('PR-{0}', github.event.pull_request.number)) || ( github.event.issue && format('comment-{0}', github.event.issue.number) ) || github.ref }}
cancel-in-progress: true
jobs:
is-external-pr:
# Be helpful with reviewer and remind them to trigger a deploy preview if the PR is from a fork.
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true }}
runs-on: ubuntu-latest
steps:
- name: Error with message for manual deploy
run: |
echo "::error title=Manual action required for preview::PR from fork can't be deployed as preview to Netlify automatically. Use '/deploy-preview' command in comments to trigger the preview manually."
shell: bash
role-of-commenter:
if: github.event.issue.pull_request
runs-on: ubuntu-latest
steps:
- name: Check if commenter is a member, owner or collaborator
id: commenter-check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
commenter_role=$(gh api repos/$GITHUB_REPOSITORY/collaborators/${{ github.event.comment.user.login }}/permission --jq '.permission')
echo "commenter_role=$commenter_role" >> "$GITHUB_OUTPUT"
echo "author_association=${{ github.event.comment.author_association }}" >> "$GITHUB_OUTPUT"
shell: bash
build-deploy-preview:
# Deploy a preview only if
# - the PR is not from a fork,
# - requested by PR comment /deploy-preview, from a repo user or github action bot (user id 41898282)
# FIXME: We need to change the way we filter because somehow some MEMBER in API are seen as CONTRIBUTOR in CI
if: >
(
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.fork != true
) ||
(
github.event.issue.pull_request &&
(
github.event.comment.user.id == '41898282' ||
github.event.comment.user.login == 'gordonwoodhull' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'COLLABORATOR'
) &&
startsWith(github.event.comment.body, '/deploy-preview')
)
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
ref: refs/pull/${{ github.event.pull_request.number || github.event.issue.number }}/merge
- name: Get latest pre-release from github
id: github-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo version=$(gh api repos/quarto-dev/quarto-cli/releases | jq -r 'map(select(.prerelease)) | first | .tag_name | sub("^v";"")') >> "$GITHUB_OUTPUT"
- name: Set up Quarto
uses: quarto-dev/quarto-actions/setup@v2
with:
version: ${{ steps.github-release.outputs.version }}
- name: Is it for prerelease website ?
id: prerelease-docs-check
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ github.event.pull_request.base.ref }}" == "prerelease" ]; then
echo "is_prerelease_docs=true" >> "$GITHUB_OUTPUT"
elif [ -n "${{ github.event.issue.pull_request.url }}" ]; then
# This will trigger when not pull request event, so a PR comment event.
# we need to get the base info from PR number the comment is made in
base_ref=$(gh -R $GITHUB_REPOSITORY pr view ${{ github.event.issue.number }} --json baseRefName --jq '.baseRefName')
if [ "$base_ref" == "prerelease" ]; then
echo "is_prerelease_docs=true" >> "$GITHUB_OUTPUT"
else
echo "is_prerelease_docs=false" >> "$GITHUB_OUTPUT"
fi
else
echo "is_prerelease_docs=false" >> "$GITHUB_OUTPUT"
fi
shell: bash
- name: Render
uses: quarto-dev/quarto-actions/render@v2
env:
QUARTO_PROFILE: ${{ steps.prerelease-docs-check.outputs.is_prerelease_docs == 'true' && 'prerelease-docs' || '' }}
- name: Deploy Preview to Netlify as preview
id: netlify-deploy
uses: nwtgck/actions-netlify@v3
env:
NETLIFY_SITE_ID: 2a3da659-672b-4e5b-8785-e10ebf79a962
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
with:
publish-dir: './_site'
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: |
Deploy from GHA: ${{ github.event.pull_request.title || format('manual from PR {0}', github.event.issue.number) }}
alias: deploy-preview-${{ github.event.pull_request.number || github.event.issue.number }}
# these all default to 'true'
enable-pull-request-comment: false
enable-commit-comment: false
enable-commit-status: true
overwrites-pull-request-comment: false
timeout-minutes: 1
- name: Get changed files
id: changed-files
uses: tj-actions/[email protected]
with:
files: |
# don't consider modifications on file used for includes for now.
docs/**/[^_]*.qmd
docs/**/[^_]*.md
docs/extensions/listings/*.yml
json: true
escape_json: false
- name: Create custom PR comment
if: github.event.pull_request || github.event.issue.pull_request
uses: actions/github-script@v7
env:
DEPLOY_URL: ${{ steps.netlify-deploy.outputs.deploy-url }}
CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request?.number || context.payload.issue.number;
const deployUrl = process.env.DEPLOY_URL;
const changedFiles = JSON.parse(process.env.CHANGED_FILES);
let commentBody = `## 📝 Preview Deployment\n\n`;
commentBody += `🔍 Full site preview: [${deployUrl}](${deployUrl})\n\n`;
if (changedFiles.length > 0) {
commentBody += `### 🔄 Modified Documents\n\n`;
changedFiles.forEach(file => {
let fileUrlPath;
// Define a mapping for special files to their corresponding URLs
const specialFileMapping = {
'docs/extensions/listings/shortcodes-and-filters.yml': 'docs/extensions/index.html',
'docs/extensions/listings/journal-articles.yml': 'docs/extensions/index.html',
'docs/extensions/listings/custom-formats.yml': 'docs/extensions/index.html',
'docs/extensions/listings/revealjs-formats.yml': 'docs/extensions/index.html',
'docs/extensions/listings/revealjs.yml': 'docs/extensions/index.html'
};
// Check if the file is in the special mapping
if (specialFileMapping[file]) {
fileUrlPath = specialFileMapping[file];
} else if (file.endsWith('.qmd') || file.endsWith('.md')) {
// Convert path to URL (removing file extension and adding appropriate path)
fileUrlPath = file.replace(/\.(qmd|md)$/, '.html');
}
if (fileUrlPath) {
const fileUrl = `${deployUrl}/${fileUrlPath}`;
commentBody += `- [${file}](${fileUrl})\n`;
}
});
}
github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
});