Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial push for CI #17

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/build-publish-to-registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish to Docker
on:
push:
branches:
- main
- ci
permissions:
packages: write
jobs:
publish:
runs-on: ubuntu-latest$
services:
mongodb:
image: mongo
ports:
- 27017:27017
steps:
- name: Checkout
uses: actions/checkout@v4
# Add your test steps here if needed...
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=sha
type=semver,pattern={{version}}
dev-latest
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build container
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ steps.meta.outputs.tags }}
48 changes: 48 additions & 0 deletions .github/workflows/run-unit-tests-on-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Run pnpm tests

on:
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
services:
mongodb:
image: mongo
ports:
- 27017:27017
steps:
- uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18.15'

- name: Install pnpm
run: npm install -g pnpm

- name: Install dependencies
run: pnpm install
- name: output list of files
run: ls -la reference-models/src/references
- name: Seed the database
run: pnpm db:init
env:
MONGO_HOST: localhost
MONGO_PORT: 27017
MONGO_DATABASE: catalog-registry
API_KEY: 8904a5a5-24f1-45a1-be87-2984f703ed19
API_URL: http://localhost:3000/v1
PORT: 3000
JOB_TIMEZONE: Europe/Paris
- name: Run tests
run: pnpm test
env:
MONGO_HOST: localhost
MONGO_PORT: 27017
MONGO_DATABASE: catalog-registry
API_KEY: 8904a5a5-24f1-45a1-be87-2984f703ed19
API_URL: http://localhost:3000/v1
PORT: 3000
JOB_TIMEZONE: Europe/Paris
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ dist
reference-models/
.env
static/
.idea/
.idea/

*.iml
2 changes: 1 addition & 1 deletion scripts/dbUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mongoose

const processFiles = files.map(async (file) => {
const filePath = path.join(directoryPath, file);

console.log(`Processing file ${filePath}`)
try {
// Read the JSON-LD file content
const fileContent = await fs.promises.readFile(filePath, "utf8");
Expand Down
16 changes: 7 additions & 9 deletions tests/api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe("API Tests", () => {
describe("GET /v1/jobs/:job - API KEY error", () => {
it("should respond with code 400 and Header error", async () => {

const response = await request(app).get(`/v1/jobs/dbUpdateJob`);
const response = await request(app).get(`/v1/jobs/dbUpdate`);
expect(response.status).to.equal(400);
expect(response.body)
.to.be.an("object")
Expand All @@ -160,8 +160,7 @@ describe("API Tests", () => {
describe("GET /v1/jobs/:job - Job name error", () => {
it("should respond with code 400 and Job name error", async () => {

const response = await request(app).get(`/v1/jobs/dbupdate`).set({ "x-api-key": process.env.API_KEY});
console.log(response.body)
const response = await request(app).get(`/v1/jobs/unknownJob`).set({ "x-api-key": process.env.API_KEY});
expect(response.status).to.equal(400);
expect(response.body)
.to.be.an("object")
Expand All @@ -172,16 +171,15 @@ describe("API Tests", () => {
describe("GET /v1/jobs/:job", () => {
it("should respond with json and a job configuration for the specified job", async () => {

const response = await request(app).get(`/v1/jobs/dbUpdateJob`).set({ "x-api-key": process.env.API_KEY});
const response = await request(app).get(`/v1/jobs/dbUpdate`).set({ "x-api-key": process.env.API_KEY});
expect(response.status).to.equal(200);
console.log(response.body);
});
});

describe("PATCH /v1/jobs/:job - API KEY error", () => {
it("should respond with code 400 and Header error", async () => {

const response = await request(app).patch(`/v1/jobs/dbUpdateJob`);
const response = await request(app).patch(`/v1/jobs/dbUpdate`);
expect(response.status).to.equal(400);
expect(response.body)
.to.be.an("object")
Expand All @@ -198,7 +196,7 @@ describe("API Tests", () => {
};

const response = await request(app)
.patch(`/v1/jobs/dbUpdate`)
.patch(`/v1/jobs/unknownJob`)
.send(payload)
.set({
"x-api-key": process.env.API_KEY,
Expand All @@ -219,7 +217,7 @@ describe("API Tests", () => {
};

const response = await request(app)
.patch(`/v1/jobs/dbUpdateJob`)
.patch(`/v1/jobs/dbUpdate`)
.send(payload)
.set({
"x-api-key": process.env.API_KEY,
Expand All @@ -240,7 +238,7 @@ describe("API Tests", () => {
};

const response = await request(app)
.patch(`/v1/jobs/dbUpdateJob`)
.patch(`/v1/jobs/dbUpdate`)
.send(payload)
.set({
"x-api-key": process.env.API_KEY,
Expand Down