Skip to content
Merged
65 changes: 43 additions & 22 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,56 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build Docker
uses: docker/build-push-action@v6
with:
push: false
tags: news-api:latest
- name: Checkout
uses: actions/checkout@v4

- name: Build Docker Image
run: docker build -t news-api:latest .

- name: Save Docker Image as Tar
run: docker save news-api:latest -o news-api.tar

- name: Upload Docker Image Artifact
uses: actions/upload-artifact@v4
with:
name: news-api-image
path: news-api.tar


test:
runs-on: ubuntu-latest
needs: build
container:
image: news-api:latest
env:
DATABASE_HOST: postgres
DATABASE_PORT: "5432"
DATABASE_USER: postgres
DATABASE_PASSWORD: password
services:
postgres:
image: postgres:alpine
env:
POSTGRES_PASSWORD: password
TZ: UTC
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Seed Prod
run: npm run seed-prod
- name: Clean install dev dependencies
run: npm ci
- name: Run Tests
run: npm test

- name: Download Docker Image Artifact
uses: actions/download-artifact@v4
with:
name: news-api-image

- name: Load Docker Image
run: docker load -i news-api.tar

- name: Run Tests in Container
run: |
docker run --rm --network=host \
-e NODE_ENV=test \
-e DATABASE_HOST=localhost \
-e DATABASE_PORT=5432 \
-e DATABASE_USER=postgres \
-e DATABASE_PASSWORD=password \
-e TZ=UTC \
news-api:latest \
sh -c "npm install --only=dev && npm test"

10 changes: 5 additions & 5 deletions __tests__/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ describe("Articles", () => {
title: "Living in the shadow of a great man",
article_id: 1,
topic: "mitch",
created_at: "2020-07-09T20:11:00.000Z",
created_at: expect.any(String),
votes: 100,
article_img_url:
"https://images.pexels.com/photos/158651/news-newsletter-newspaper-information-158651.jpeg?w=700&h=700",
Expand Down Expand Up @@ -309,15 +309,15 @@ describe("Articles", () => {
{
comment_id: 11,
votes: 0,
created_at: "2020-09-19T23:10:00.000Z",
created_at: expect.any(String),
author: "icellusedkars",
body: "Ambidextrous marsupial",
article_id: 3,
},
{
comment_id: 10,
votes: 0,
created_at: "2020-06-20T07:24:00.000Z",
created_at: expect.any(String),
author: "icellusedkars",
body: "git push origin master",
article_id: 3,
Expand Down Expand Up @@ -610,7 +610,7 @@ describe('Comments', () => {
article_id: 1,
author: "butter_bridge",
votes: 16,
created_at: "2020-10-31T03:03:00.000Z",
created_at: expect.any(String),
});
});
});
Expand All @@ -626,7 +626,7 @@ describe('Comments', () => {
article_id: 1,
author: "butter_bridge",
votes: 12,
created_at: "2020-10-31T03:03:00.000Z",
created_at: expect.any(String),
});
});
});
Expand Down