|
| 1 | +# Copyright 2023 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: Configurations |
| 16 | + |
| 17 | +concurrency: |
| 18 | + group: "configurations-${{ github.workflow }}-${{ github.ref }}" |
| 19 | + cancel-in-progress: true |
| 20 | + |
| 21 | +on: |
| 22 | + pull_request: |
| 23 | + types: [opened,synchronize,reopened] |
| 24 | + paths: |
| 25 | + - 'configurations/**/*.yaml' |
| 26 | + - 'provisioning/schemas/configuration/**/*.json' |
| 27 | + |
| 28 | + |
| 29 | +jobs: |
| 30 | + |
| 31 | + validation: |
| 32 | + runs-on: ubuntu-latest |
| 33 | + permissions: |
| 34 | + contents: read |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout source code |
| 38 | + uses: actions/checkout@v3 |
| 39 | + |
| 40 | + - name: install ajv |
| 41 | + run: npm install -g ajv-cli |
| 42 | + |
| 43 | + - name: Lint configurations |
| 44 | + run: find "${{ github.workspace }}/configurations" -mindepth 2 -maxdepth 2 -type f \( -name "*.yaml" -o -name "*.yml" \) -exec echo {} + |
| 45 | + |
| 46 | + - name: Lint schemas |
| 47 | + run: echo "JSON liniting will be here" |
| 48 | + |
| 49 | + - name: Schema validation |
| 50 | + run: |- |
| 51 | + cd "${{ github.workspace }}" |
| 52 | + for CONFIG_FILE in $(find configurations -mindepth 2 -maxdepth 2 -type f -name "*.yaml"); do |
| 53 | + FILENAME=$(basename -s ".yaml" "${CONFIG_FILE@L}") |
| 54 | + case "${FILENAME}" in |
| 55 | + alerts | dashboards | healthchecks | metrics | services | slos) |
| 56 | + ;; |
| 57 | + *) |
| 58 | + echo "Unknown file ${CONFIG_FILE}" 1>&2 |
| 59 | + continue |
| 60 | + ;; |
| 61 | + esac |
| 62 | + ajv --spec=draft2020 -s "provisioning/schemas/configuration/${FILENAME}.json" -d "${CONFIG_FILE}" |
| 63 | + done |
| 64 | + |
| 65 | + - name: Dry run |
| 66 | + run: echo "Validation of Terraform plan for test configuration will be here" |
0 commit comments