🐷

Github Actionsで作業ディレクトリを指定したいときのメモ

2023/02/23に公開

Github Actions を初めて使ってみました。
その際にルートディレクトリ以外でテストを行いたかったのでメモを残しておきます。

今回のディレクトリ構成

root
├── .github/workflows
│   ├── test.yml
└── app1
    ├── eslintrc.js
    ├── jest.config.js
    ├── node_modules
    ├── package-lock.json
    ├── package.json
    ├── src
    └── tsconfig.json

やりたいことは上記の app1 でテストを走らせること。

.github/workflows フォルダを作成して、yml ファイルを作成します。
今回は test.yml としました。

下記のようにする

name: Test

on:
  pull_request:
    types: [opened, synchronize, reopened]
    branches:
      - main

jobs:
  test:
    name: Test
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: ./app1
    steps:
      - uses: actions/checkout@v3

      - uses: actions/setup-node@v3
        with:
          node-version: "18"

      - run: npm ci

      - run: npm run test:ci

working-directory: でパスを指定できました。
ただし./app1 のように./ がないとエラーになったので注意です。

参考

https://zenn.dev/panyoriokome/scraps/dbf23d2327a8cc

GitHubで編集を提案

Discussion