-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ci/install-slices/similar-behaviour
- Loading branch information
Showing
3 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: CLA Check | ||
on: | ||
pull_request: | ||
workflow_call: | ||
|
||
jobs: | ||
cla-check: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Check if CLA signed | ||
uses: canonical/has-signed-canonical-cla@v1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
name: Lint | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- "main" | ||
paths: | ||
- ".github/workflows/lint.yaml" | ||
- ".github/yamllint.yaml" | ||
schedule: | ||
# Run at 00:00 every day. | ||
# Ref: https://man7.org/linux/man-pages/man5/crontab.5.html | ||
- cron: "0 0 * * *" | ||
workflow_call: | ||
|
||
env: | ||
# chisel-releases branches to lint on. | ||
RELEASES: ${{ toJson('["ubuntu-20.04","ubuntu-22.04","ubuntu-23.10","ubuntu-24.04"]') }} | ||
|
||
jobs: | ||
prepare-lint: | ||
runs-on: ubuntu-latest | ||
name: "Prepare to lint" | ||
outputs: | ||
matrix: ${{ steps.set-output.outputs.matrix }} | ||
main-ref: ${{ steps.set-output.outputs.main_ref }} | ||
steps: | ||
- name: Set output | ||
id: set-output | ||
run: | | ||
set -ex | ||
if [[ | ||
"${{ github.base_ref || github.ref_name }}" == "main" || | ||
"${{ github.event_name }}" == "schedule" | ||
]]; then | ||
echo "matrix={\"ref\":${{ env.RELEASES }}}" >> $GITHUB_OUTPUT | ||
else | ||
echo "matrix={\"ref\":[\"\"]}" >> $GITHUB_OUTPUT | ||
fi | ||
# For PRs to main, use the updated files from PR head_ref by leaving | ||
# main_ref unset. Otherwise, set main_ref to main. | ||
if [[ "${{ github.base_ref }}" != "main" ]]; then | ||
echo "main_ref=main" >> $GITHUB_OUTPUT | ||
fi | ||
lint: | ||
runs-on: ubuntu-latest | ||
name: "Lint" | ||
needs: prepare-lint | ||
strategy: | ||
fail-fast: false | ||
matrix: ${{ fromJson(needs.prepare-lint.outputs.matrix) }} | ||
env: | ||
main-branch-ref: ${{ needs.prepare-lint.outputs.main-ref }} | ||
main-branch-path: files-from-main | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ matrix.ref }} | ||
|
||
- name: Checkout main branch | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ env.main-branch-ref }} | ||
path: ${{ env.main-branch-path }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
set -ex | ||
pip install --upgrade pip | ||
pip install yamllint | ||
- name: Lint with yamllint | ||
env: | ||
config-path: "${{ env.main-branch-path }}/.github/yamllint.yaml" | ||
run: | | ||
set -e | ||
yamllint -c "${{ env.config-path }}" \ | ||
chisel.yaml \ | ||
slices/ | ||
- name: Lint with SDF-specific rules | ||
run: | | ||
set -e | ||
export LC_COLLATE=C | ||
EXIT_CODE=0 | ||
err() { | ||
echo "error: " "$@" >&2 | ||
EXIT_CODE=1 | ||
} | ||
warn() { | ||
echo "warning: " "$@" >&2 | ||
} | ||
for filename in $(find slices/ | grep "\.yaml$" | sort); do | ||
yq '.slices | keys | .[]' "$filename" | sort -C || \ | ||
warn "$filename: slice names are not sorted" | ||
for slice in $(yq '.slices | keys | .[]' "$filename"); do | ||
key="$slice" yq \ | ||
'.slices | with_entries(select(.key == env(key))) | .[].essential[]' \ | ||
"$filename" | sort -C || \ | ||
err "$filename: $slice: \"essential\" entries are not sorted" | ||
key="$slice" yq \ | ||
'.slices | with_entries(select(.key == env(key))) | .[].contents | select(.) | keys | .[]' \ | ||
"$filename" | sort -C || \ | ||
err "$filename: $slice: \"contents\" entries are not sorted" | ||
done | ||
done | ||
exit $EXIT_CODE |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# yamllint configurations. | ||
# Ref: https://yamllint.readthedocs.io/en/stable/configuration.html | ||
|
||
extends: default | ||
|
||
# Ref: https://yamllint.readthedocs.io/en/stable/rules.html | ||
rules: | ||
braces: | ||
forbid: false | ||
min-spaces-inside: 0 | ||
max-spaces-inside: 1 | ||
min-spaces-inside-empty: 0 | ||
max-spaces-inside-empty: 0 | ||
brackets: | ||
forbid: false | ||
min-spaces-inside: 0 | ||
max-spaces-inside: 1 | ||
min-spaces-inside-empty: 0 | ||
max-spaces-inside-empty: 0 | ||
comments: | ||
level: error | ||
comments-indentation: | ||
level: error | ||
document-end: | ||
present: false | ||
document-start: | ||
present: false | ||
empty-lines: | ||
max: 1 | ||
indentation: | ||
spaces: 2 | ||
line-length: | ||
max: 80 |