77jobs :
88 build-preview :
99 runs-on : ubuntu-latest
10+ permissions :
11+ contents : write
12+ pull-requests : write
1013 steps :
11- - uses : actions/checkout@v2
14+ - uses : actions/checkout@v3
1215
1316 - name : Setup Hugo
1417 uses : peaceiris/actions-hugo@v2
@@ -27,34 +30,81 @@ jobs:
2730 - name : Build
2831 run : hugo --minify
2932
30- - name : Deploy PR Preview
31- uses : rossjrw/pr-preview-action@v1
32- with :
33- source-dir : ./public/
34- preview-branch : gh-pages
35- umbrella-dir : pr-preview
36- action : auto
37-
38- - name : Find Comment
39- uses : peter-evans/find-comment@v1
40- id : fc
41- with :
42- issue-number : ${{ github.event.pull_request.number }}
43- comment-author : ' github-actions[bot]'
44- body-includes : " Preview this PR"
33+ - name : Setup GitHub Pages
34+ id : pages
35+ uses : actions/configure-pages@v3
4536
46- - name : Create or Update Comment
47- uses : peter-evans/create-or-update-comment@v1
48- with :
49- comment-id : ${{ steps.fc.outputs.comment-id }}
50- issue-number : ${{ github.event.pull_request.number }}
51- body : |
52- ### :rocket: Preview this PR
37+ - name : Deploy Preview to GitHub Pages Branch
38+ run : |
39+ PR_NUMBER=${{ github.event.pull_request.number }}
40+ PREVIEW_DIR="pr-preview/pr-$PR_NUMBER"
41+
42+ git config --global user.name "github-actions[bot]"
43+ git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
44+
45+ git clone --quiet --branch=gh-pages --depth=1 https://${GITHUB_TOKEN}@github.com/${{ github.repository }}.git gh-pages
46+
47+ mkdir -p gh-pages/${PREVIEW_DIR}
48+ rm -rf gh-pages/${PREVIEW_DIR}/*
49+ cp -r public/* gh-pages/${PREVIEW_DIR}/
50+
51+ cd gh-pages
52+ git add .
53+ git commit -m "Update preview for PR #$PR_NUMBER" || echo "No changes to commit"
54+ git push origin gh-pages
55+ env :
56+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
57+
58+ - name : Add or Update PR Comment
59+ run : |
60+ PR_NUMBER=${{ github.event.pull_request.number }}
61+ PREVIEW_URL="${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-$PR_NUMBER/"
62+
63+ # Check if comment already exists
64+ COMMENT_ID=$(gh pr view $PR_NUMBER --json comments --jq '.comments[] | select(.author.login == "github-actions[bot]" and contains(.body, "Preview this PR")) | .id')
65+
66+ if [ -z "$COMMENT_ID" ]; then
67+ # Create new comment
68+ gh pr comment $PR_NUMBER --body "### :rocket: Preview this PR
5369
5470 You can view a preview of the website changes at:
55- https://innersourcecommons.github.io/innersourcecommons.org/pr-preview/pr-${{ github.event.pull_request.number }}/
71+ https://${PREVIEW_URL}
5672
5773 This preview will be updated automatically as you make changes to the PR.
5874
59- _Note: The preview may take a few moments to deploy after changes are pushed._
60- edit-mode : replace
75+ ### :computer: Review in GitHub Codespaces
76+
77+ You can also review these changes directly in GitHub Codespaces:
78+
79+ 1. Click the 'Code' button above and select the 'Codespaces' tab
80+ 2. Create a codespace on this PR's branch
81+ 3. Once loaded, press F5 or use the Run and Debug panel to start the Hugo server
82+ 4. Make changes and see them update in real-time
83+
84+ For detailed instructions, refer to the [Codespaces documentation](../blob/main/CODESPACES.md).
85+
86+ _Note: The preview may take a few moments to deploy after changes are pushed._"
87+ else
88+ # Update existing comment
89+ gh pr comment $PR_NUMBER --edit-comment $COMMENT_ID --body "### :rocket: Preview this PR
90+
91+ You can view a preview of the website changes at:
92+ https://${PREVIEW_URL}
93+
94+ This preview will be updated automatically as you make changes to the PR.
95+
96+ ### :computer: Review in GitHub Codespaces
97+
98+ You can also review these changes directly in GitHub Codespaces:
99+
100+ 1. Click the 'Code' button above and select the 'Codespaces' tab
101+ 2. Create a codespace on this PR's branch
102+ 3. Once loaded, press F5 or use the Run and Debug panel to start the Hugo server
103+ 4. Make changes and see them update in real-time
104+
105+ For detailed instructions, refer to the [Codespaces documentation](../blob/main/CODESPACES.md).
106+
107+ _Note: The preview may take a few moments to deploy after changes are pushed._"
108+ fi
109+ env :
110+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments