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 build tests for Frontend / Backend to CI (GitHub Actions) #247

Closed
devleejb opened this issue Jul 23, 2024 · 5 comments · Fixed by #310
Closed

Add build tests for Frontend / Backend to CI (GitHub Actions) #247

devleejb opened this issue Jul 23, 2024 · 5 comments · Fixed by #310
Assignees
Labels
enhancement 🌟 New feature or request good first issue 🐤 Good for newcomers
Milestone

Comments

@devleejb
Copy link
Member

devleejb commented Jul 23, 2024

What would you like to be added:
Currently, our CI setup using GitHub Actions does not include build tests for both Frontend and Backend applications, making it difficult to determine if the build is successful or not.

To improve the CI pipeline, it is recommended to add build tests for both the Frontend and Backend applications. This will allow us to validate the build process and catch any potential errors early on.

Why is this needed:
Adding build tests for both the Frontend and Backend applications in our CI pipeline will help ensure the stability and quality of our codebase. It will provide a more comprehensive testing environment and help prevent issues from being deployed to production.

@devleejb devleejb added the bug 🐞 Something isn't working label Jul 23, 2024
@devleejb devleejb moved this to Backlog in Yorkie Project - 2024 Jul 23, 2024
@devleejb devleejb added the good first issue 🐤 Good for newcomers label Jul 23, 2024
@devleejb devleejb changed the title Inconsistency between System Dependencies in Docker Image Build and GitHub Action CI Environment Add build tests for Frontend / Backend to CI (GitHub Actions) Jul 25, 2024
@devleejb devleejb added enhancement 🌟 New feature or request and removed bug 🐞 Something isn't working labels Jul 25, 2024
@having-dlrow
Copy link

Could I work on this issue?

@devleejb
Copy link
Member Author

@having-dlrow Sure! This seems to be a good issue to understand CodePair's CI!

@devleejb devleejb moved this from Backlog to In progress in Yorkie Project - 2024 Jul 27, 2024
@having-dlrow
Copy link

having-dlrow commented Jul 28, 2024

Add tests for backend failed.

I plan to add tasks as shown below.

1.Build was successful.2.Test failed due to missing environment variables.

  1. Build
  - name: Run build
    run: npm run build
    working-directory: ${{ env.working-directory }}
  1. Test
  - name: Run test
    run: npm run test

2-1. Test Fail Log

Test Suites: 20 failed, 20 total
Tests:       20 failed, 20 total
Snapshots:   0 total
Time:        8.534 s
Ran all test suites.

    22 afterEach(async () => {
  → 23 	const deleteWorkspaces = prismaService.workspace.deleteMany(
  error: Environment variable not found: DATABASE_URL.
    -->  schema.prisma:10
      | 
    9 |   provider = "mongodb"
  10 |   url      = env("DATABASE_URL")
      | 

  Validation Error Count: 1

For more detailed error information, please refer to https://github.com/having-dlrow/codepair/actions/runs/10114844891.


I think there are three possible solutions:

  1. Using an in-memory database when in a Node.js CI environment.
      // Example
      const Datastore = require('nedb');
      const mongoose = require('mongoose');
      
      let db;
      
      if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'ci') {
        // NeDB setup
        db = new Datastore({ filename: 'datafile', autoload: true });
      } else {
        // MongoDB setup
        mongoose.connect(process.env.DATABASE_URL, {
          useNewUrlParser: true,
          useUnifiedTopology: true,
        });
        db = mongoose.connection;
        db.on('error', console.error.bind(console, 'connection error:'));
        db.once('open', function() {
          console.log('Connected to MongoDB');
        });
      }
      
      module.exports = db;
  1. Installing MongoDB instance on the runner
      jobs:
        test:
          name: Check the source code
          runs-on: ubuntu-latest
          services:
            mongodb:
              image: mongo:latest
              ports:
                - 27017:27017
              options: >-
                --health-cmd "mongo --eval 'db.runCommand({ ping: 1 })'"
                --health-interval 10s
                --health-timeout 5s
                --health-retries 5
          strategy:
            matrix:
              node-version: [18.x]
          env:
            working-directory: ./backend
            DATABASE_URL: mongodb://localhost:27017/testdb
  1. Providing a CI environment (MongoDB) and an env.ci file

Using GitHub secrets to inject values.
However, a MongoDB connection endpoint is required for the CI environment.

  
  # Method of replacing keys
  - name: Replace environment variables in .env.development
    run: |
      sed -i 's/^DATABASE_URL=.*/DATABASE_URL=${{ secrets.DATABASE_URL }}/g' .env.development
      sed -i 's/^OPENAI_API_KEY=.*/OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}/g' .env.development

  # Method of replacing files          
  - name: Make .env.development
    run: |
      touch .env.development
      echo "${{ secrets.env }}" >> .env.development
    shell: bash

if anyone has other solutions or opinions, I would be grateful to hear them.
@devleejb

@devleejb
Copy link
Member Author

devleejb commented Jul 28, 2024

@having-dlrow
It seems that we need to discuss the test environment. I think it is out of scope.

How about we only add build test to this issue and create a new issue for the test environment?
(If you are interested in the new issue, would you enroll the issue? I like your approaches.)

I also have a idea.
I think we can handle the test environment using docker. In yorkie, docker container runs for using mongodb.

https://github.com/yorkie-team/yorkie/blob/52d2732e4a9892db3c1dc91cc033edd004722e1b/.github/workflows/ci.yml#L49-L50

@github-project-automation github-project-automation bot moved this to Backlog in CodePair Aug 20, 2024
@devleejb devleejb moved this from Backlog to In progress in CodePair Aug 20, 2024
@devleejb
Copy link
Member Author

@having-dlrow
Could you share your progress?

@devleejb devleejb modified the milestones: v0.1.3, v0.1.4 Aug 20, 2024
@devleejb devleejb moved this from In progress to Backlog in CodePair Aug 24, 2024
@devleejb devleejb moved this from In progress to Backlog in Yorkie Project - 2024 Aug 24, 2024
@devleejb devleejb removed this from the v0.1.4 milestone Aug 24, 2024
@devleejb devleejb self-assigned this Aug 24, 2024
@devleejb devleejb linked a pull request Aug 24, 2024 that will close this issue
2 tasks
@devleejb devleejb added this to the v0.1.5 milestone Aug 24, 2024
@devleejb devleejb moved this from Backlog to In progress in CodePair Aug 24, 2024
@github-project-automation github-project-automation bot moved this from Backlog to Done in Yorkie Project - 2024 Aug 24, 2024
@github-project-automation github-project-automation bot moved this from In progress to Done in CodePair Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🌟 New feature or request good first issue 🐤 Good for newcomers
Projects
Archived in project
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants