Skip to content

Commit 721ceaa

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

File tree

1 file changed

+75
-17
lines changed

1 file changed

+75
-17
lines changed

.github/workflows/ci.yaml

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

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-
60118
- name: Pack
61119
run: npm pack
62120

0 commit comments

Comments
 (0)