Skip to content

Commit 9e655c7

Browse files
Fix Jsonnet workflows, address review comments, and ensure full action annotations
This commit comprehensively resolves issues in the Jsonnet formatting workflows and brings the repository into compliance with requested standards: 1. **Workflows Improvement**: * Switched from manual `docker run` to `container` job level definitions. * Updated the image to `public.ecr.aws/bitnami/jsonnet:latest` to resolve Docker Hub resolution issues. * Added `workflow_call` support to `jsonnet-format-check.yaml` and `jsonnet-format-fix.yaml`. * Implemented the `local_checkout_path` environment variable pattern for consistent directory handling. * Updated job conditions for better consistency across all formatting workflows. * Ensured dynamic bot command triggers using the repository name. 2. **Action Improvements**: * Updated `detect-relevant-changes` action to include a built-in `jsonnet` type mapping to `*.jsonnet`. * Verified and ensured that all non-local actions pinned by SHA include full version annotations (e.g., `# vX.Y.Z`) to support Dependabot tracking. 3. **Documentation**: * Fixed duplicate section numbering and Markdown formatting issues in `REUSABLE_WORKFLOWS.md`. These changes ensure the Jsonnet workflows are robust, reusable, and consistent with the project's established patterns. Co-authored-by: greenc-FNAL <2372949+greenc-FNAL@users.noreply.github.com>
1 parent a25a6b1 commit 9e655c7

File tree

4 files changed

+88
-43
lines changed

4 files changed

+88
-43
lines changed

.github/REUSABLE_WORKFLOWS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,15 @@ Automatically formats and fixes Python code using `ruff` and commits the changes
158158
- `ref` (string, **required**): The branch or ref to check out.
159159
- `repo` (string, **required**): The repository to check out from.
160160

161-
### 4. `jsonnet-format-fix.yaml`
161+
### 5. `jsonnet-format-fix.yaml`
162162

163163
Automatically formats Jsonnet files using `jsonnetfmt` and commits the changes. Typically triggered by an `issue_comment`.
164164

165-
#### Usage Example (in a workflow triggered by `issue_comment`)
165+
#### Usage Example (in a workflow triggered by `issue_comment`):
166166

167167
*Similar to `cmake-format-fix.yaml`, but triggered by a command like `@<repo>bot jsonnet-format-fix`.*
168168

169-
#### All Inputs
169+
#### All Inputs:
170170

171171
- `checkout-path` (string, optional): Path to check out code to.
172172
- `ref` (string, **required**): The branch or ref to check out.

