From 2c46e2c63b66a49283e6e877ca35bff7e4e794b1 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Mon, 27 Oct 2025 19:54:00 +1300 Subject: [PATCH 1/4] feat: implement ci workflow --- .github/workflows/ci.yml | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..eda4f62 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +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 \ No newline at end of file From 73b86f8607051e38914c0d336c590c119ef7a1dd Mon Sep 17 00:00:00 2001 From: John Zhang Date: Mon, 27 Oct 2025 20:01:52 +1300 Subject: [PATCH 2/4] test: fail unit test --- src/app.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.test.ts b/src/app.test.ts index d0d5fb9..48d25e9 100644 --- a/src/app.test.ts +++ b/src/app.test.ts @@ -5,7 +5,7 @@ describe('Web App', () => { describe('GET /', () => { it('should return Hello World', async () => { const response = await request(app).get('/'); - + throw new Error('Test error'); expect(response.status).toBe(200); expect(response.text).toBe('Hello World'); }); From b4998a39f9e1767b02c0fa1ad97a96e57e7eb0c0 Mon Sep 17 00:00:00 2001 From: John Zhang Date: Mon, 27 Oct 2025 20:10:48 +1300 Subject: [PATCH 3/4] feat: add final check step to block merge --- .github/workflows/ci.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eda4f62..b124a60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,4 +42,20 @@ jobs: push: false tags: interview-webapp:latest cache-from: type=gha - cache-to: type=gha,mode=max \ No newline at end of file + 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 From 1c2df362759b979965f574e3d5a83187be56b3ae Mon Sep 17 00:00:00 2001 From: John Zhang Date: Mon, 27 Oct 2025 20:13:01 +1300 Subject: [PATCH 4/4] Revert "test: fail unit test" This reverts commit 73b86f8607051e38914c0d336c590c119ef7a1dd. --- src/app.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.test.ts b/src/app.test.ts index 48d25e9..d0d5fb9 100644 --- a/src/app.test.ts +++ b/src/app.test.ts @@ -5,7 +5,7 @@ describe('Web App', () => { describe('GET /', () => { it('should return Hello World', async () => { const response = await request(app).get('/'); - throw new Error('Test error'); + expect(response.status).toBe(200); expect(response.text).toBe('Hello World'); });