Skip to content

Commit cd77ee3

Browse files
committed
Cache API validation results (#5376)
* Generate API validation report * Fix path and add cache * Add cache/restore steps * Test with main * Prepare for merge * Use single workflow Also use restore-keys * Remove correct file * Fix zizmor issues * Remove contents: read since the repo is public (cherry picked from commit bd811dc)
1 parent e8e47b5 commit cd77ee3

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

.github/workflows/validate-pr.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,51 @@ on:
66
- main
77
- 8.x
88
- '[0-9]+.[0-9]+'
9+
push:
10+
branches:
11+
- main
12+
- '[0-9]+.[0-9]+'
13+
14+
permissions:
15+
pull-requests: write # To create/update PR comments
916

1017
jobs:
11-
validate-pr:
18+
validate-apis:
1219
name: build
1320
runs-on: ubuntu-latest
1421

1522
steps:
1623
- name: Check pull request was opened from branch
17-
if: github.event.pull_request.head.repo.full_name != 'elastic/elasticsearch-specification'
24+
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != 'elastic/elasticsearch-specification'
1825
run: echo "Validation is not supported from forks"; exit 1
1926

2027
- uses: actions/checkout@v4
2128
with:
2229
path: ./elasticsearch-specification
30+
persist-credentials: false
2331

2432
- uses: actions/checkout@v4
2533
with:
2634
repository: elastic/clients-flight-recorder
2735
path: ./clients-flight-recorder
2836
token: ${{ secrets.PAT }}
2937
ref: ${{ github.base_ref }}
38+
persist-credentials: false
3039

3140
- name: Use Node.js 22
3241
uses: actions/setup-node@v4
3342
with:
3443
node-version: 22
3544

45+
- name: Cache JSON report
46+
id: cache-json-report
47+
uses: actions/cache@v4
48+
with:
49+
path: ./clients-flight-recorder/recordings/types-validation/types-validation.json
50+
key: types-validation-json-${{ github.event_name == 'pull_request' && format('{0}-{1}', github.head_ref, github.event.pull_request.base.sha) || format('{0}-{1}', github.ref_name, github.sha) }}
51+
restore-keys: |
52+
types-validation-json-${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}-
53+
3654
- name: Install deps 1/2
3755
working-directory: ./clients-flight-recorder
3856
run: |
@@ -62,12 +80,21 @@ jobs:
6280
node scripts/upload-recording/download.js --branch $branch --git
6381
node scripts/clone-elasticsearch/index.js --branch $branch
6482
65-
- name: Run validation
83+
- name: Run validation (Push)
84+
if: github.event_name == 'push'
85+
working-directory: ./clients-flight-recorder/scripts/types-validator
86+
env:
87+
BRANCH: ${{ github.ref_name }}
88+
run: node index.js --generate-report --ci --branch $BRANCH
89+
90+
- name: Run validation (PR)
91+
if: github.event_name == 'pull_request'
6692
id: validation
6793
working-directory: ./elasticsearch-specification
6894
run: node .github/validate-pr --token ${{ secrets.GITHUB_TOKEN }}
6995

7096
- name: Find existing comment
97+
if: github.event_name == 'pull_request'
7198
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
7299
id: find-comment
73100
with:
@@ -76,6 +103,7 @@ jobs:
76103
body-includes: 'Following you can find the validation changes'
77104

78105
- name: Create or update comment
106+
if: github.event_name == 'pull_request'
79107
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
80108
with:
81109
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)