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

Add Codecov to CI #7

Merged
merged 29 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d0348d1
Create test-codecov.yaml
BaptisteLecat Apr 15, 2024
19fb072
Update test-codecov.yaml
BaptisteLecat Apr 15, 2024
783dfba
Update test-codecov.yaml
BaptisteLecat Apr 15, 2024
c4ebc11
Update test-codecov.yaml
BaptisteLecat Apr 15, 2024
a639af3
Update test-codecov.yaml
BaptisteLecat Apr 15, 2024
1971774
Update test-codecov.yaml
BaptisteLecat Apr 16, 2024
34496bd
Make a command to run the test and firebase together
BaptisteLecat Apr 16, 2024
830cf66
Update test-codecov.yaml
BaptisteLecat Apr 16, 2024
d718719
Update test-codecov.yaml
BaptisteLecat Apr 16, 2024
ae4bfca
Update test-codecov.yaml
BaptisteLecat Apr 16, 2024
851312b
Fix
BaptisteLecat Apr 16, 2024
ee7c04e
Update ci-test.sh
BaptisteLecat Apr 16, 2024
07dca4f
fix
BaptisteLecat Apr 16, 2024
c7d12db
Update test-codecov.yaml
BaptisteLecat Apr 16, 2024
32c5e7c
Update ci-test.sh
BaptisteLecat Apr 16, 2024
83f441b
Update test-codecov.yaml
BaptisteLecat Apr 16, 2024
d3d98d9
test
BaptisteLecat Apr 16, 2024
707a9f1
fix
BaptisteLecat Apr 16, 2024
79744e7
Update test-codecov.yaml
BaptisteLecat Apr 16, 2024
81da7c4
Update test-codecov.yaml
BaptisteLecat Apr 16, 2024
582d3c8
test
BaptisteLecat Apr 16, 2024
f37275c
Update package.json
BaptisteLecat Apr 16, 2024
0ecb522
Update app.e2e-spec.ts
BaptisteLecat Apr 16, 2024
1d256d0
Update app.e2e-spec.ts
BaptisteLecat Apr 16, 2024
440d1a2
Update test-codecov.yaml
BaptisteLecat Apr 16, 2024
30db630
Update test-codecov.yaml
BaptisteLecat Apr 16, 2024
7cdb002
Update app.e2e-spec.ts
BaptisteLecat Apr 16, 2024
c4c6236
Update firebase.provider.ts
BaptisteLecat Apr 16, 2024
7d3e8e8
Rework
BaptisteLecat Apr 17, 2024
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
64 changes: 64 additions & 0 deletions .github/workflows/test-codecov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Testing and update Codecov

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
pull_request_review:
types: [submitted]
branches:
- main

jobs:
test-e2e:
environment: prod
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Nécessaire pour récupérer tous les tags

- name: Set up Node.js
uses: actions/setup-node@v1
with:
node-version: "20.x"

- name: Use NPM to install dependencies
uses: actions/setup-node@v1
with:
node-version: "20.x"
- run: npm install

- name: Set .env file
run: |
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> .env
echo "DISCORD_SERVER_ID=${{ secrets.DISCORD_SERVER_ID }}" >> .env
echo "DISCORD_CHANNEL_ID=${{ secrets.DISCORD_CHANNEL_ID }}" >> .env
echo "DISCORD_SALAI_TOKEN=${{ secrets.DISCORD_SALAI_TOKEN }}" >> .env
echo "API_KEY=${{ secrets.API_KEY }}" >> .env

- name: Build application
run: npm run build

- name: Setup Firebase emulator
run: |
curl -sL https://firebase.tools | bash
echo $GCP_SA_KEY > $HOME/gcloud_service_key.json
export GOOGLE_APPLICATION_CREDENTIALS="$HOME/gcloud_service_key.json"
env:
GCP_SA_KEY: ${{ secrets.FIREBASE_SA_KEY }}

