워크플로우에 스크립트 추가하기
워크플로우에 스크립트 추가하기
GitHub Actions 워크플로우를 사용해 스크립트를 실행할 수 있어요.
출처: 문서
본문
GitHub Actions 워크플로우를 사용해 스크립트와 셸 명령을 실행할 수 있으며, 이들은 할당된 러너에서 실행됩니다. 이 예시는 run 키워드를 사용해 러너에서 npm install -g bats 명령을 실행하는 방법을 보여줍니다.
jobs:
example-job:
runs-on: ubuntu-latest
steps:
- run: npm install -g bats
워크플로우를 사용해 저장소에 저장된 스크립트를 실행하려면 먼저 저장소를 러너에 체크아웃해야 해요. 이렇게 한 후 run 키워드를 사용해 러너에서 스크립트를 실행할 수 있어요. 다음 예시는 각각 별도의 작업 단계에서 두 개의 스크립트를 실행합니다. 러너에서 스크립트의 위치는 run 명령에 대한 기본 작업 디렉토리를 설정해 지정합니다. 자세한 내용은 Setting a default shell and working directory를 참고하세요.
jobs:
example-job:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./scripts
steps:
- name: Check out the repository to the runner
uses: actions/checkout@v6
- name: Run a script
run: ./my-script.sh
- name: Run another script
run: ./my-other-script.sh
워크플로우 작업이 실행하려는 모든 스크립트는 실행 가능해야 합니다. 이렇게 하려면 워크플로우 내에서 스크립트를 실행할 인터프리터에 인수로 전달하거나(예: run: bash script.sh), 파일 자체를 실행 가능하게 만들 수 있어요. 로컬에서 git update-index --chmod=+x PATH/TO/YOUR/script.sh 명령을 사용해 파일에 실행 권한을 부여한 다음 파일을 커밋하고 저장소에 푸시할 수 있어요. 또는 Linux와 Mac 러너에서 실행되는 워크플로우라면, 스크립트 실행 전에 워크플로우 작업에서 실행 권한을 부여하는 명령을 추가할 수 있습니다:
jobs:
example-job:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./scripts
steps:
- name: Check out the repository to the runner
uses: actions/checkout@v6
- name: Make the script files executable
run: chmod +x my-script.sh my-other-script.sh
- name: Run the scripts
run: |
./my-script.sh
./my-other-script.sh
run 키워드에 대한 자세한 내용은 Workflow syntax for GitHub Actions을 참고하세요.