CI/CD 플랫폼
workflows
jobs
steps
actions
name: Node.js CI #이름
on:
push: #트리거 이벤트
branches: [ "main" ]
jobs:
build: #이름
runs-on: ubuntu-latest # 실행 환경
steps:
- uses: actions/checkout@v3 #actios 레포 받기
- name: Use Node.js 18
uses: actions/setup-node@v3 # 노드 설치
with:
node-version: 18
- run: npm install #dependencies 추가
- run: npm run build # 빌드
- run: npm test # 테스트
가장 상위 개념
하나의 레포지토리에 여러 개의 워크플로우를 작성할 수 있다.
.gitbub/workflows 폴더 아래에 YAML 파일로 작성
on을 통해 워크 플로우가 수행 되는 트리거를 설정할 수 있다.
[트리거 종류](https://docs.github.com/ko/github-ae@latest/actions/using-workflows/events-that-trigger-workflows#gollum) `push`
```yaml
on:
push:
branches:
- main
```
`pull_request`
```yaml
on:
pull_request:
branches:
- main
```
`schedule`
```yaml
on:
schedule:
- cron: '0 0 * * *' # 매일 00:00 UTC에 실행
```
cron?
![](https://velog.velcdn.com/images/eunbeann/post/ce56a598-54b5-4548-b9a0-cad4832d0e2e/image.png)
- **[Crontab.guru - The cron schedule expression editor](https://crontab.guru/)**
[[Cron] 크론(cron) 표현식 정리](https://zamezzz.tistory.com/197)
`delete`
```yaml
on:
delete:
```
# ...(생략)...
jobs:
build: #작업의 이름
runs-on: ubuntu-latest #리눅스의 최신버전으로 실행
# build에 대한 세부 작업
test:
# test에 대한 세부 작업
deploy:
# deploy에 대한 세부 작업
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# 저장소에서 코드 내려 받기
- run: npm install
# 패키지를 설치함
- run: npm test
# 테스트 스크립트 실행
run 속성을 사용한다.
steps:
- name: Checkout Repository
**run**: git checkout main
- name: Install Dependencies
**run**: npm install
- name: Build Project
**run**: npm run build
run 속성을 사용한다.
steps:
- name: Run Custom Script
run: |
echo "Hello, this is a custom script"
mkdir artifacts
cp -r src/* artifacts/
uses 속성을 사용한다.
steps:
- name: Use Third-party Action
**uses**: actions/setup-node@v3
with:
node-version: 14
- name: Install Dependencies
run: npm install
- name: Run Tests
run: npm test
on: pull_request_review
name: Label approved pull requests
jobs:
labelWhenApproved:
name: Label when approved
runs-on: ubuntu-latest
steps:
- name: Label when approved
uses: pullreminders/label-when-approved-action@master
env:
APPROVALS: "2"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ADD_LABEL: "approved"
REMOVE_LABEL: "awaiting%20review"