# ワークフローにスクリプトを追加する

GitHub Actionsワークフローを使用してスクリプトを実行できます。

GitHub Actions ワークフローを使用してスクリプトとシェル コマンドを実行し、割り当てられたランナーで実行できます。 この例では、キーワード `run`を使用してランナーで コマンド`npm install -g bats` を実行する方法を示します。

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

ワークフローを使用してリポジトリに格納されているスクリプトを実行するには、まずリポジトリをランナーにチェックする必要があります。 これを行うと、キーワード`run`を使用してランナーでスクリプトを実行できます。 次の例では、それぞれ別のジョブ ステップで 2 つのスクリプトを実行します。 ランナー上のスクリプトの場所は、実行コマンドの既定の作業ディレクトリを設定することによって指定されます。 詳しくは、「[既定のシェルと作業ディレクトリの設定](/ja/enterprise-server@3.22/actions/how-tos/write-workflows/choose-what-workflows-do/set-default-values-for-jobs)」をご覧ください。

```yaml
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 ランナーで実行されるワークフローの場合は、スクリプトを実行する前に、ワークフロー ジョブで実行アクセス許可をファイルに付与するコマンドを追加できます。

```yaml
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` キーワードについて詳しくは、「[GitHub Actions　のワークフロー構文](/ja/enterprise-server@3.22/actions/reference/workflows-and-actions/workflow-syntax#jobsjob_idstepsrun)」をご覧ください。