1+ name : CI/CD Pipeline
2+
3+ on :
4+ push :
5+ branches : [ main, develop ]
6+ pull_request :
7+ branches : [ main ]
8+ workflow_dispatch : # Allow manual triggering
9+
10+ env :
11+ REGISTRY : ghcr.io
12+ IMAGE_NAME : ${{ github.repository }}
13+ # For your repository: muhammadhammad2005/Matchly
14+
15+ jobs :
16+ test :
17+ name : Test and Lint
18+ runs-on : ubuntu-latest
19+
20+ steps :
21+ - name : Checkout code
22+ uses : actions/checkout@v4
23+
24+ - name : Setup Node.js
25+ uses : actions/setup-node@v4
26+ with :
27+ node-version : ' 18'
28+ cache : ' npm'
29+
30+ - name : Install dependencies
31+ run : npm ci
32+
33+ - name : Run security audit
34+ run : npm audit --audit-level=moderate || true
35+
36+ - name : Check HTML validity (basic)
37+ run : |
38+ if [ -f index.html ]; then
39+ echo "Checking HTML structure..."
40+ # Basic HTML validation using tidy-html5 if available
41+ if command -v tidy &> /dev/null; then
42+ tidy -q -errors index.html 2>&1 | head -20 || true
43+ fi
44+ fi
45+
46+ - name : Check for broken links
47+ run : |
48+ if command -v linkchecker &> /dev/null; then
49+ linkchecker --check-extern index.html || true
50+ else
51+ echo "Linkchecker not installed, skipping..."
52+ fi
53+
54+ build-docker :
55+ name : Build Docker Image
56+ runs-on : ubuntu-latest
57+ needs : test
58+ if : github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
59+
60+ permissions :
61+ contents : read
62+ packages : write
63+
64+ steps :
65+ - name : Checkout code
66+ uses : actions/checkout@v4
67+
68+ - name : Set up Docker Buildx
69+ uses : docker/setup-buildx-action@v3
70+
71+ - name : Log in to Container Registry
72+ uses : docker/login-action@v3
73+ with :
74+ registry : ${{ env.REGISTRY }}
75+ username : ${{ github.actor }}
76+ password : ${{ secrets.GITHUB_TOKEN }}
77+
78+ - name : Extract metadata
79+ id : meta
80+ uses : docker/metadata-action@v5
81+ with :
82+ images : ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
83+ tags : |
84+ type=ref,event=branch
85+ type=ref,event=pr
86+ type=semver,pattern={{version}}
87+ type=semver,pattern={{major}}.{{minor}}
88+ type=sha,prefix={{branch}}-
89+
90+ - name : Build and push Docker image
91+ uses : docker/build-push-action@v5
92+ with :
93+ context : .
94+ push : ${{ github.event_name != 'pull_request' }}
95+ tags : ${{ steps.meta.outputs.tags }}
96+ labels : ${{ steps.meta.outputs.labels }}
97+ cache-from : type=gha
98+ cache-to : type=gha,mode=max
99+
100+ deploy-vercel :
101+ name : Deploy to Vercel
102+ runs-on : ubuntu-latest
103+ needs : build-docker
104+ if : github.event_name == 'push' && github.ref == 'refs/heads/main'
105+
106+ steps :
107+ - name : Checkout code
108+ uses : actions/checkout@v4
109+
110+ - name : Deploy to Vercel
111+ uses : amondnet/vercel-action@v25
112+ with :
113+ vercel-token : ${{ secrets.VERCEL_TOKEN }}
114+ vercel-org-id : ${{ secrets.VERCEL_ORG_ID }}
115+ vercel-project-id : ${{ secrets.VERCEL_PROJECT_ID }}
116+ vercel-args : ' --prod'
117+ working-directory : ./
118+
119+ security-scan :
120+ name : Security Scan
121+ runs-on : ubuntu-latest
122+ needs : test
123+
124+ steps :
125+ - name : Checkout code
126+ uses : actions/checkout@v4
127+
128+ - name : Run Trivy vulnerability scanner
129+ uses : aquasecurity/trivy-action@master
130+ with :
131+ scan-type : ' fs'
132+ scan-ref : ' .'
133+ format : ' sarif'
134+ output : ' trivy-results.sarif'
135+
136+ - name : Upload Trivy scan results to GitHub Security tab
137+ uses : github/codeql-action/upload-sarif@v3
138+ if : always()
139+ with :
140+ sarif_file : ' trivy-results.sarif'
141+
142+ notify :
143+ name : Notify Status
144+ runs-on : ubuntu-latest
145+ needs : [test, build-docker, deploy-vercel]
146+ if : always()
147+
148+ steps :
149+ - name : Determine workflow status
150+ id : check-status
151+ run : |
152+ if [[ "${{ needs.test.result }}" == "success" && "${{ needs.build-docker.result }}" == "success" ]]; then
153+ echo "status=success" >> $GITHUB_OUTPUT
154+ echo "message=✅ All checks passed successfully!" >> $GITHUB_OUTPUT
155+ else
156+ echo "status=failure" >> $GITHUB_OUTPUT
157+ echo "message=❌ Some checks failed. Please review the logs." >> $GITHUB_OUTPUT
158+ fi
159+
160+ - name : Send Slack notification (optional)
161+ if : failure()
162+ uses : 8398a7/action-slack@v3
163+ with :
164+ status : ${{ steps.check-status.outputs.status }}
165+ text : ${{ steps.check-status.outputs.message }}
166+ env :
167+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK_URL }}
0 commit comments