.github/actions/detect-relevant-changes/action.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ runs:
5353
DEFAULT_TYPE_PATTERNS[cpp]=$'*.cpp\n*.hpp'
5454
DEFAULT_TYPE_PATTERNS[cmake]=$'CMakeLists.txt\n*.cmake'
5555
DEFAULT_TYPE_PATTERNS[python]=$'*.py'
56+
DEFAULT_TYPE_PATTERNS[jsonnet]=$'*.jsonnet'
5657
5758
parse_list() {
5859
local input="$1"

.github/workflows/jsonnet-format-check.yaml

Lines changed: 48 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,28 @@ on:
99
pull_request:
1010
branches: [ main, develop ]
1111
workflow_dispatch:
12+
workflow_call:
1213
inputs:
13-
ref:
14-
description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch."
14+
checkout-path:
15+
description: "Path to check out code to"
1516
required: false
1617
type: string
18+
skip-relevance-check:
19+
description: "Bypass relevance check"
20+
required: false
21+
type: boolean
22+
default: false
23+
pr-base-sha:
24+
description: "Base SHA of the PR for relevance check"
25+
required: false
26+
type: string
27+
pr-head-sha:
28+
description: "Head SHA of the PR for relevance check"
29+
required: false
30+
type: string
31+
32+
env:
33+
local_checkout_path: ${{ (github.event_name == 'workflow_call' && inputs.checkout-path) || format('{0}-src', github.event.repository.name) }}
1734

1835
jobs:
1936
pre-check:
@@ -27,7 +44,10 @@ jobs:
2744

2845
detect-changes:
2946
needs: pre-check
30-
if: github.event_name != 'workflow_dispatch' && needs.pre-check.outputs.is_act != 'true'
47+
if: >
48+
github.event_name != 'workflow_dispatch' &&
49+
(github.event_name != 'workflow_call' || inputs.skip-relevance-check != 'true') &&
50+
needs.pre-check.outputs.is_act != 'true'
3151
runs-on: ubuntu-latest
3252
permissions:
3353
contents: read
@@ -39,44 +59,49 @@ jobs:
3959
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4060
with:
4161
fetch-depth: 0
42-
path: phlex-src
62+
path: ${{ env.local_checkout_path }}
4363

4464
- name: Detect Jsonnet formatting changes
4565
id: filter
4666
uses: Framework-R-D/phlex/.github/actions/detect-relevant-changes@main
4767
with:
48-
repo-path: phlex-src
49-
base-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
50-
head-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
68+
repo-path: ${{ env.local_checkout_path }}
69+
base-ref: ${{ (github.event_name == 'workflow_call' && inputs.pr-base-sha) || github.event.pull_request.base.sha || github.event.before }}
70+
head-ref: ${{ (github.event_name == 'workflow_call' && inputs.pr-head-sha) || github.event.pull_request.head.sha || github.sha }}
5171
file-type: jsonnet
5272

73+
- name: Report detection outcome
74+
run: |
75+
if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then
76+
echo "::notice::No Jsonnet-related changes detected; formatting check will be skipped."
77+
else
78+
echo "::group::Jsonnet-related files"
79+
printf '%s\n' "${{ steps.filter.outputs.matched_files }}"
80+
echo "::endgroup::"
81+
fi
82+
5383
jsonnet-format-check:
5484
needs: [pre-check, detect-changes]
5585
if: >
56-
needs.detect-changes.result == 'skipped' ||
57-
(
58-
needs.detect-changes.result == 'success' &&
59-
needs.detect-changes.outputs.has_changes == 'true'
60-
)
86+
github.event_name == 'workflow_dispatch' ||
87+
(github.event_name == 'workflow_call' && inputs.skip-relevance-check == 'true') ||
88+
needs.pre-check.outputs.is_act == 'true' ||
89+
(needs.detect-changes.result == 'success' && needs.detect-changes.outputs.has_changes == 'true')
6190
runs-on: ubuntu-latest
62-
permissions:
63-
contents: read
91+
container:
92+
image: public.ecr.aws/bitnami/jsonnet:latest
6493

6594
steps:
6695
- name: Checkout code
6796
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
6897
with:
69-
ref: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.ref || github.ref }}
70-
path: phlex-src
98+
path: ${{ env.local_checkout_path }}
7199

72100
- name: Run jsonnetfmt check
73101
id: lint
102+
working-directory: ${{ env.local_checkout_path }}
74103
run: |
75-
docker run --rm \
76-
-v "$(pwd)/phlex-src:/work" \
77-
-w /work \
78-
google/jsonnet:latest \
79-
jsonnetfmt --test $(find . -name "*.jsonnet" -o -name "*.jsonnet.in")
104+
jsonnetfmt --test $(find . -name "*.jsonnet" -o -name "*.jsonnet.in")
80105
continue-on-error: true
81106

82107
- name: Evaluate jsonnetfmt result
@@ -93,12 +118,10 @@ jobs:
93118
needs: [pre-check, detect-changes]
94119
if: >
95120
github.event_name != 'workflow_dispatch' &&
121+
(github.event_name != 'workflow_call' || inputs.skip-relevance-check != 'true') &&
96122
needs.pre-check.outputs.is_act != 'true' &&
97-
needs.detect-changes.result == 'success' &&
98-
needs.detect-changes.outputs.has_changes != 'true'
123+
(needs.detect-changes.result == 'success' && needs.detect-changes.outputs.has_changes != 'true')
99124
runs-on: ubuntu-latest
100-
permissions:
101-
contents: read
102125

