Skip to content
Open
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
2 changes: 2 additions & 0 deletions .github/actions/detect-relevant-changes/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ runs:
DEFAULT_TYPE_PATTERNS[python]=$'*.py'
DEFAULT_TYPE_PATTERNS[md]=$'*.md'
DEFAULT_TYPE_PATTERNS[jsonnet]=$'*.jsonnet\n*.libsonnet'
DEFAULT_TYPE_PATTERNS[yaml]=$'*.yaml\n*.yml'
# Types that do not support .in variants for relevance detection
declare -A NO_IN_VARIANT_TYPES
NO_IN_VARIANT_TYPES[jsonnet]="1"
NO_IN_VARIANT_TYPES[yaml]="1"

parse_list() {
local input="$1"
Expand Down
128 changes: 128 additions & 0 deletions .github/workflows/yaml-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: YAML Check
'run-name': "${{ github.actor }} checking YAML files"

permissions:
contents: read

on:
pull_request:
workflow_dispatch:
inputs:
ref:
description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch."
required: false
type: string

jobs:
pre-check:
runs-on: ubuntu-latest
outputs:
is_act: ${{ steps.detect_act.outputs.is_act }}
ref: ${{ (github.event_name == 'workflow_dispatch' && (github.event.inputs.ref || github.ref)) || github.sha }}
repo: ${{ github.repository }}
base_sha: ${{ github.event.pull_request.base.sha || github.event.before }}
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.result == 'success' &&
github.event_name != 'workflow_dispatch' &&
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: phlex-src
ref: ${{ needs.pre-check.outputs.ref }}
repository: ${{ needs.pre-check.outputs.repo }}

- name: Detect relevant changes
id: filter
uses: Framework-R-D/phlex/.github/actions/detect-relevant-changes@main
with:
repo-path: phlex-src
base-ref: ${{ needs.pre-check.outputs.base_sha }}
head-ref: ${{ needs.pre-check.outputs.ref }}
file-type: yaml

- name: Report detection outcome
run: |
if [ "${{ steps.filter.outputs.matched }}" != "true" ]; then
echo "::notice::No YAML-related changes detected; check will be skipped."
else
echo "::group::YAML-related files"
printf '%s\n' "${{ steps.filter.outputs.matched_files }}"
echo "::endgroup::"
fi

yaml-check:
needs: [pre-check, detect-changes]
if: >
always() &&
(
needs.detect-changes.result == 'skipped' ||
(
needs.detect-changes.result == 'success' &&
needs.detect-changes.outputs.has_changes == 'true'
)
)
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ needs.pre-check.outputs.ref }}
path: phlex-src
repository: ${{ needs.pre-check.outputs.repo }}

- name: Setup Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: '3.x'

- name: Install yamllint
run: pip install yamllint

- name: Run yamllint
id: lint
working-directory: phlex-src
run: yamllint .
continue-on-error: true

- name: Evaluate yamllint result
if: always() && steps.lint.outcome != 'skipped'
run: |
if [ "${{ steps.lint.outcome }}" = "success" ]; then
echo "✅ YAML check passed."
else
echo "::error::YAML check failed."
echo "::error::Comment '@${{ github.event.repository.name }}bot yaml-fix' on the PR to auto-fix."
exit 1
fi

yaml-check-skipped:
needs: [pre-check, detect-changes]
if: >
needs.pre-check.result == 'success' &&
github.event_name != 'workflow_dispatch' &&
needs.pre-check.outputs.is_act != 'true' &&
(needs.detect-changes.result == 'success' && needs.detect-changes.outputs.has_changes != 'true')
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: No relevant YAML changes detected
run: echo "::notice::No YAML-related changes detected; yaml-check skipped."
79 changes: 79 additions & 0 deletions .github/workflows/yaml-fix.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: YAML Fix
'run-name': "${{ github.actor }} fixing YAML files"

on:
issue_comment:
types:
- created
workflow_dispatch:
inputs:
ref:
description: "The branch, ref, or SHA to checkout. Defaults to the repository's default branch."
required: false
type: string

permissions:
pull-requests: write
contents: write

jobs:
pre-check:
runs-on: ubuntu-latest
name: Parse command
if: >
github.event_name == 'workflow_dispatch' ||
(
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(fromJSON('["OWNER", "COLLABORATOR", "MEMBER"]'), github.event.comment.author_association) &&
(
startsWith(github.event.comment.body, format('@{0}bot format', github.event.repository.name)) ||
startsWith(github.event.comment.body, format('@{0}bot yaml-fix', github.event.repository.name))
)
)
outputs:
ref: ${{ (github.event_name == 'workflow_dispatch' && (github.event.inputs.ref || github.ref)) || steps.get_pr.outputs.ref }}
repo: ${{ steps.get_pr.outputs.repo || github.repository }}

steps:
- name: Get PR Info
if: github.event_name == 'issue_comment'
id: get_pr
uses: Framework-R-D/phlex/.github/actions/get-pr-info@main

apply_yaml_fixes:
runs-on: ubuntu-latest
name: Apply YAML fixes
needs: pre-check
if: ${{ needs.pre-check.result == 'success' }}

steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
path: phlex-src
ref: ${{ needs.pre-check.outputs.ref }}
repository: ${{ needs.pre-check.outputs.repo }}
token: ${{ secrets.WORKFLOW_PAT }}

- name: Setup Node.js
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
with:
node-version: '20.x'

- name: Install prettier
run: npm install -g prettier

- name: Apply YAML formatting
run: |
cd phlex-src
prettier --write '**/*.{yaml,yml}'

- name: Handle fix commit
uses: Framework-R-D/phlex/.github/actions/handle-fix-commit@main
with:
tool: YAML formatter
working-directory: phlex-src
token: ${{ secrets.WORKFLOW_PAT }}
pr-info-ref: ${{ needs.pre-check.outputs.ref }}
pr-info-repo: ${{ needs.pre-check.outputs.repo }}
7 changes: 7 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
printWidth: 120
tabWidth: 2
useTabs: false
proseWrap: preserve
singleQuote: false
endOfLine: lf
15 changes: 15 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
extends: default

rules:
line-length:
max: 120
level: warning
indentation:
spaces: 2
comments:
min-spaces-from-content: 1
document-start: disable
truthy:
allowed-values: ['true', 'false']
trailing-spaces: enable
Loading