Skip to content

Commit fd903bd

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

File tree

1 file changed

+73
-17
lines changed

1 file changed

+73
-17
lines changed

.github/workflows/ci.yaml

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

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-
60116
- name: Pack
61117
run: npm pack
62118

0 commit comments

Comments
 (0)