From b64ab9ea056e6f71c629aabc8d9bf53a33146fda Mon Sep 17 00:00:00 2001 From: Jack Luar Date: Sun, 13 Oct 2024 13:38:28 +0000 Subject: [PATCH] replace yamllint with yamlfix, add sanity check before commit in gh action Signed-off-by: Jack Luar --- .../workflows/github-actions-yaml-test.yml | 30 ++++++++++----- .yamllint | 37 ------------------- etc/DependencyInstaller.sh | 2 +- flow/scripts/variables.yaml | 8 +--- yamlfix.toml | 11 ++++++ 5 files changed, 33 insertions(+), 55 deletions(-) delete mode 100644 .yamllint create mode 100644 yamlfix.toml diff --git a/.github/workflows/github-actions-yaml-test.yml b/.github/workflows/github-actions-yaml-test.yml index 3a55cea0e1..61a83e1d14 100644 --- a/.github/workflows/github-actions-yaml-test.yml +++ b/.github/workflows/github-actions-yaml-test.yml @@ -14,16 +14,15 @@ jobs: uses: actions/checkout@v4 with: submodules: 'recursive' - - name: Run YAML script + - name: Run generate-variable-docs.py run: | python3 flow/scripts/generate-variable-docs.py - - name: Run YAML Lint + - name: Run yamlfix check run: | - pip install yamllint==1.35.1 - yamllint flow/scripts/variables.yaml + yamlfix -c yamlfix.toml flow/scripts/variables.yaml --check docs-pr-update: - name: 'Create PR to update ORFS FlowVariables.md' + name: 'Create PR to update ORFS FlowVariables.md and variables.yaml' needs: - docs-test-job runs-on: ubuntu-latest @@ -33,8 +32,12 @@ jobs: - name: Run generate-variable-docs.py run: | python3 flow/scripts/generate-variable-docs.py + - name: Run yamlfix + run: | + pip install yamlfix==1.17.0 + yamlfix -c yamlfix.toml flow/scripts/variables.yaml - name: Create branch if diff exists - id: docs-update + id: variables-update run: | git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" @@ -43,15 +46,22 @@ jobs: else echo "has_update=false" >> "$GITHUB_OUTPUT" fi - git add . + git add flow/scripts/variables.yaml + git add docs/user/FlowVariables.md git commit --signoff -m "[Docs]: Update ORFS FlowVariables.md" + + # Sanity check that no other files are unstaged + if [ -n "$(git status --porcelain)" ]; then + echo "Error: Unstaged changes after commit." + exit 1 + fi - name: Only push if not master if: "github.event.client_payload.branch != 'master'" - id: remote-update-pr + id: variables-update-pr run: | git push origin "HEAD:refs/pull/${{ github.event.client_payload.branch }}/head" - - name: Create docs update PR - if: "steps.remote-update.outputs.has_update == 'true' && github.event.client_payload.branch == 'master'" + - name: Create variables update PR + if: "steps.variables-update.outputs.has_update == 'true' && github.event.client_payload.branch == 'master'" uses: peter-evans/create-pull-request@v5 with: token: ${{ github.token }} diff --git a/.yamllint b/.yamllint deleted file mode 100644 index 524db4c8e8..0000000000 --- a/.yamllint +++ /dev/null @@ -1,37 +0,0 @@ -extends: default - -rules: - # General formatting - indentation: - level: error # options: 'error' (strict), 'warning' (less strict) - spaces: 2 # number of spaces per indentation level - line-length: - max: 120 # maximum allowed length for lines - level: warning - allow-non-breakable-words: false # non-breakable words exceeding line-length - - # Document structure - document-start: - level: error # documents should start with '---' - - # Trailing spaces - trailing-spaces: - level: error # no trailing spaces allowed - - # Comments - comments: - level: warning - require-starting-space: true # comments should have a space after '#' - - # Special characters - key-duplicates: - level: error # duplicate keys are not allowed - truthy: - level: warning # warn on 'yes/no' and 'on/off'; prefer 'true/false' - - # File properties - empty-lines: - max: 2 # no more than 2 consecutive empty lines - level: warning - new-line-at-end-of-file: - level: warning # files should end with a newline diff --git a/etc/DependencyInstaller.sh b/etc/DependencyInstaller.sh index a92b45d5a9..82b91f916d 100755 --- a/etc/DependencyInstaller.sh +++ b/etc/DependencyInstaller.sh @@ -29,7 +29,7 @@ _installCommon() { source /opt/rh/rh-python38/enable set -u fi - local pkgs="pandas numpy firebase_admin click pyyaml yamllint" + local pkgs="pandas numpy firebase_admin click pyyaml yamlfix" if [[ $(id -u) == 0 ]]; then pip3 install --no-cache-dir -U $pkgs else diff --git a/flow/scripts/variables.yaml b/flow/scripts/variables.yaml index 372756162a..6b0816019c 100644 --- a/flow/scripts/variables.yaml +++ b/flow/scripts/variables.yaml @@ -1,5 +1,5 @@ --- -# Prettified using: https://jsonformatter.org/yaml-formatter +# Run the command: yamlfix -c yamlfix.toml flow/scripts/variables.yaml GENERATE_ARTIFACTS_ON_FAILURE: description: > For instance Bazel needs artifacts (.odb and .rpt files) on a failure to @@ -7,23 +7,18 @@ GENERATE_ARTIFACTS_ON_FAILURE: working with a Makefile flow, it is more natural to fail the step and leave the user to manually inspect the logs and artifacts directly via the file system. - Set to 1 to change the behavior to generate artifacts upon failure to e.g. do a global route. The exit code will still be non-zero on all other failures that aren't covered by the "useful to inspect the artifacts on failure" use-case. - Example: just like detailed routing, a global route that fails with congestion, is not a build failure(as in exit code non-zero), it is a successful(as in zero exit code) global route that produce reports detailing the problem. - Detailed route will not proceed, if there is global routing congestion - This allows build systems, such as bazel, to create artifacts for global and detailed route, even if the operation had problems, without having know about the semantics between global and detailed route. - Considering that global and detailed route can run for a long time and use a lot of memory, this allows inspecting results on a laptop for a build that ran on a server. @@ -32,7 +27,6 @@ TNS_END_PERCENT: description: > Default TNS_END_PERCENT value for post CTS timing repair. Try fixing all violating endpoints by default (reduce to 5% for runtime). - Specifies how many percent of violating paths to fix [0-100]. Worst path will always be fixed. default: 100 diff --git a/yamlfix.toml b/yamlfix.toml new file mode 100644 index 0000000000..7226384a44 --- /dev/null +++ b/yamlfix.toml @@ -0,0 +1,11 @@ +explicit_start = true +line_length = 120 +preserve_quotes = true +quote_representation = "'" +section_whitelines = 0 +sequence_style = "block_style" +comments_min_spaces_from_content = 2 +allow_duplicate_keys = false +indent_mapping = 2 +indent_offset = 2 +indent_sequence = 4