44 workflow_call :
55 workflow_dispatch :
66 pull_request :
7- types : [ "opened", "synchronize", "reopened" ]
7+ types : [ "opened", "synchronize", "reopened", "closed" ]
88 push :
99 branches : [ "main" ]
1010
1111permissions :
1212 contents : write
13- pages : write
14- id-token : write
1513
1614concurrency :
1715 group : " pages"
1816 cancel-in-progress : false
1917
2018jobs :
2119 reports :
20+ if : github.event_name != 'pull_request' || github.event.action != 'closed'
2221 name : Generate Reports
2322 runs-on : ubuntu-latest
2423
@@ -65,49 +64,30 @@ jobs:
6564 echo "::warning title=Invalid file permissions automatically fixed::$line"
6665 done
6766
68- - name : Upload artifact
69- if : github.event_name != 'pull_request'
70- uses : actions/upload-pages-artifact@v5
71- with :
72- name : ${{ env.PAGES_ARTIFACT_NAME }}
73- path : public/
67+ - name : Add .nojekyll
68+ run : touch public/.nojekyll
7469
75- - name : Upload pull request artifact
76- if : github.event_name == 'pull_request '
77- uses : actions/upload-pages-artifact@v5
70+ - name : Deploy main reports
71+ if : github.event_name == 'push '
72+ uses : peaceiris/actions-gh-pages@v4
7873 with :
79- name : ${{ env.PAGES_ARTIFACT_NAME }}
80- path : public/
81-
82- - name : Upload downloadable pull request reports
74+ github_token : ${{ secrets.GITHUB_TOKEN }}
75+ publish_branch : gh-pages
76+ publish_dir : ./public
77+ destination_dir : .
78+ keep_files : true
79+ force_orphan : false
80+
81+ - name : Deploy PR preview
8382 if : github.event_name == 'pull_request'
84- uses : actions/upload-artifact@v6
83+ uses : peaceiris/actions-gh-pages@v4
8584 with :
86- name : reports-pr-${{ github.event.pull_request.number }}
87- path : public/
88- retention-days : 14
89-
90- deploy :
91- if : github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch'
92-
93- name : Deploy to GitHub Pages
94- needs : reports
95-
96- permissions :
97- pages : write
98- id-token : write
99-
100- environment :
101- name : github-pages
102- url : ${{ steps.deployment.outputs.page_url }}
103-
104- runs-on : ubuntu-latest
105- steps :
106- - name : Deploy to GitHub Pages
107- id : deployment
108- uses : actions/deploy-pages@v5
109- with :
110- artifact_name : github-pages
85+ github_token : ${{ secrets.GITHUB_TOKEN }}
86+ publish_branch : gh-pages
87+ publish_dir : ./public
88+ destination_dir : previews/pr-${{ github.event.pull_request.number }}
89+ keep_files : true
90+ force_orphan : false
11191
11292 preview :
11393 if : github.event_name == 'pull_request'
@@ -132,3 +112,30 @@ jobs:
132112 with :
133113 artifact_name : github-pages-pr-${{ github.event.pull_request.number }}
134114 preview : true
115+
116+ cleanup_preview :
117+ if : github.event_name == 'pull_request' && github.event.action == 'closed'
118+ name : Cleanup Pull Request Preview
119+ runs-on : ubuntu-latest
120+
121+ steps :
122+ - name : Checkout gh-pages
123+ uses : actions/checkout@v6
124+ with :
125+ ref : gh-pages
126+ path : gh-pages
127+
128+ - name : Remove preview directory
129+ run : |
130+ rm -rf "gh-pages/previews/pr-${{ github.event.pull_request.number }}"
131+ cd gh-pages
132+ touch .nojekyll
133+ git config user.name "github-actions[bot]"
134+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
135+ git add -A
136+ git diff --cached --quiet || git commit -m "chore: remove preview for PR #${{ github.event.pull_request.number }}"
137+
138+ - name : Push changes
139+ run : |
140+ cd gh-pages
141+ git push
0 commit comments