@@ -2,138 +2,54 @@ name: Deploy to GitHub Pages
22
33on :
44 push :
5- branches : [master]
6- pull_request :
7- branches : [master]
8- workflow_dispatch :
5+ branches :
6+ - master # Set your default branch here
7+ workflow_dispatch : # Allows manual triggering
98
109permissions :
11- contents : write
10+ contents : read
1211 pages : write
1312 id-token : write
14- security-events : write
1513
14+ # Allow only one concurrent deployment
1615concurrency :
17- group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
16+ group : " pages "
1817 cancel-in-progress : true
1918
2019jobs :
21- security :
22- name : Security Scan
20+ build :
2321 runs-on : ubuntu-latest
2422 steps :
25- - uses : actions/checkout@v3
26-
27- - name : Run CodeQL Analysis
28- uses : github/codeql-action/init@v2
29- with :
30- languages : javascript, typescript
31-
32- - name : Autobuild
33- uses : github/codeql-action/autobuild@v2
34-
35- - name : Perform CodeQL Analysis
36- uses : github/codeql-action/analyze@v2
37-
38- build-and-deploy :
39- needs : security
40- runs-on : ubuntu-latest
41-
42- steps :
43- - name : Checkout
23+ - name : Checkout repository
4424 uses : actions/checkout@v3
4525
4626 - name : Setup Node.js
4727 uses : actions/setup-node@v3
4828 with :
49- node-version : ' 20 '
29+ node-version : 18
5030 cache : ' npm'
5131
52- - name : Cache build
53- uses : actions/cache@v3
54- with :
55- path : |
56- dist
57- node_modules/.cache
58- key : ${{ runner.os }}-build-${{ hashFiles('**/package-lock.json', '**/src/**') }}
59- restore-keys : |
60- ${{ runner.os }}-build-
32+ - name : Install dependencies
33+ run : npm ci
6134
62- - name : Install Dependencies
63- run : |
64- npm ci
65- npm install -g html-minifier-terser svgo
66- if [ $? -ne 0 ]; then
67- echo "::error::Failed to install dependencies"
68- exit 1
69- fi
35+ - name : Build website
36+ run : npm run build
7037
71- - name : Validate Environment
72- run : |
73- if [ -z "${{ secrets.ESHANIZED_GH_TOKEN }}" ]; then
74- echo "::error::ESHANIZED_GH_TOKEN is not set"
75- exit 1
76- fi
38+ - name : Setup Pages
39+ uses : actions/configure-pages@v3
7740
78- - name : Build
79- run : |
80- npm run build
81- if [ $? -ne 0 ]; then
82- echo "::error::Build failed"
83- exit 1
84- fi
85- env :
86- DEPLOY_TARGET : github
87- NODE_ENV : production
88-
89- - name : Optimize Assets
90- run : |
91- # HTML Minification
92- html-minifier-terser \
93- --input-dir dist \
94- --output-dir dist \
95- --file-ext html \
96- --collapse-whitespace \
97- --remove-comments \
98- --remove-redundant-attributes \
99- --remove-script-type-attributes \
100- --remove-style-link-type-attributes \
101- --use-short-doctype \
102- --minify-css true \
103- --minify-js true \
104- || echo "HTML minification failed, continuing..."
105-
106- # SVG Optimization (only if SVG files exist)
107- if find dist -name "*.svg" -type f -print -quit | grep -q .; then
108- svgo -f dist -r
109- else
110- echo "No SVG files found to optimize"
111- fi
112-
113- - name : Deploy to GitHub Pages
114- uses : peaceiris/actions-gh-pages@v3
115- if : github.ref == 'refs/heads/master' && github.event_name != 'pull_request'
41+ - name : Upload artifact
42+ uses : actions/upload-pages-artifact@v2
11643 with :
117- github_token : ${{ secrets.ESHANIZED_GH_TOKEN }}
118- publish_dir : ./dist
119- cname : eshanized.is-a.dev
120- user_name : ' eshanized'
121- user_email : ' m.eshanized@gmail.com'
122- commit_message : ' Deploy to GitHub Pages'
123- full_commit_message : ' Deploy to GitHub Pages from @ ${{ github.sha }}'
44+ path : ./out
12445
125- - name : Report Status
126- if : always() && github.event_name == 'pull_request'
127- uses : actions/github-script@v6
128- with :
129- script : |
130- const { conclusion } = context;
131- const message = conclusion === 'success'
132- ? '✅ Deployment successful'
133- : '❌ Deployment failed';
134- github.rest.issues.createComment({
135- issue_number: context.issue.number,
136- owner: context.repo.owner,
137- repo: context.repo.repo,
138- body: message
139- });
46+ deploy :
47+ environment :
48+ name : github-pages
49+ url : ${{ steps.deployment.outputs.page_url }}
50+ runs-on : ubuntu-latest
51+ needs : build
52+ steps :
53+ - name : Deploy to GitHub Pages
54+ id : deployment
55+ uses : actions/deploy-pages@v2
0 commit comments