Skip to content

Get Extensions from Quarto Website #122

Get Extensions from Quarto Website

Get Extensions from Quarto Website #122

Workflow file for this run

name: Get Extensions from Quarto Website
on:
schedule:
- cron: "0 1 * * 0"
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
quarto-web:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Create GitHub App token
uses: actions/create-github-app-token@v3
id: app-token
with:
client-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_KEY }}
- name: Get GitHub App User ID
id: get-user-id
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
shell: bash
run: echo "user-id=$(gh api "/users/${APP_SLUG}[bot]" --jq .id)" >>
"${GITHUB_OUTPUT}"
- name: Git Config
env:
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
USER_ID: ${{ steps.get-user-id.outputs.user-id }}
shell: bash
run: |
git config --global user.name "${APP_SLUG}[bot]"
git config --global user.email "${USER_ID}+${APP_SLUG}[bot]@users.noreply.github.com"
- name: Get extensions from Quarto Website and commit
shell: bash
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
CSV_FILE="extensions/quarto-extensions.csv"
git clone --quiet --filter=blob:none --no-checkout https://github.com/quarto-dev/quarto-web _quarto-web
git -C _quarto-web sparse-checkout init --cone
git -C _quarto-web sparse-checkout set docs/extensions/listings
git -C _quarto-web checkout main --quiet
find _quarto-web/docs/extensions/listings -type f -name "*.yml" ! -name "_*" \
-exec grep -o 'path: https://github.com/.*' {} \; \
| sed 's/path: https:\/\/github.com\///' | sed 's/blob\/[^/]*\///' > _quarto-web/quarto-web-extensions.csv
cat "${CSV_FILE}" > _quarto-web/quarto-extensions.csv
echo "gadenbuie/countdown" >> _quarto-web/quarto-extensions.csv # Don't add this extension as not available through tag
extensions_to_add=$(grep -Fvxi -f _quarto-web/quarto-extensions.csv _quarto-web/quarto-web-extensions.csv || true)
rm -rf _quarto-web
if [[ -z "${extensions_to_add}" ]]; then
echo "No new extensions to add."
exit 0
fi
while IFS= read -r extension; do
[[ -z "${extension}" ]] && continue
slug=$(echo "${extension}" | tr '/' '-')
branch="ci/get-quarto-web-extension-${slug}"
git checkout -B "${branch}" main --quiet
echo "${extension}" >> "${CSV_FILE}"
git add "${CSV_FILE}"
git commit -m "ci: add ${extension} from quarto-web"
git push --force origin "${branch}"
if [[ -z "$(gh pr list --head "${branch}" --state open --json number --jq '.[].number')" ]]; then
gh pr create \
--title "ci: add ${extension} from quarto-web" \
--body "Add \`${extension}\` discovered on the Quarto website." \
--base "main" \
--head "${branch}" \
--label "Type: CI/CD :robot:" \
--reviewer "${GITHUB_REPOSITORY_OWNER}"
fi
done <<< "${extensions_to_add}"