- name: Run tests
run: |
export NODE_ENV=development
npm run firebase:emulator:ci

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: ${{ github.repository }}
file: ./coverage/lcov.info
fail_ci_if_error: true
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
</p>

[![codecov](https://codecov.io/gh/BaptisteLecat/weather-journey-image-api/graph/badge.svg?token=JBOHVOITTC)](https://codecov.io/gh/BaptisteLecat/weather-journey-image-api)

## Description

Weather Journey Image API is a RESTful API that generates images based on the weather conditions of a location. It uses the OpenAI API to generate images based on the weather conditions of a location. The API is built using NestJS and is deployed on Google Cloud Run.
Expand Down Expand Up @@ -44,6 +46,10 @@ Start the Firebase Emulator and generate a JWT token for testing.

Reference : https://stackoverflow.com/a/66343248/19101705

### Code Coverage

https://codecov.io/gh/BaptisteLecat/weather-journey-image-api/graphs/sunburst.svg?token=JBOHVOITTC

```bash
$ npm run firebase:emulator
$ curl -X POST \ 'http://127.0.0.1:9099/identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=key' \
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage --no-cache --passWithNoTests",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json --detectOpenHandles",
"test:e2e": "jest --config ./test/jest-e2e.json",
"firebase:emulator": "firebase emulators:start --import ./import",
"firebase:emulator:ci": "firebase emulators:exec \"jest --coverage --no-cache --passWithNoTests\" --import ./import",
"firebase:emulator:export": "firebase emulators:start --import ./import --export-on-exit ./import"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/providers/firebase.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export class FirebaseProvider {
admin.initializeApp();
} else {
// Set the Firebase Auth emulator host : https://stackoverflow.com/a/77929815/19101705
process.env['FIREBASE_AUTH_EMULATOR_HOST'] = 'localhost:9099';
process.env['FIRESTORE_EMULATOR_HOST'] = 'localhost:8080';
process.env['FIREBASE_AUTH_EMULATOR_HOST'] = '127.0.0.1:9099';
process.env['FIRESTORE_EMULATOR_HOST'] = '127.0.0.1:8080';

// Initialize Firebase Admin SDK
admin.initializeApp(
Expand Down
3 changes: 1 addition & 2 deletions test/app.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('API (e2e)', function () {
);

token = await authenticateUser();
console.log(token.length);
expiredToken = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJuYW1lIjoiYWxpY2UiLCJwaWN0dXJlIjoiIiwiZW1haWwiOiJhbGljZUBnbWFpbC5jb20iLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsImF1dGhfdGltZSI6MTcxMzE3NzAyOCwidXNlcl9pZCI6IjNLOWZZemdKR2xJeDRPdVFnZm1VMVlFRG4ybGIiLCJmaXJlYmFzZSI6eyJpZGVudGl0aWVzIjp7ImVtYWlsIjpbImFsaWNlQGdtYWlsLmNvbSJdfSwic2lnbl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn0sImlhdCI6MTcxMzE3NzAyOCwiZXhwIjoxNzEzMTgwNjI4LCJhdWQiOiJ3ZWF0aGVyYXBwLWpvdXJuZXkiLCJpc3MiOiJodHRwczovL3NlY3VyZXRva2VuLmdvb2dsZS5jb20vd2VhdGhlcmFwcC1qb3VybmV5Iiwic3ViIjoiM0s5Zll6Z0pHbEl4NE91UWdmbVUxWUVEbjJsYiJ9.";
});

Expand Down Expand Up @@ -105,8 +106,6 @@ describe('API (e2e)', function () {
.set("Authorization", `Bearer ${token}`)
.set("Content-Type", "application/json")
.send({ "time": "Alice", "weather": "Alice" })
.expect(201)
.expect('Content-Type', /json/)
.expect((res) => {
// Vérification de la structure et des types de l'objet génération
expect(res.body).toEqual(expect.objectContaining({
Expand Down
Loading