Skip to content

Commit 57b0606

Browse files
committed
base: update to execute only the CI for the packages that have been changed.
1 parent e2bd922 commit 57b0606

File tree

2 files changed

+139
-2
lines changed

2 files changed

+139
-2
lines changed

.github/workflows/ci.yml

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,51 @@ permissions:
1414
contents: read
1515

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

.github/workflows/ci_node.yml

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,51 @@ on:
1111
- "**/*.md"
1212

1313
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'
1559
runs-on: ubuntu-latest
1660

1761
strategy:
@@ -31,3 +75,28 @@ jobs:
3175
- name: Publish to npm (dry)
3276
if: matrix.node-version != 24
3377
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

Comments
 (0)