Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 70 additions & 13 deletions .github/REUSABLE_WORKFLOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
The workflows in `Framework-R-D/phlex/` may be invoked as follows:

1. Automatically as part of CI checks on a PR submitted to `Framework-R-D/phlex`, at PR creation time and thereafter on pushes to the PR branch. This should work whether your PR branch is situated in the primary repository or a fork.
1. Via triggering comments on the PR (`@phlexbot <action>`).
1. Via triggering comments on the PR (`@${{ github.event.repository.name }}bot <action>`).
1. Via the "actions" tab on the project's GitHub web page.

Additionally, you can configure your own fork of Phlex to run CI checks on local PRs, and on its default branch, following the instructions below.
Expand Down Expand Up @@ -34,7 +34,7 @@ However, to enable the automatic fixing features (e.g., for `cmake-format-fix` o
1. **Enable Workflows:** By default, GitHub Actions are disabled on forks. You must manually enable them by going to the `Actions` tab of your forked repository and clicking the "I understand my workflows, go ahead and enable them" button.
1. **Create the `WORKFLOW_PAT` Secret:** The auto-fix workflows require a Personal Access Token (PAT) with write permissions to commit changes back to your PR branch. Follow the instructions below to create a PAT and add it as a secret named `WORKFLOW_PAT` **to your forked repository's settings**.

Once you have done this, you can trigger the auto-fix workflows by commenting on a pull request in your fork (e.g., `@phlexbot format`).
Once you have done this, you can trigger the auto-fix workflows by commenting on a pull request in your fork (e.g., `@${{ github.event.repository.name }}bot format`).

### Creating a Personal Access Token (PAT)

Expand All @@ -56,7 +56,7 @@ To use a workflow, you call it from a workflow file in your own repository's `.g
```yaml
jobs:
some_job:
uses: Framework-R-D/phlex/.github/workflows/<workflow_file_name>.yaml@cef968c52aab432b836bb28119a9661c82c8b0d1
uses: Framework-R-D/phlex/.github/workflows/<workflow_file_name>.yaml@<commit_sha>
with:
# ... inputs for the workflow ...
secrets:
Expand All @@ -69,6 +69,25 @@ You should follow the instructions in the previous section to create the `WORKFL

For development purposes, you may choose to use `@main` at your own risk to get the latest changes.

#### Emulating Trigger Types and Relevance Checks

When calling a reusable workflow, it's often desirable to emulate the behavior of the calling workflow's trigger. For example, if your workflow is triggered by a manual `workflow_dispatch`, you likely want the reusable workflow to skip its relevance detection and check all files. Conversely, if triggered by a `pull_request`, you want detection enabled.

You can achieve this by passing the appropriate value to the `skip-relevance-check` input:

```yaml
with:
skip-relevance-check: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'issue_comment' }}
```

Additionally, to ensure the reusable workflow can access the correct code in an extra-repository context, always pass the `ref` and `repo`:

```yaml
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
repo: ${{ github.repository }}
```

---

## Available Workflows and Their Inputs
Expand All @@ -82,7 +101,7 @@ Builds and tests your project using CMake.
```yaml
jobs:
build_and_test:
uses: Framework-R-D/phlex/.github/workflows/cmake-build.yaml@cef968c52aab432b836bb28119a9661c82c8b0d1
uses: Framework-R-D/phlex/.github/workflows/cmake-build.yaml@<commit_sha>
with:
# Optional: A list of build combinations to run (e.g., "gcc/asan clang/tsan")
build-combinations: 'all -clang/valgrind'
Expand Down Expand Up @@ -111,7 +130,7 @@ Checks CMake files for formatting issues using `gersemi`.
```yaml
jobs:
check_cmake_format:
uses: Framework-R-D/phlex/.github/workflows/cmake-format-check.yaml@cef968c52aab432b836bb28119a9661c82c8b0d1
uses: Framework-R-D/phlex/.github/workflows/cmake-format-check.yaml@<commit_sha>
```

#### All Inputs
Expand Down Expand Up @@ -140,7 +159,7 @@ jobs:
github.event.issue.pull_request &&
(github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'OWNER') &&
startsWith(github.event.comment.body, format('@{0}bot format', github.event.repository.name))
uses: Framework-R-D/phlex/.github/workflows/cmake-format-fix.yaml@cef968c52aab432b836bb28119a9661c82c8b0d1
uses: Framework-R-D/phlex/.github/workflows/cmake-format-fix.yaml@<commit_sha>
with:
# The ref and repo of the PR need to be retrieved and passed
ref: ${{ steps.get_pr_info.outputs.ref }}
Expand All @@ -166,7 +185,7 @@ Checks Python code for formatting and type errors using `ruff` and `mypy`.
```yaml
jobs:
check_python:
uses: Framework-R-D/phlex/.github/workflows/python-check.yaml@cef968c52aab432b836bb28119a9661c82c8b0d1
uses: Framework-R-D/phlex/.github/workflows/python-check.yaml@<commit_sha>
```

#### All Inputs
Expand Down Expand Up @@ -195,7 +214,7 @@ jobs:
github.event.issue.pull_request &&
(github.event.comment.author_association == 'COLLABORATOR' || github.event.comment.author_association == 'OWNER') &&
startsWith(github.event.comment.body, format('@{0}bot python-fix', github.event.repository.name))
uses: Framework-R-D/phlex/.github/workflows/python-fix.yaml@cef968c52aab432b836bb28119a9661c82c8b0d1
uses: Framework-R-D/phlex/.github/workflows/python-fix.yaml@<commit_sha>
with:
# The ref and repo of the PR need to be retrieved and passed
ref: ${{ steps.get_pr_info.outputs.ref }}
Expand All @@ -219,7 +238,7 @@ Checks Markdown files for formatting issues using `markdownlint`.
```yaml
jobs:
check_markdown:
uses: Framework-R-D/phlex/.github/workflows/markdown-check.yaml@cef968c52aab432b836bb28119a9661c82c8b0d1
uses: Framework-R-D/phlex/.github/workflows/markdown-check.yaml@<commit_sha>
```

#### All Inputs
Expand Down Expand Up @@ -253,7 +272,7 @@ jobs:
startsWith(github.event.comment.body, format('@{0}bot format', github.event.repository.name)) ||
startsWith(github.event.comment.body, format('@{0}bot markdown-fix', github.event.repository.name))
)
uses: Framework-R-D/phlex/.github/workflows/markdown-fix.yaml@cef968c52aab432b836bb28119a9661c82c8b0d1
uses: Framework-R-D/phlex/.github/workflows/markdown-fix.yaml@<commit_sha>
with:
# The ref and repo of the PR need to be retrieved and passed
ref: ${{ steps.get_pr_info.outputs.ref }}
Expand All @@ -277,7 +296,7 @@ Checks GitHub Actions workflow files for errors and best practices using `action
```yaml
jobs:
check_actions:
uses: Framework-R-D/phlex/.github/workflows/actionlint-check.yaml@cef968c52aab432b836bb28119a9661c82c8b0d1
uses: Framework-R-D/phlex/.github/workflows/actionlint-check.yaml@<commit_sha>
```

#### All Inputs
Expand All @@ -296,7 +315,7 @@ Performs static analysis on the codebase using GitHub CodeQL to identify potenti
```yaml
jobs:
analyze:
uses: Framework-R-D/phlex/.github/workflows/codeql-analysis.yaml@cef968c52aab432b836bb28119a9661c82c8b0d1
uses: Framework-R-D/phlex/.github/workflows/codeql-analysis.yaml@<commit_sha>
```

#### All Inputs
Expand All @@ -308,6 +327,44 @@ jobs:
- `pr-head-repo` (string, optional): The full name of the PR head repository.
- `pr-base-repo` (string, optional): The full name of the PR base repository.

### 5. `jsonnet-format-check.yaml`

Checks Jsonnet files for formatting issues using `jsonnetfmt`.

#### Usage Example

```yaml
jobs:
check_jsonnet:
uses: Framework-R-D/phlex/.github/workflows/jsonnet-format-check.yaml@<commit_sha>
with:
# Optional: bypass detection and check all files (useful for manual triggers)
skip-relevance-check: ${{ github.event_name == 'workflow_dispatch' }}
```

#### All Inputs

- `checkout-path` (string, optional): Path to check out code to.
- `skip-relevance-check` (boolean, optional, default: `false`): Bypass the check that only runs if Jsonnet files have changed.
- `ref` (string, optional): The branch or ref to check out.
- `repo` (string, optional): The repository to check out from.
- `pr-base-sha` (string, optional): Base SHA of the PR for relevance check.
- `pr-head-sha` (string, optional): Head SHA of the PR for relevance check.

### 6. `jsonnet-format-fix.yaml`

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

#### Usage Example

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

#### All Inputs

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

### Other Workflows

The repository also provides `clang-format-check.yaml`, `clang-format-fix.yaml`, `clang-tidy-check.yaml`, and `clang-tidy-fix.yaml`, which can be used in a similar manner.
The repository also provides `clang-format-check.yaml`, `clang-format-fix.yaml`, `clang-tidy-check.yaml`, and `clang-tidy-fix.yaml`. However, these workflows are currently **not** available for reuse via `workflow_call` as they are specifically intended for use on this repository and its forks.
12 changes: 10 additions & 2 deletions .github/actions/detect-relevant-changes/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ runs:
DEFAULT_TYPE_PATTERNS[cmake]=$'CMakeLists.txt\n*.cmake'
DEFAULT_TYPE_PATTERNS[python]=$'*.py'
DEFAULT_TYPE_PATTERNS[md]=$'*.md'

DEFAULT_TYPE_PATTERNS[jsonnet]=$'*.jsonnet\n*.libsonnet'
# Types that do not support .in variants for relevance detection
declare -A NO_IN_VARIANT_TYPES
NO_IN_VARIANT_TYPES[jsonnet]="1"

parse_list() {
local input="$1"
printf '%s' "$input" | tr ',' '\n' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e '/^$/d'
Expand Down Expand Up @@ -134,7 +138,11 @@ runs:
while IFS= read -r pattern; do
pattern=${pattern#./}
[ -z "$pattern" ] && continue
add_pattern_variant "$pattern"
if [ -n "${NO_IN_VARIANT_TYPES[$type]:-}" ]; then
PATTERN_SET["$pattern"]=1
else
add_pattern_variant "$pattern"
fi
done <<< "$patterns"
done
fi
Expand Down
166 changes: 166 additions & 0 deletions .github/workflows/jsonnet-format-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
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:
inputs:
ref:
description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch."
required: false
type: string
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
ref:
description: "The branch, ref, or SHA to checkout"
required: false
type: string
repo:
description: "The repository to checkout from"
required: false
type: string
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 }}
ref: ${{ (github.event_name == 'workflow_call' && inputs.ref) || (github.event_name == 'workflow_dispatch' && (github.event.inputs.ref || github.ref)) || github.sha }}
repo: ${{ (github.event_name == 'workflow_call' && inputs.repo) || github.repository }}
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: >
needs.pre-check.outputs.is_act != 'true' &&
(
github.event_name == 'pull_request' ||
github.event_name == 'push' ||
(
github.event_name == 'workflow_call' &&
inputs.skip-relevance-check != 'true' &&
github.event.inputs == null &&
github.event.comment == null
)
)
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 }}
ref: ${{ needs.pre-check.outputs.ref }}
repository: ${{ needs.pre-check.outputs.repo }}

