Skip to content

Commit b06f951

Browse files
pquentingithub-actions[bot]
authored andcommitted
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 26550a9 commit b06f951

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
@@ -5,33 +5,51 @@ on:
55
branches:
66
- main
77
- '[0-9]+.[0-9]+'
8+
push:
9+
branches:
10+
- main
11+
- '[0-9]+.[0-9]+'
12+
13+
permissions:
14+
pull-requests: write # To create/update PR comments
815

916
jobs:
10-
validate-pr:
17+
validate-apis:
1118
name: build
1219
runs-on: ubuntu-latest
1320

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

1926
- uses: actions/checkout@v4
2027
with:
2128
path: ./elasticsearch-specification
29+
persist-credentials: false
2230

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

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

44+
- name: Cache JSON report
45+
id: cache-json-report
46+
uses: actions/cache@v4
47+
with:
48+
path: ./clients-flight-recorder/recordings/types-validation/types-validation.json
49+
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) }}
50+
restore-keys: |
51+
types-validation-json-${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}-
52+
3553
- name: Install deps 1/2
3654
working-directory: ./clients-flight-recorder
3755
run: |
@@ -61,12 +79,21 @@ jobs:
6179
node scripts/upload-recording/download.js --branch $branch --git
6280
node scripts/clone-elasticsearch/index.js --branch $branch
6381
64-
- name: Run validation
82+
- name: Run validation (Push)
83+
if: github.event_name == 'push'
84+
working-directory: ./clients-flight-recorder/scripts/types-validator
85+
env:
86+
BRANCH: ${{ github.ref_name }}
87+
run: node index.js --generate-report --ci --branch $BRANCH
88+
89+
- name: Run validation (PR)
90+
if: github.event_name == 'pull_request'
6591
id: validation
6692
working-directory: ./elasticsearch-specification
6793
run: node .github/validate-pr --token ${{ secrets.GITHUB_TOKEN }}
6894

6995
- name: Find existing comment
96+
if: github.event_name == 'pull_request'
7097
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
7198
id: find-comment
7299
with:
@@ -75,6 +102,7 @@ jobs:
75102
body-includes: 'Following you can find the validation changes'
76103

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

0 commit comments

Comments
 (0)