From 1c445ddf6fee50962ea52f72eabcc66dd6624577 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Wed, 1 Oct 2025 15:02:03 +0400 Subject: [PATCH 1/2] 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 bd811dc9f6f29f58cc4b4910bb7a0c6ef62569c5) --- .github/workflows/validate-pr.yml | 34 ++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-pr.yml index f5587f7e91..c85dc7a474 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate-pr.yml @@ -6,20 +6,28 @@ on: - main - 8.x - '[0-9]+.[0-9]+' + push: + branches: + - main + - '[0-9]+.[0-9]+' + +permissions: + pull-requests: write # To create/update PR comments jobs: - validate-pr: + validate-apis: name: build runs-on: ubuntu-latest steps: - name: Check pull request was opened from branch - if: github.event.pull_request.head.repo.full_name != 'elastic/elasticsearch-specification' + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != 'elastic/elasticsearch-specification' run: echo "Validation is not supported from forks"; exit 1 - uses: actions/checkout@v4 with: path: ./elasticsearch-specification + persist-credentials: false - uses: actions/checkout@v4 with: @@ -27,12 +35,22 @@ jobs: path: ./clients-flight-recorder token: ${{ secrets.PAT }} ref: ${{ github.base_ref }} + persist-credentials: false - name: Use Node.js 22 uses: actions/setup-node@v4 with: node-version: 22 + - name: Cache JSON report + id: cache-json-report + uses: actions/cache@v4 + with: + path: ./clients-flight-recorder/recordings/types-validation/types-validation.json + 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) }} + restore-keys: | + types-validation-json-${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}- + - name: Install deps 1/2 working-directory: ./clients-flight-recorder run: | @@ -64,12 +82,21 @@ jobs: env: GCS_CREDENTIALS: ${{ secrets.GCS_CREDENTIALS }} - - name: Run validation + - name: Run validation (Push) + if: github.event_name == 'push' + working-directory: ./clients-flight-recorder/scripts/types-validator + env: + BRANCH: ${{ github.ref_name }} + run: node index.js --generate-report --ci --branch $BRANCH + + - name: Run validation (PR) + if: github.event_name == 'pull_request' id: validation working-directory: ./elasticsearch-specification run: node .github/validate-pr --token ${{ secrets.GITHUB_TOKEN }} - name: Find existing comment + if: github.event_name == 'pull_request' uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0 id: find-comment with: @@ -78,6 +105,7 @@ jobs: body-includes: 'Following you can find the validation changes' - name: Create or update comment + if: github.event_name == 'pull_request' uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0 with: token: ${{ secrets.GITHUB_TOKEN }} From f6452887d88ed2c4496a519195a69ae448ea7a20 Mon Sep 17 00:00:00 2001 From: Quentin Pradet Date: Wed, 1 Oct 2025 19:00:33 +0400 Subject: [PATCH 2/2] Apply changes from main --- .../workflows/{validate-pr.yml => validate-apis.yml} | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) rename .github/workflows/{validate-pr.yml => validate-apis.yml} (93%) diff --git a/.github/workflows/validate-pr.yml b/.github/workflows/validate-apis.yml similarity index 93% rename from .github/workflows/validate-pr.yml rename to .github/workflows/validate-apis.yml index c85dc7a474..c4e1adc4bb 100644 --- a/.github/workflows/validate-pr.yml +++ b/.github/workflows/validate-apis.yml @@ -4,7 +4,6 @@ on: pull_request: branches: - main - - 8.x - '[0-9]+.[0-9]+' push: branches: @@ -47,9 +46,9 @@ jobs: uses: actions/cache@v4 with: path: ./clients-flight-recorder/recordings/types-validation/types-validation.json - 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) }} + key: types-validation-json-${{ github.event_name == 'pull_request' && format('{0}-{1}', github.base_ref, github.event.pull_request.base.sha) || format('{0}-{1}', github.ref_name, github.sha) }} restore-keys: | - types-validation-json-${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}- + types-validation-json-${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}- - name: Install deps 1/2 working-directory: ./clients-flight-recorder @@ -72,15 +71,14 @@ jobs: - name: Download artifacts working-directory: ./clients-flight-recorder run: | - if [[ -n "${GITHUB_BASE_REF+x}" ]]; then + if [[ -n "${GITHUB_BASE_REF:-}" ]]; then branch=$GITHUB_BASE_REF else branch=$GITHUB_REF_NAME fi + echo "Using branch: $branch" node scripts/upload-recording/download.js --branch $branch --git node scripts/clone-elasticsearch/index.js --branch $branch - env: - GCS_CREDENTIALS: ${{ secrets.GCS_CREDENTIALS }} - name: Run validation (Push) if: github.event_name == 'push'