- 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: >
needs.detect-changes.result == 'skipped' ||
(
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:
ref: ${{ needs.pre-check.outputs.ref }}
repository: ${{ needs.pre-check.outputs.repo }}
path: ${{ env.local_checkout_path }}

- name: Check Jsonnet formatting
id: lint
working-directory: ${{ env.local_checkout_path }}
run: |
find . \( -name "*.jsonnet" -o -name "*.libsonnet" \) -print0 | xargs -0 -r -I {} \
bash -c 'jsonnetfmt --test "{}" || (echo "FAILED: {}" && diff -u <(jsonnetfmt "{}") "{}" && exit 1)'
continue-on-error: true

- name: Evaluate Jsonnet formatting result
if: always()
run: |
if [ "${{ steps.lint.outcome }}" = 'success' ]; then
echo "✅ Jsonnet formatting check passed."
else
echo "::error::Jsonnet formatting issues found. Please review the output above for details."
echo "::error::Run 'jsonnetfmt -i <file>' locally or comment '@${{ github.event.repository.name }}bot format' on the PR to auto-fix."
exit 1
fi

jsonnet-format-check-skipped:
needs: [pre-check, detect-changes]
if: >
needs.pre-check.outputs.is_act != 'true' &&
(
github.event_name == 'pull_request' ||
github.event_name == 'push' ||
(
github.event_name == 'workflow_call' &&
inputs.skip-relevance-check != 'true' &&
github.event.inputs == null &&
github.event.comment == null
)
) &&
(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-related changes detected; jsonnet-format check skipped."
Loading
Loading