|
| 1 | +name: CI/CD Angular + Docker + Vercel |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - develop |
| 7 | + - release-* |
| 8 | + - master |
| 9 | + |
| 10 | +env: |
| 11 | + NODE_VERSION: 24 |
| 12 | + APP_NAME: angular-bb |
| 13 | + |
| 14 | +jobs: |
| 15 | + lint: |
| 16 | + name: Lint Code |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: 1. Checkout Source |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: 2. Setup Node.js |
| 23 | + uses: actions/setup-node@v4 |
| 24 | + with: |
| 25 | + node-version: ${{ env.NODE_VERSION }} |
| 26 | + |
| 27 | + - name: 3. Cache npm |
| 28 | + uses: actions/cache@v4 |
| 29 | + with: |
| 30 | + path: ~/.npm |
| 31 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
| 32 | + restore-keys: | |
| 33 | + ${{ runner.os }}-node- |
| 34 | +
|
| 35 | + - name: 4. Install Dependencies |
| 36 | + run: npm ci |
| 37 | + |
| 38 | + - name: 5. Run Linter |
| 39 | + run: npm run lint |
| 40 | + |
| 41 | + test: |
| 42 | + name: Run Unit Tests |
| 43 | + runs-on: ubuntu-latest |
| 44 | + steps: |
| 45 | + - name: 1. Checkout Source |
| 46 | + uses: actions/checkout@v4 |
| 47 | + |
| 48 | + - name: 2. Setup Node.js |
| 49 | + uses: actions/setup-node@v4 |
| 50 | + with: |
| 51 | + node-version: ${{ env.NODE_VERSION }} |
| 52 | + |
| 53 | + - name: 3. Cache npm |
| 54 | + uses: actions/cache@v4 |
| 55 | + with: |
| 56 | + path: ~/.npm |
| 57 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
| 58 | + restore-keys: | |
| 59 | + ${{ runner.os }}-node- |
| 60 | +
|
| 61 | + - name: 4. Install Dependencies |
| 62 | + run: npm ci |
| 63 | + |
| 64 | + - name: 5. Run Tests |
| 65 | + run: npm run test |
| 66 | + |
| 67 | + build-frontend: |
| 68 | + name: Build Angular Frontend |
| 69 | + runs-on: ubuntu-latest |
| 70 | + needs: [lint, test] |
| 71 | + steps: |
| 72 | + - name: 1. Checkout Source |
| 73 | + uses: actions/checkout@v4 |
| 74 | + |
| 75 | + - name: 2. Setup Node.js |
| 76 | + uses: actions/setup-node@v4 |
| 77 | + with: |
| 78 | + node-version: ${{ env.NODE_VERSION }} |
| 79 | + |
| 80 | + - name: 3. Cache npm |
| 81 | + uses: actions/cache@v4 |
| 82 | + with: |
| 83 | + path: ~/.npm |
| 84 | + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} |
| 85 | + restore-keys: | |
| 86 | + ${{ runner.os }}-node- |
| 87 | +
|
| 88 | + - name: 4. Install Dependencies |
| 89 | + run: npm ci |
| 90 | + |
| 91 | + - name: 5. Build Angular App |
| 92 | + run: npm run build -- --configuration production |
| 93 | + |
| 94 | + - name: 6. Upload Angular Dist Artifact |
| 95 | + uses: actions/upload-artifact@v4 |
| 96 | + with: |
| 97 | + name: dist |
| 98 | + path: dist |
| 99 | + |
| 100 | + build-image: |
| 101 | + name: Build & Push Docker Image |
| 102 | + runs-on: ubuntu-latest |
| 103 | + needs: build-frontend |
| 104 | + env: |
| 105 | + DH_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} |
| 106 | + DH_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} |
| 107 | + steps: |
| 108 | + - name: 1. Checkout Source |
| 109 | + uses: actions/checkout@v4 |
| 110 | + |
| 111 | + - name: 2. Set up Docker Buildx |
| 112 | + uses: docker/setup-buildx-action@v3 |
| 113 | + with: |
| 114 | + driver: docker-container |
| 115 | + buildkitd-flags: --debug |
| 116 | + |
| 117 | + - name: 3. Log in to DockerHub |
| 118 | + uses: docker/login-action@v3 |
| 119 | + with: |
| 120 | + username: ${{ env.DH_USERNAME }} |
| 121 | + password: ${{ env.DH_TOKEN }} |
| 122 | + |
| 123 | + - name: 4. Build & Push Docker Image |
| 124 | + uses: docker/build-push-action@v6 |
| 125 | + with: |
| 126 | + context: . |
| 127 | + push: true |
| 128 | + tags: ${{ env.DH_USERNAME }}/angular-topics:latest |
| 129 | + cache-from: type=registry,ref=${{ env.DH_USERNAME }}/angular-topics:latest |
| 130 | + cache-to: type=registry,ref=${{ env.DH_USERNAME }}/angular-topics:latest,mode=max |
| 131 | + |
| 132 | + deploy: |
| 133 | + name: Deploy to Vercel |
| 134 | + runs-on: ubuntu-latest |
| 135 | + needs: build-frontend |
| 136 | + steps: |
| 137 | + - name: 1. Download Angular Dist Artifact |
| 138 | + uses: actions/download-artifact@v4 |
| 139 | + with: |
| 140 | + name: dist |
| 141 | + path: dist |
| 142 | + |
| 143 | + - name: 2. Install Vercel CLI |
| 144 | + run: npm install -g vercel |
| 145 | + |
| 146 | + - name: 3. Deploy to Vercel |
| 147 | + run: vercel dist/${{ env.APP_NAME }}/browser --prod --yes --token=${{ secrets.VERCEL_TOKEN }} |
0 commit comments