Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions .github/workflows/build-mkdocs-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ jobs:
build-and-deploy:
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'pull_request' && github.event.pull_request.merged == true)
(github.event_name == 'pull_request' &&
github.event.pull_request.merged == true)
runs-on: ubuntu-latest
permissions:
contents: write
Expand All @@ -36,16 +37,19 @@ jobs:
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"
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"
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
sed -i "s|^site_url:.*|site_url: '${{
steps.config.outputs.url }}'|" mkdocs.yml

- name: Build MkDocs
run: mkdocs build
Expand All @@ -54,9 +58,10 @@ jobs:
env:
GH_PAT: ${{ secrets.R_DEV_ENV_DOCS }}
run: |
curl -H "Authorization: token $GH_PAT" https://api.github.com/user || {
echo "PAT is invalid or expired" >&2
exit 1
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
Expand All @@ -65,7 +70,15 @@ jobs:
run: |
echo "Deploying from branch: ${{ github.ref_name }}"
echo "Commit: ${{ github.sha }}"
git config --global credential.helper store
echo "https://x-access-token:${GH_PAT}@github.com" > ~/.git-credentials
git remote set-url origin https://github.com/${{ steps.config.outputs.target_repo }}
mkdocs gh-deploy --config-file mkdocs.yml --remote-branch gh-pages --force

git config --global user.email "[email protected]"
git config --global user.name "github-actions"

git worktree add gh-pages gh-pages
cp -r site/* gh-pages/
cd gh-pages
git add .
git commit -m "Automated site update for r-dev-env ${{ github.sha }}" \
|| echo "No changes to commit"
git push https://x-access-token:${GH_PAT}@github.com/${{
steps.config.outputs.target_repo }} gh-pages
Loading