github action 로컬 테스트하기

act를 활용

1. act 설치

brew install act

//docker기반이므로 도커설치(mac)
//https://docs.docker.com/desktop/setup/install/mac-install/
//에서 해당 설치파일설치

2. workflow 작성

// act -l //현재 github/workflows/ 의 workflows를 확인할 수 있음.

3. .secret 작성, .gitignore에 추가

워크 플로우에서 활용하는 환경변수가 있다면 프로젝트루트에 .secret에 추가하고 ignore에 추가한다.

4. 테스트 이벤트 파일 작성

# event.json 파일 생성
touch event.json

# event.json 내용
//pr 기반
{
  "pull_request": {
    "merged": true,
    "base": {
      "ref": "stage"
    }
  },
  "action": "closed"
}

//push 기반
{
	"ref": "refs/heads/stage",
	"before": "1111111111111111111111111111111111111111",
	"after": "2222222222222222222222222222222222222222",
	"repository": {
		"full_name": "your-org/your-repo"
	},
	"pusher": {
		"name": "your-username"
	}
}

나의 경우 stage에 머지 되서 PR이 닫히면 이벤트가 동작하는 워크플로우이므로 위와 같이 이벤트파일을 작성함.

5. package.json에 테스트 스크립트 추가

//pr 기반
  "scripts": {
    "act:dry": "act pull_request -n -W .github/workflows/ota-version-update.yml -e event.json",
    "act:test": "act pull_request -W .github/workflows/ota-version-update.yml -e event.json --secret-file .secrets",
    "act:verbose": "act -v pull_request -W .github/workflows/ota-version-update.yml -e event.json --secret-file .secrets"
  }

//push 기반
"scripts": {
"act:dry": "act -P ubuntu-latest=node:20 push -n -W .github/workflows/ota-version-update.yml -e event.json",
		"act:test": "act -P ubuntu-latest=node:20 push -W .github/workflows/ota-version-update.yml -e event.json --secret-file .secrets",
		"act:verbose": "act -P ubuntu-latest=node:20 -v push -W .github/workflows/ota-version-update.yml -e event.json --secret-file .secrets",
}

너무 command가 기니까 스크립트로 만든다.

  • dry는 실제 동작이 일어나지 않는다.
  • test는 실제로 일어남
  • verbose는 로그확인을 하면서 실제 test진행

6.테스트 진행

# 드라이런 (실제 실행 X)
yarn act:dry

# 실제 테스트 (시크릿 포함)
yarn act:test

# 상세 로그 보기
yarn act:verbose

참고링크

-https://zion830.tistory.com/163

profile
🌃브로콜리한 개발자🌟

0개의 댓글

Powered by GraphCDN, the GraphQL CDN