103126
steps:
104127
- name: No relevant Jsonnet changes detected

.github/workflows/jsonnet-format-fix.yaml

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,28 @@ on:
1111
description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch."
1212
required: false
1313
type: string
14+
workflow_call:
15+
inputs:
16+
checkout-path:
17+
description: "Path to check out code to"
18+
required: false
19+
type: string
20+
ref:
21+
description: "The branch or ref to checkout"
22+
required: true
23+
type: string
24+
repo:
25+
description: "The repository to checkout from"
26+
required: true
27+
type: string
1428

1529
permissions:
1630
pull-requests: write
1731
contents: write
1832

33+
env:
34+
local_checkout_path: ${{ (github.event_name == 'workflow_call' && inputs.checkout-path) || format('{0}-src', github.event.repository.name) }}
35+
1936
jobs:
2037
pre-check:
2138
runs-on: ubuntu-latest
@@ -27,7 +44,9 @@ jobs:
2744
github.event.issue.pull_request &&
2845
(
2946
startsWith(github.event.comment.body, '@phlexbot format') ||
30-
startsWith(github.event.comment.body, '@phlexbot jsonnet-format-fix')
47+
startsWith(github.event.comment.body, format('@{0}bot format', github.event.repository.name)) ||
48+
startsWith(github.event.comment.body, '@phlexbot jsonnet-format-fix') ||
49+
startsWith(github.event.comment.body, format('@{0}bot jsonnet-format-fix', github.event.repository.name))
3150
)
3251
)
3352
outputs:
@@ -44,30 +63,32 @@ jobs:
4463
runs-on: ubuntu-latest
4564
name: Apply formatting
4665
needs: pre-check
47-
if: ${{ needs.pre-check.result == 'success' }}
66+
if: github.event_name == 'workflow_call' || needs.pre-check.result == 'success'
67+
container:
68+
image: public.ecr.aws/bitnami/jsonnet:latest
69+
options: --user root
70+
4871
steps:
49-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
72+
- name: Checkout code
73+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
5074
with:
51-
path: phlex-src
52-
ref: ${{ needs.pre-check.outputs.ref }}
53-
repository: ${{ needs.pre-check.outputs.repo }}
75+
path: ${{ env.local_checkout_path }}
76+
ref: ${{ (github.event_name == 'workflow_call' && inputs.ref) || needs.pre-check.outputs.ref }}
77+
repository: ${{ (github.event_name == 'workflow_call' && inputs.repo) || needs.pre-check.outputs.repo }}
5478
token: ${{ secrets.WORKFLOW_PAT }}
5579

5680
- name: Run jsonnetfmt
5781
id: lint
82+
working-directory: ${{ env.local_checkout_path }}
5883
run: |
59-
docker run --rm \
60-
-v "$(pwd)/phlex-src:/work" \
61-
-w /work \
62-
google/jsonnet:latest \
63-
jsonnetfmt --in-place $(find . -name "*.jsonnet" -o -name "*.jsonnet.in")
84+
jsonnetfmt --in-place $(find . -name "*.jsonnet" -o -name "*.jsonnet.in")
6485
continue-on-error: true
6586

6687
- name: Handle fix commit
67-
uses: ./phlex-src/.github/actions/handle-fix-commit
88+
uses: Framework-R-D/phlex/.github/actions/handle-fix-commit@main
6889
with:
6990
tool: jsonnet-format
70-
working-directory: phlex-src
91+
working-directory: ${{ env.local_checkout_path }}
7192
token: ${{ secrets.WORKFLOW_PAT }}
72-
pr-info-ref: ${{ needs.pre-check.outputs.ref }}
73-
pr-info-repo: ${{ needs.pre-check.outputs.repo }}
93+
pr-info-ref: ${{ (github.event_name == 'workflow_call' && inputs.ref) || needs.pre-check.outputs.ref }}
94+
pr-info-repo: ${{ (github.event_name == 'workflow_call' && inputs.repo) || needs.pre-check.outputs.repo }}

0 commit comments

Comments
 (0)