Backend/Trouble Shooting

[문제 해결] GitHub Actions가 작동하지 않는 문제 해결

sangwonYoon 2023. 7. 30. 18:44

문제 상황

default branch(main branch)가 아닌, 다른 branch에서 GitHub Actions를 실행시키는 과정에서 발생한 문제이다. develop 브랜치에 push하거나, pull request를 할 경우 GitHub Actions가 작동하도록 아래와 같이 workflow 파일을 작성했다.

name: CI for backend

on:
  push:
    paths: "backend/**"
    branches: [ "develop" ]
  pull_request:
    paths: "backend/**"
    branches: [ "develop" ]

...

 

그러나, develop 브랜치로 pull request를 해도 GitHub Actions가 동작하지 않았다.

정상적으로 GitHub Actions가 동작한 결과
backend 디렉토리를 수정하고 develop branch로 pull request를 했음에도 GitHub Actions가 동작하지 않았다.

 

문제 해결

문제의 원인을 한 줄로 요약하자면, develop branch에 workflow 파일이 존재하지 않았던 것이 원인이었다.

이전까지 항상 GitHub Actions를 default branch에서만 실행했고, GitHub 저장소 GUI에서 새로운 workflow 파일을 생성하면 default branch에 생성되어서 default branch에 workflow 파일이 존재하면 GitHub Actions가 동작하는 것으로 착각하고 있었다.

그러나, stackoverflow의 답변을 인용하면 GitHub Actions이 trigger되는 원리는 아래와 같다.

if the event occurred on a particular repository branch, then the workflow files must be present in the repository on that branch.

즉, 이벤트가 특정 branch에서 발생하려면, workflow 파일은 반드시 해당 branch에 존재해야 한다는 의미이다. 여기서 이벤트는 GitHub Actions의 실행 조건을 의미한다.