|
| 1 | +name: Check Generated VRL Docs Freshness |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + merge_group: |
| 6 | + types: [checks_requested] |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.event.number || github.sha }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +env: |
| 16 | + COMMIT_MESSAGE: "Update generated VRL docs" |
| 17 | + COMMIT_AUTHOR: "github-actions[bot]" |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +jobs: |
| 23 | + changes: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + permissions: |
| 26 | + contents: read |
| 27 | + outputs: |
| 28 | + docs: ${{ steps.filter.outputs.docs }} |
| 29 | + steps: |
| 30 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 31 | + - uses: dorny/paths-filter@v3 |
| 32 | + id: filter |
| 33 | + with: |
| 34 | + filters: | |
| 35 | + docs: |
| 36 | + - "lib/vector-vrl/**" |
| 37 | + - "vdev/**" |
| 38 | + - "Cargo.lock" |
| 39 | + - ".github/workflows/check_generated_vrl_docs.yml" |
| 40 | +
|
| 41 | + run-check-generated-vrl-docs: |
| 42 | + needs: changes |
| 43 | + if: needs.changes.outputs.docs == 'true' |
| 44 | + runs-on: ubuntu-24.04-8core |
| 45 | + permissions: |
| 46 | + contents: write |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 49 | + with: |
| 50 | + ref: ${{ github.event.pull_request.head.sha || github.sha }} |
| 51 | + |
| 52 | + - uses: ./.github/actions/setup |
| 53 | + with: |
| 54 | + vdev: true |
| 55 | + mold: false |
| 56 | + cargo-cache: false |
| 57 | + |
| 58 | + - name: Regenerate VRL docs |
| 59 | + run: make generate-vector-vrl-docs |
| 60 | + |
| 61 | + - name: Check for changes |
| 62 | + id: check |
| 63 | + run: | |
| 64 | + git add docs/generated/ |
| 65 | + if git diff --cached --quiet; then |
| 66 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 67 | + else |
| 68 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 69 | + fi |
| 70 | +
|
| 71 | + - name: Check last commit |
| 72 | + if: steps.check.outputs.changed == 'true' |
| 73 | + id: last-commit |
| 74 | + run: | |
| 75 | + MSG=$(git log -1 --pretty=%s) |
| 76 | + AUTHOR=$(git log -1 --pretty=%an) |
| 77 | + if [ "$MSG" = "$COMMIT_MESSAGE" ] && [ "$AUTHOR" = "$COMMIT_AUTHOR" ]; then |
| 78 | + echo "is-auto=true" >> "$GITHUB_OUTPUT" |
| 79 | + else |
| 80 | + echo "is-auto=false" >> "$GITHUB_OUTPUT" |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Commit and push |
| 84 | + if: > |
| 85 | + steps.check.outputs.changed == 'true' |
| 86 | + && steps.last-commit.outputs.is-auto != 'true' |
| 87 | + && github.event_name == 'pull_request' |
| 88 | + && github.event.pull_request.head.repo.full_name == github.repository |
| 89 | + id: push |
| 90 | + continue-on-error: true |
| 91 | + env: |
| 92 | + HEAD_REF: ${{ github.head_ref }} |
| 93 | + run: | |
| 94 | + git config user.name "github-actions[bot]" |
| 95 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 96 | + git commit -m "$COMMIT_MESSAGE" |
| 97 | + git push origin HEAD:refs/heads/$HEAD_REF |
| 98 | +
|
| 99 | + - name: Save PR number for comment workflow |
| 100 | + if: > |
| 101 | + steps.check.outputs.changed == 'true' |
| 102 | + && steps.last-commit.outputs.is-auto != 'true' |
| 103 | + && github.event_name == 'pull_request' |
| 104 | + && steps.push.outcome != 'success' |
| 105 | + run: | |
| 106 | + mkdir -p /tmp/docs-check |
| 107 | + echo "${{ github.event.pull_request.number }}" > /tmp/docs-check/pr-number |
| 108 | +
|
| 109 | + - name: Upload PR metadata |
| 110 | + if: > |
| 111 | + steps.check.outputs.changed == 'true' |
| 112 | + && steps.last-commit.outputs.is-auto != 'true' |
| 113 | + && github.event_name == 'pull_request' |
| 114 | + && steps.push.outcome != 'success' |
| 115 | + uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0 |
| 116 | + with: |
| 117 | + name: vrl-docs-check-pr |
| 118 | + path: /tmp/docs-check/pr-number |
| 119 | + |
| 120 | + - name: Fail if docs are out of date |
| 121 | + if: steps.check.outputs.changed == 'true' |
| 122 | + run: | |
| 123 | + echo "docs/generated/ is out of date. Regenerate with: make generate-vector-vrl-docs" |
| 124 | + exit 1 |
| 125 | +
|
| 126 | + check-generated-vrl-docs: |
| 127 | + if: always() |
| 128 | + runs-on: ubuntu-latest |
| 129 | + needs: run-check-generated-vrl-docs |
| 130 | + steps: |
| 131 | + - run: | |
| 132 | + if [[ "${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}" == "true" ]]; then |
| 133 | + echo "One or more jobs failed or were cancelled" |
| 134 | + exit 1 |
| 135 | + fi |
0 commit comments