greenc-FNAL checking jsonnet format #16
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Jsonnet Format Check | |
| run-name: "${{ github.actor }} checking jsonnet format" | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| on: | |
| pull_request: | |
| branches: [ main, develop ] | |
| workflow_dispatch: | |
| workflow_call: | |
| inputs: | |
| checkout-path: | |
| description: "Path to check out code to" | |
| required: false | |
| type: string | |
| skip-relevance-check: | |
| description: "Bypass relevance check" | |
| required: false | |
| type: boolean | |
| default: false | |
| pr-base-sha: | |
| description: "Base SHA of the PR for relevance check" | |
| required: false | |
| type: string | |
| pr-head-sha: | |
| description: "Head SHA of the PR for relevance check" | |
| required: false | |
| type: string | |
| env: | |
| local_checkout_path: ${{ (github.event_name == 'workflow_call' && inputs.checkout-path) || format('{0}-src', github.event.repository.name) }} | |
| jobs: | |
| pre-check: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| is_act: ${{ steps.detect_act.outputs.is_act }} | |
| steps: | |
| - name: Detect act environment | |
| id: detect_act | |
| uses: Framework-R-D/phlex/.github/actions/detect-act-env@main | |
| detect-changes: | |
| needs: pre-check | |
| if: > | |
| github.event_name != 'workflow_dispatch' && | |
| (github.event_name != 'workflow_call' || inputs.skip-relevance-check != 'true') && | |
| needs.pre-check.outputs.is_act != 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: read | |
| outputs: | |
| has_changes: ${{ steps.filter.outputs.matched }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| path: ${{ env.local_checkout_path }} | |
| - name: Detect Jsonnet formatting changes | |
| id: filter | |
| uses: Framework-R-D/phlex/.github/actions/detect-relevant-changes@main | |
| with: | |
| repo-path: ${{ env.local_checkout_path }} | |
| base-ref: ${{ (github.event_name == 'workflow_call' && inputs.pr-base-sha) || github.event.pull_request.base.sha || github.event.before }} | |
| head-ref: ${{ (github.event_name == 'workflow_call' && inputs.pr-head-sha) || github.event.pull_request.head.sha || github.sha }} | |
| file-type: jsonnet | |
| - name: Report detection outcome | |
| run: | | |
| if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then | |
| echo "::notice::No Jsonnet-related changes detected; formatting check will be skipped." | |
| else | |
| echo "::group::Jsonnet-related files" | |
| printf '%s\n' "${{ steps.filter.outputs.matched_files }}" | |
| echo "::endgroup::" | |
| fi | |
| jsonnet-format-check: | |
| needs: [pre-check, detect-changes] | |
| if: > | |
| github.event_name == 'workflow_dispatch' || | |
| (github.event_name == 'workflow_call' && inputs.skip-relevance-check == 'true') || | |
| needs.pre-check.outputs.is_act == 'true' || | |
| (needs.detect-changes.result == 'success' && needs.detect-changes.outputs.has_changes == 'true') | |
| runs-on: ubuntu-latest | |
| container: | |
| image: public.ecr.aws/bitnami/jsonnet:latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| path: ${{ env.local_checkout_path }} | |
| - name: Run jsonnetfmt check | |
| id: lint | |
| working-directory: ${{ env.local_checkout_path }} | |
| run: | | |
| find . \( -name "*.jsonnet" -o -name "*.libsonnet" \) -print0 | xargs -0 -r jsonnetfmt --test | |
| continue-on-error: true | |
| - name: Evaluate jsonnetfmt result | |
| if: always() | |
| run: | | |
| if [ '${{ steps.lint.outcome }}' = 'success' ]; then | |
| echo "✅ jsonnetfmt check passed." | |
| else | |
| echo "::error::jsonnetfmt check failed. Please review the output above for details." | |
| exit 1 | |
| fi | |
| jsonnet-format-check-skipped: | |
| needs: [pre-check, detect-changes] | |
| if: > | |
| github.event_name != 'workflow_dispatch' && | |
| (github.event_name != 'workflow_call' || inputs.skip-relevance-check != 'true') && | |
| needs.pre-check.outputs.is_act != 'true' && | |
| (needs.detect-changes.result == 'success' && needs.detect-changes.outputs.has_changes != 'true') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: No relevant Jsonnet changes detected | |
| run: echo "::notice::No jsonnet-format relevant changes detected; check skipped." |