Skip to main content

워크플로에 스크립트 추가

스크립트 실행을 위해 GitHub Actions 워크플로를 사용할 수 있습니다.

GitHub Actions 워크플로를 사용하여 스크립트 및 셸 명령을 실행할 수 있으며, 이후 할당된 실행기에서 실행됩니다. 이 예제에서는 작업에서 run 키워드를 사용하여 실행기에서 npm install -g bats 명령을 실행하는 방법을 보여줍니다.

jobs:
  example-job:
    runs-on: ubuntu-latest
    steps:
      - run: npm install -g bats

워크플로를 사용하여 리포지토리에 저장된 스크립트를 실행하려면 먼저 리포지토리를 실행기로 검사 합니다. 이렇게 하면 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@v4  
      - 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@v4  
      - 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 키워드 사용에 관한 자세한 내용은 "GitHub Actions에 대한 워크플로 구문"을 참조하세요.