Skip to content

Commit be76141

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

File tree

1 file changed

+74
-17
lines changed

1 file changed

+74
-17
lines changed

.github/workflows/ci.yaml

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,82 @@ 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+
with:
22+
ref: ${{ github.event.pull_request.head.ref }}
23+
fetch-depth: 2
24+
25+
- name: Check for modified .ts files
26+
id: check-files
27+
run: |
28+
if git show --name-only --pretty="" ${{ github.event.pull_request.head.sha }} | grep -E "\.ts$"; then
29+
echo "ts_modified=true" >> $GITHUB_OUTPUT
30+
else
31+
echo "ts_modified=false" >> $GITHUB_OUTPUT
32+
fi
33+
34+
update-indices:
35+
name: Update indices
36+
needs: ts-modified
37+
if: needs.ts-modified.outputs.ts_modified == 'true'
38+
runs-on: ubuntu-latest
39+
outputs:
40+
has_changes: ${{ steps.check_changes.outputs.has_changes }}
41+
steps:
42+
- name: Checkout PR branch
43+
uses: actions/checkout@v4
44+
with:
45+
ref: ${{ github.event.pull_request.head.ref }}
46+
token: ${{ secrets.BOT_GH_TOKEN }}
47+
48+
- name: Generate indices
49+
run: ./generateIndices.sh
50+
51+
- name: Check uncommitted indices
52+
id: check_changes
53+
run: |
54+
echo "has_changes=$([ -n "$(git diff --name-only HEAD "**/index.ts")" ] && echo "true" || echo "false")" >> $GITHUB_OUTPUT
55+
56+
- name: Commit indices
57+
if: steps.check_changes.outputs.has_changes == 'true'
58+
run: |
59+
echo "${{ secrets.BOT_PGP_KEY }}" | gpg --import --batch
60+
git config --global user.name "Cloudnode [bot]"
61+
git config --global user.email "[email protected]"
62+
git config --global user.signingkey "[email protected]"
63+
git add "**/index.ts"
64+
git commit -S -m "chore: update indices"
65+
git push
66+
67+
were-indices-updated:
68+
name: Were indices updated?
69+
needs: update-indices
70+
if: always()
71+
runs-on: ubuntu-latest
72+
outputs:
73+
indices_updated: ${{ steps.check_indices.outputs.indices_updated }}
74+
steps:
75+
- name: Check indices
76+
id: check_indices
77+
run: |
78+
if [ "${{ needs.update-indices.result }}" == "skipped" ]; then
79+
echo "indices_updated=false" >> $GITHUB_OUTPUT
80+
else
81+
echo "indices_updated=${{ needs.update-indices.outputs.has_changes }}" >> $GITHUB_OUTPUT
82+
fi
83+
1284
build:
1385
name: Build
86+
needs: were-indices-updated
87+
if: needs.were-indices-updated.outputs.indices_updated == 'false'
1488
runs-on: ubuntu-latest
1589
steps:
1690
- name: Checkout repository
@@ -40,23 +114,6 @@ jobs:
40114
- name: Build
41115
run: npm run build
42116

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-
60117
- name: Pack
61118
run: npm pack
62119

0 commit comments

Comments
 (0)