@@ -69,13 +69,10 @@ jobs:
6969 if : github.event_name == 'pull_request'
7070 runs-on : ubuntu-latest
7171 needs : build
72+ permissions :
73+ contents : write
74+ pull-requests : write
7275 steps :
73- - name : Checkout gh-pages branch
74- uses : actions/checkout@v4
75- with :
76- ref : gh-pages
77- token : ${{ secrets.GITHUB_TOKEN }}
78-
7976 - name : Download artifact
8077 uses : actions/download-artifact@v4
8178 with :
@@ -84,61 +81,12 @@ jobs:
8481
8582 - name : Extract artifact
8683 run : |
87- mkdir -p pr-${{ github.event.pull_request.number }}
88- tar -xvf ./artifact/artifact.tar -C pr-${{ github.event.pull_request.number }}
89-
90- - name : Configure Git
91- run : |
92- git config user.name "github-actions[bot]"
93- git config user.email "github-actions[bot]@users.noreply.github.com"
94-
95- - name : Commit and push PR preview
96- run : |
97- git add pr-${{ github.event.pull_request.number }}
98- git commit -m "Deploy PR #${{ github.event.pull_request.number }} preview" || echo "No changes to commit"
99- git push origin gh-pages
84+ mkdir -p preview
85+ tar -xvf ./artifact/artifact.tar -C preview
10086
101- - name : Comment PR with preview URL
102- uses : actions/github-script@v7
87+ - name : Deploy PR Preview
88+ uses : rossjrw/pr-preview-action@v1
10389 with :
104- script : |
105- const prNumber = context.payload.pull_request.number;
106- const previewUrl = `https://php-debugger.github.io/pr-${prNumber}/`;
107-
108- const comment = `## 🚀 Preview Deployment
109-
110- Your changes have been deployed to a preview environment:
111-
112- **Preview URL:** ${previewUrl}
113-
114- This preview will be updated automatically when you push new commits to this PR.`;
115-
116- // Find existing preview comment
117- const { data: comments } = await github.rest.issues.listComments({
118- owner: context.repo.owner,
119- repo: context.repo.repo,
120- issue_number: prNumber,
121- });
122-
123- const existingComment = comments.find(c =>
124- c.user.login === 'github-actions[bot]' &&
125- c.body.includes('Preview Deployment')
126- );
127-
128- if (existingComment) {
129- // Update existing comment
130- await github.rest.issues.updateComment({
131- owner: context.repo.owner,
132- repo: context.repo.repo,
133- comment_id: existingComment.id,
134- body: comment
135- });
136- } else {
137- // Create new comment
138- await github.rest.issues.createComment({
139- owner: context.repo.owner,
140- repo: context.repo.repo,
141- issue_number: prNumber,
142- body: comment
143- });
144- }
90+ source-dir : preview
91+ preview-branch : gh-pages
92+ umbrella-dir : pr-preview
0 commit comments