forked from genzzo/ci-cd-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (77 loc) · 2.08 KB
/
ci-cd.yml
File metadata and controls
96 lines (77 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: CI/CD Pipeline
permissions:
contents: write # for checkout
pages: write # for deploying to GitHub Pages
id-token: write # required by deploy-pages@v4
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
ci:
name: Continuous Integration
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: "24"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Check code formatting
run: npm run format:check
- name: Run tests
run: npm test
- name: Build project
run: npm run build
- name: Generate log file
run: |
mkdir -p logs
echo "CI Pipeline ran at $(date)" > logs/ci-pipeline.log
echo "Tests passed" >> logs/ci-pipeline.log
- name: Generate demo HTML page
run: |
mkdir -p public
cp demo/index.html public/
cp dist/sum.js public/
- name: Upload build logs artifact
uses: actions/upload-artifact@v6
with:
name: build-logs
path: logs/
retention-days: 30
- name: Upload demo site artifact
uses: actions/upload-artifact@v6
with:
name: demo-site
path: public/
retention-days: 30
deploy:
name: Deploy to GitHub Pages
needs: ci
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- name: Download artifact
uses: actions/download-artifact@v7
with:
name: demo-site
path: ./public
- name: Upload to GitHub Pages
uses: actions/upload-pages-artifact@v3
with:
path: ./public
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4