Skip to content

Commit a5e062a

Browse files
committed
update indices only if .ts were modified in the commit
1 parent 9ce9b2f commit a5e062a

File tree

1 file changed

+71
-17
lines changed

1 file changed

+71
-17
lines changed

.github/workflows/ci.yaml

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,79 @@ on:
99
types: [published]
1010

1111
jobs:
12+
ts-modified:
13+
name: TS files changed
14+
if: github.event_name == 'pull_request'
15+
runs-on: ubuntu-latest
16+
outputs:
17+
ts_modified: ${{ steps.check-files.outputs.ts_modified }}
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Check for modified .ts files
23+
id: check-files
24+
run: |
25+
if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -E "\.ts$"; then
26+
echo "ts_modified=true" >> $GITHUB_OUTPUT
27+
else
28+
echo "ts_modified=false" >> $GITHUB_OUTPUT
29+
fi
30+
31+
update-indices:
32+
name: Update indices
33+
needs: ts-modified
34+
if: needs.ts-modified.outputs.ts_modified == 'true'
35+
runs-on: ubuntu-latest
36+
outputs:
37+
has_changes: ${{ steps.check_changes.outputs.has_changes }}
38+
steps:
39+
- name: Checkout PR branch
40+
uses: actions/checkout@v4
41+
with:
42+
ref: ${{ github.event.pull_request.head.ref }}
43+
token: ${{ secrets.BOT_GH_TOKEN }}
44+
45+
- name: Generate indices
46+
run: ./generateIndices.sh
47+
48+
- name: Check uncommitted indices
49+
id: check_changes
50+
run: |
51+
echo "has_changes=$([ -n "$(git diff --name-only HEAD "**/index.ts")" ] && echo "true" || echo "false")" >> $GITHUB_OUTPUT
52+
53+
- name: Commit indices
54+
if: steps.check_changes.outputs.has_changes == 'true'
55+
run: |
56+
echo "${{ secrets.BOT_PGP_KEY }}" | gpg --import --batch
57+
git config --global user.name "Cloudnode [bot]"
58+
git config --global user.email "[email protected]"
59+
git config --global user.signingkey "[email protected]"
60+
git add "**/index.ts"
61+
git commit -S -m "chore: update indices"
62+
git push
63+
64+
were-indices-updated:
65+
name: Were indices updated?
66+
needs: update-indices
67+
if: always()
68+
runs-on: ubuntu-latest
69+
outputs:
70+
indices_updated: ${{ steps.check_indices.outputs.indices_updated }}
71+
steps:
72+
- name: Check indices
73+
id: check_indices
74+
run: |
75+
if [ "${{ needs.update-indices.result }}" == "skipped" ]; then
76+
echo "indices_updated=false" >> $GITHUB_OUTPUT
77+
else
78+
echo "indices_updated=${{ needs.update-indices.outputs.has_changes }}" >> $GITHUB_OUTPUT
79+
fi
80+
1281
build:
1382
name: Build
83+
needs: were-indices-updated
84+
if: needs.were-indices-updated.outputs.indices_updated == 'false'
1485
runs-on: ubuntu-latest
1586
steps:
1687
- name: Checkout repository
@@ -40,23 +111,6 @@ jobs:
40111
- name: Build
41112
run: npm run build
42113

43-
- name: Check uncommitted indices
44-
id: uncommitted_indices
45-
if: github.event_name == 'pull_request'
46-
run: |
47-
echo "has_changes=$([ -n "$(git diff --name-only HEAD "**/index.ts")" ] && echo "true" || echo "false")" >> $GITHUB_OUTPUT
48-
49-
- name: Commit indices
50-
if: github.event_name == 'pull_request' && steps.uncommitted_indices.outputs.has_changes == 'true'
51-
run: |
52-
echo "${{ secrets.BOT_PGP_KEY }}" | gpg --import --batch
53-
git config --global user.signingkey "[email protected]"
54-
git config --global user.name "Cloudnode [bot]"
55-
git config --global user.email "[email protected]"
56-
git add "**/index.ts"
57-
git commit -S -m "chore: update indices"
58-
git push
59-
60114
- name: Pack
61115
run: npm pack
62116

0 commit comments

Comments
 (0)