Tools/gibhub

[GitHub Actions] GitHub Actions를 이용하여 Node Project CI 해보기

MOMOBOB 2022. 8. 22. 00:16
반응형

1. Node Project 생성

CI를 진행할 노드 프로젝트를 준비함.

 

반응형

 

 

2. Workflow 생성

CI를 진행할 레포의 Actions클릭 후 Node.js Configure 클릭.

 

yml 파일 작성

name: Node CI Example

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Use Node.js 17.x
      uses: actions/setup-node@v3
      with:
        node-version: 17.x
        cache: 'npm'
    - run: npm ci
    - run: npm test
      env:
        DB_HOST: ${{ secrets.DB_HOST }}
        DB_USERNAME: ${{ secrets.DB_USERNAME }}
        DB_PASSWORD: ${{ secrets.DB_PASSWORD }}

 

push와 pull request 이벤트가 발생하면 소스를 체크아웃, 노드환경을 설정, 노드모듈설치 후 노드 프로젝트를 테스트하는 워크플로우 작성 

 

※ workflow file의 syntax에 자세한 대한 설명은 아래 링크 참고

https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions#understanding-the-workflow-file

 

Understanding GitHub Actions - GitHub Docs

Overview GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository, or deplo

docs.github.com

※ workflow file의 secrets 환경변수에 대한 설명은 아래링크 참고

https://momobob.tistory.com/77

 

[GitHub Actions] GitHub Actions에서 Secrets 환경변수 사용하기

Node.js DB설정정보를 아래와 같이 config파일로 분할하여 gitignore하여 형상관리를 하지 않는 방법으로 민감정보 노출을 막아왔다. { "development": { "username": "user", "password": "12345", "database": "..

momobob.tistory.com

 

Start Commit으로 github에서 커밋을 하면 main branch의 push 이벤트가 발생하여 우리가 작성한 Workflow가 실행됨.

반응형