Skip to content

Commit

Permalink
Scan all yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Rindrics committed Jun 15, 2024
1 parent 05f36ce commit bf54ef0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- id: foo
run: echo hello
continue-on-error: true

- id: bar
run: sleep 5
Expand Down
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ runs:
steps:
- name: Get current workflow file
id: get-workflow
shell: bash
run: |
WORKFLOW_REF="${{ github.workflow_ref }}"
WORKFLOW_PATH=$(echo "${WORKFLOW_REF}" | cut -d'@' -f1)
WORKFLOW_FILE=".github/workflows/${WORKFLOW_PATH##*/}"
echo "workflow_file=${WORKFLOW_FILE}" >> $GITHUB_OUTPUT
shell: bash
echo "workflow_file=${WORKFLOW_FILE}" >> $GITHUB_ENV
- name: Check parameters
run: ./scripts/validate-param.sh
shell: bash
run: ./scripts/validate-param.sh
env:
PARAMS: ${{ inputs.params }}
WORKFLOW_FILE: ${{ github.workspace }}/${{ steps.get-workflow.outputs.workflow_file }}
WORKFLOW_FILE: ${{ github.workspace }}/${{ env.workflow_file }}
18 changes: 14 additions & 4 deletions scripts/validate-param.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ if [ ! -f "${WORKFLOW_FILE}" ]; then
exit 1
fi

# Load the workflow file content
WORKFLOW_CONTENT=$(cat "${WORKFLOW_FILE}")

# Parse the JSON input and iterate over the checks
echo "${PARAMS}" | jq -c 'to_entries | .[]' | while read -r step; do
STEP_ID=$(echo "${step}" | jq -r '.key')
Expand All @@ -19,11 +22,18 @@ echo "${PARAMS}" | jq -c 'to_entries | .[]' | while read -r step; do
PARAM=$(echo "${param}" | jq -r '.key')
EXPECTED_VALUE=$(echo "${param}" | jq -r '.value')

# Check the parameter in the workflow file
grep -A 5 "id: ${STEP_ID}" "${WORKFLOW_FILE}" | grep "${PARAM}: ${EXPECTED_VALUE}"
# Check the parameter in the workflow file content
STEP_CONTENT=$(echo "${WORKFLOW_CONTENT}" | yq e ".jobs.test.steps[] | select(.id == \"${STEP_ID}\")" -)

if [ -z "${STEP_CONTENT}" ]; then
echo "Step with id ${STEP_ID} not found in the workflow file."
exit 1
fi

ACTUAL_VALUE=$(echo "${STEP_CONTENT}" | yq e ".${PARAM}" -)

if [ $? -ne 0 ]; then
echo "The parameter ${PARAM} for step ${STEP_ID} is not set to ${EXPECTED_VALUE}."
if [ "${ACTUAL_VALUE}" != "${EXPECTED_VALUE}" ]; then
echo "The parameter ${PARAM} for step ${STEP_ID} is not set to ${EXPECTED_VALUE}. Current value: ${ACTUAL_VALUE}"
exit 1
fi

Expand Down

0 comments on commit bf54ef0

Please sign in to comment.