|
11 | 11 | - "**/*.md"
|
12 | 12 |
|
13 | 13 | jobs:
|
14 |
| - build: |
| 14 | + # 変更されたファイルをチェックして、どのパッケージのテストを実行するかを決定 |
| 15 | + check-changes: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + outputs: |
| 18 | + run-all: ${{ steps.changes.outputs.run-all }} |
| 19 | + packages: ${{ steps.changes.outputs.packages }} |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + - name: Check for changes |
| 25 | + id: changes |
| 26 | + run: | |
| 27 | + # 前回のコミットとの差分を取得 |
| 28 | + if [ "${{ github.event_name }}" = "push" ]; then |
| 29 | + # pushの場合は前のコミットとの差分 |
| 30 | + CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD) |
| 31 | + else |
| 32 | + # PRの場合はベースブランチとの差分 |
| 33 | + CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD) |
| 34 | + fi |
| 35 | + |
| 36 | + echo "Changed files:" |
| 37 | + echo "$CHANGED_FILES" |
| 38 | + |
| 39 | + # common、core、CI/CDファイル、ルートファイルが変更された場合は全テスト実行 |
| 40 | + if echo "$CHANGED_FILES" | grep -E '^(packages/(common|core)/|\.github/|deno\.json|\.gitignore)'; then |
| 41 | + echo "run-all=true" >> $GITHUB_OUTPUT |
| 42 | + echo "packages=[]" >> $GITHUB_OUTPUT |
| 43 | + else |
| 44 | + # 特定のパッケージのみが変更された場合 |
| 45 | + CHANGED_PACKAGES=$(echo "$CHANGED_FILES" | grep '^packages/' | cut -d'/' -f2 | sort -u | grep -v -E '^(common|core)$' | jq -R -s -c 'split("\n")[:-1]') |
| 46 | + if [ "$CHANGED_PACKAGES" = "[]" ] || [ "$CHANGED_PACKAGES" = '[""]' ]; then |
| 47 | + echo "run-all=false" >> $GITHUB_OUTPUT |
| 48 | + echo "packages=[]" >> $GITHUB_OUTPUT |
| 49 | + else |
| 50 | + echo "run-all=false" >> $GITHUB_OUTPUT |
| 51 | + echo "packages=$CHANGED_PACKAGES" >> $GITHUB_OUTPUT |
| 52 | + fi |
| 53 | + fi |
| 54 | +
|
| 55 | + # 全テストを実行するジョブ |
| 56 | + build-all: |
| 57 | + needs: check-changes |
| 58 | + if: needs.check-changes.outputs.run-all == 'true' |
15 | 59 | runs-on: ubuntu-latest
|
16 | 60 |
|
17 | 61 | strategy:
|
|
31 | 75 | - name: Publish to npm (dry)
|
32 | 76 | if: matrix.node-version != 24
|
33 | 77 | run: deno task dry-publish
|
| 78 | + |
| 79 | + # 特定のパッケージのみをテストするジョブ |
| 80 | + build-packages: |
| 81 | + needs: check-changes |
| 82 | + if: needs.check-changes.outputs.run-all == 'false' && needs.check-changes.outputs.packages != '[]' |
| 83 | + runs-on: ubuntu-latest |
| 84 | + |
| 85 | + strategy: |
| 86 | + matrix: |
| 87 | + node-version: [16, 18, 19, 20, 21, 22, 23, 24] |
| 88 | + package: ${{ fromJson(needs.check-changes.outputs.packages) }} |
| 89 | + |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v4 |
| 92 | + - uses: actions/setup-node@v4 |
| 93 | + with: |
| 94 | + node-version: ${{ matrix.node-version }} |
| 95 | + - uses: denoland/setup-deno@v2 |
| 96 | + with: |
| 97 | + deno-version: 2.x |
| 98 | + - name: Run package-specific node test |
| 99 | + run: deno task test:node:${{ matrix.package }} |
| 100 | + - name: Publish package to npm (dry) |
| 101 | + if: matrix.node-version != 24 |
| 102 | + run: deno task dry-publish:${{ matrix.package }} |
0 commit comments