Skip to content

Commit f10f30f

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

File tree

1 file changed

+57
-17
lines changed

1 file changed

+57
-17
lines changed

.github/workflows/ci.yaml

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,65 @@ 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+
1267
build:
1368
name: Build
69+
needs: update-indices
70+
if: always() && (needs.update-indices.outputs.has_changes == 'false' || needs.update-indices.result == 'skipped')
1471
runs-on: ubuntu-latest
1572
steps:
1673
- name: Checkout repository
@@ -40,23 +97,6 @@ jobs:
4097
- name: Build
4198
run: npm run build
4299

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-
60100
- name: Pack
61101
run: npm pack
62102

0 commit comments

Comments
 (0)