Skip to content

Commit f0bd049

Browse files
Copilotyuhattor
andcommitted
Fix debug configuration and update PR preview workflow
Co-authored-by: yuhattor <15963767+yuhattor@users.noreply.github.com>
1 parent 1ed2cfd commit f0bd049

4 files changed

Lines changed: 105 additions & 32 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@
1414
"davidanson.vscode-markdownlint",
1515
"esbenp.prettier-vscode",
1616
"ms-vscode.live-server",
17-
"tamasfe.even-better-toml"
17+
"tamasfe.even-better-toml",
18+
"ms-vscode.js-debug-nightly"
1819
],
1920
"settings": {
2021
"editor.formatOnSave": true,
21-
"editor.defaultFormatter": "esbenp.prettier-vscode"
22+
"editor.defaultFormatter": "esbenp.prettier-vscode",
23+
"debug.javascript.autoAttachFilter": "smart"
2224
}
2325
}
2426
},
2527
"forwardPorts": [1313],
2628
"remoteUser": "vscode",
27-
"postCreateCommand": "cd /tmp && wget -O hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.133.1/hugo_extended_0.133.1_linux-amd64.deb && sudo dpkg -i hugo.deb && rm hugo.deb && hugo version && echo 'Hugo server ready to run! Use the Run and Debug view to start the server.'"
29+
"postCreateCommand": "cd /tmp && wget -O hugo.deb https://github.com/gohugoio/hugo/releases/download/v0.133.1/hugo_extended_0.133.1_linux-amd64.deb && sudo dpkg -i hugo.deb && rm hugo.deb && npm init -y && npm install hugo-bin@latest && hugo version && echo 'Hugo server ready to run! Use the Run and Debug view to start the server.'"
2830
}

.github/workflows/pr-preview.yml

Lines changed: 76 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ on:
77
jobs:
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 }}

.vscode/launch.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33
"configurations": [
44
{
55
"name": "Hugo Server",
6-
"type": "shell",
6+
"type": "pwa-node",
77
"request": "launch",
8-
"command": "hugo",
8+
"program": "${workspaceFolder}/node_modules/.bin/hugo",
99
"args": [
1010
"server",
1111
"--appendPort=false",
1212
"--baseURL=/",
1313
"-D"
1414
],
15-
"console": "integratedTerminal"
15+
"console": "integratedTerminal",
16+
"preLaunchTask": "Hugo: Check Environment",
17+
"serverReadyAction": {
18+
"pattern": "Web Server is available at //localhost:(\\d+)/",
19+
"uriFormat": "http://localhost:%s/",
20+
"action": "openExternally"
21+
}
1622
}
1723
]
1824
}

.vscode/tasks.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "Hugo: Check Environment",
6+
"type": "shell",
7+
"command": "which hugo || (echo 'Hugo not found. Please make sure Hugo is installed and in your PATH.' && exit 1)",
8+
"presentation": {
9+
"reveal": "silent",
10+
"panel": "dedicated"
11+
},
12+
"problemMatcher": []
13+
}
14+
]
15+
}

0 commit comments

Comments
 (0)