Get Extensions from Quarto Website #103
This file contains hidden or 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: 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 | |
| env: | |
| BRANCH: ci/get-quarto-web-extensions | |
| COMMIT: "ci: get quarto-web extensions" | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Create GitHub App token | |
| uses: actions/create-github-app-token@v2 | |
| id: app-token | |
| with: | |
| app-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 | |
| if git show-ref --quiet refs/heads/${BRANCH}; then | |
| echo "Branch ${BRANCH} already exists." | |
| git branch -D "${BRANCH}" | |
| git push origin --delete "${BRANCH}" | |
| fi | |
| git checkout -b "${BRANCH}" | |
| echo "${extensions_to_add}" >> "${CSV_FILE}" | |
| git add "${CSV_FILE}" | |
| git commit -m "${COMMIT}" | |
| git push --force origin ${BRANCH} | |
| gh pr create \ | |
| --fill-first \ | |
| --base "main" \ | |
| --head "${BRANCH}" \ | |
| --label "Type: CI/CD :robot:" \ | |
| --reviewer "${GITHUB_REPOSITORY_OWNER}" | |
| sleep 5 | |
| gh pr merge --auto --squash --delete-branch |