From 539e6f9b9d5206910d081e42b34b044bf059f371 Mon Sep 17 00:00:00 2001 From: Heather Turner Date: Mon, 16 Jun 2025 14:53:28 +0100 Subject: [PATCH] update mkdocs workflow --- .github/workflows/build-mkdocs-website.yml | 44 +++++++++++++++++----- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-mkdocs-website.yml b/.github/workflows/build-mkdocs-website.yml index 5e4e0ce97..393174ace 100644 --- a/.github/workflows/build-mkdocs-website.yml +++ b/.github/workflows/build-mkdocs-website.yml @@ -10,34 +10,60 @@ on: - 'docs/**/**' - 'mkdocs.yml' -permissions: - contents: write - jobs: build-and-deploy: if: | github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) runs-on: ubuntu-latest + permissions: + contents: write steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: 3.x - name: Install dependencies run: pip install mkdocs mkdocs-material[imaging] + - name: Determine deployment settings + id: config + run: | + if [[ "${{ github.ref_name }}" == "main" ]]; then + echo "target_repo=${{ github.repository }}" >> "$GITHUB_OUTPUT" + echo "url=https://contributor.r-project.org/r-dev-env" >> "$GITHUB_OUTPUT" + else + echo "target_repo=r-devel/r-dev-env-devel" >> "$GITHUB_OUTPUT" + echo "url=https://contributor.r-project.org/r-dev-env-devel" >> "$GITHUB_OUTPUT" + fi + + - name: Modify site_url in mkdocs.yml + run: | + echo "Setting site_url to ${{ steps.config.outputs.url }}" + sed -i "s|^site_url:.*|site_url: '${{ steps.config.outputs.url }}'|" mkdocs.yml + - name: Build MkDocs run: mkdocs build - - name: Deploy to GitHub Pages + - name: Validate PAT + env: + GH_PAT: ${{ secrets.R_DEV_ENV_DOCS }} run: | - mkdocs gh-deploy --force - git push origin gh-pages + curl -H "Authorization: token $GH_PAT" https://api.github.com/user || { + echo "PAT is invalid or expired" >&2 + exit 1 + } + + - name: Deploy to GitHub Pages env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_PAT: ${{ secrets.R_DEV_ENV_DOCS }} + run: | + echo "Deploying from branch: ${{ github.ref_name }}" + echo "Commit: ${{ github.sha }}" + git remote set-url origin https://x-access-token:${GH_PAT}@github.com/${{ steps.config.outputs.target_repo }} + mkdocs gh-deploy --config-file mkdocs.yml --remote-branch gh-pages --force