Skip to content

Commit 100766b

Browse files
authored
Update indices only if .ts were modified in the commit (#29)
2 parents 64f6eb5 + 392a3d0 commit 100766b

File tree

1 file changed

+58
-18
lines changed

1 file changed

+58
-18
lines changed

.github/workflows/ci.yaml

Lines changed: 58 additions & 18 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

@@ -68,7 +108,7 @@ jobs:
68108
publish:
69109
name: Publish
70110
needs: build
71-
if: github.event_name == 'release'
111+
if: always() && github.event_name == 'release'
72112
runs-on: ubuntu-latest
73113
permissions:
74114
contents: read

0 commit comments

Comments
 (0)