diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b124a60 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,61 @@ +name: Continuous Integration + +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + name: Test and Build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + + - name: Set up Node.js + uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 #v6.0.0 + with: + node-version: '20.x' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run npm build + run: npm run build + + - name: Run tests + run: npm test + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@e468171a9de216ec08956ac3ada2f0791b6bd435 # v3.11.1 + + - name: Build Docker image + uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 + with: + context: . + push: false + tags: interview-webapp:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + ci-status: + name: Validate CI Status + runs-on: ubuntu-latest + needs: test + if: always() + steps: + - name: Check all jobs succeeded + run: | + if [ "${{ needs.test.result }}" != "success" ]; then + echo "❌ Pipeline failed: One or more jobs did not complete successfully" + echo "Test job result: ${{ needs.test.result }}" + exit 1 + else + echo "✅ All pipeline steps completed successfully!" + fi \ No newline at end of file