1name: CI Pipeline
2
3on:
4 push:
5 branches: [main, develop]
6 pull_request:
7 branches: [main]
8
9env:
10 REGISTRY: ghcr.io
11 IMAGE_NAME: ${{ github.repository }}
12
13jobs:
14 build-and-test:
15 runs-on: ubuntu-latest
16 steps:
17 - uses: actions/checkout@v4
18
19 - name: Setup Node.js
20 uses: actions/setup-node@v4
21 with:
22 node-version: "20"
23 cache: "npm"
24
25 - name: Install dependencies
26 run: npm ci
27
28 - name: Run tests
29 run: npm test
30
31 - name: Build Docker image
32 run: docker build -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} .
33
34 - name: Log in to GitHub Container Registry
35 if: github.event_name == 'push' && github.ref == 'refs/heads/main'
36 uses: docker/login-action@v3
37 with:
38 registry: ${{ env.REGISTRY }}
39 username: ${{ github.actor }}
40 password: ${{ secrets.GITHUB_TOKEN }}
41
42 - name: Push image
43 if: github.event_name == 'push' && github.ref == 'refs/heads/main'
44 run: docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}