Skip to content

Commit

Permalink
Simplify interface to receive expects in key: value format
Browse files Browse the repository at this point in the history
  • Loading branch information
Rindrics committed Jun 15, 2024
1 parent 1af5fa8 commit 515ceb4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
uses: ./ # This points to the local action in the repository
with:
params: >
[
{"step_id": "foo", "param": "continue-on-error", "expected_value": "true"},
{"step_id": "bar", "param": "timeout-minutes", "expected_value": "10"}
]
{
"foo": {"continue-on-error": "true"},
"bar": {"timeout-minutes": "10"}
}
- id: foo
run: echo hello
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: 'Expect Self Parameter'
description: 'Check if specific parameters are set for given steps'
inputs:
params:
description: 'List of step-id, param, and expected-value sets in JSON format'
description: 'List of step parameters and values in JSON format'
required: true
type: string
runs:
Expand Down
28 changes: 16 additions & 12 deletions scripts/validate-param.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Extract inputs
PARAMS=$1
PARAMS=$PARAMS

# Check if the workflow file exists
if [ ! -f "${GITHUB_WORKFLOW}" ]; then
Expand All @@ -10,18 +10,22 @@ if [ ! -f "${GITHUB_WORKFLOW}" ]; then
fi

# Parse the JSON input and iterate over the checks
echo "${PARAMS}" | jq -c '.[]' | while read -r check; do
STEP_ID=$(echo "${check}" | jq -r '.step_id')
PARAM=$(echo "${check}" | jq -r '.param')
EXPECTED_VALUE=$(echo "${check}" | jq -r '.expected_value')
echo "${PARAMS}" | jq -c 'to_entries | .[]' | while read -r step; do
STEP_ID=$(echo "${step}" | jq -r '.key')
PARAMS=$(echo "${step}" | jq -r '.value')

# Check the parameter in the workflow file
grep -A 5 "id: ${STEP_ID}" "${GITHUB_WORKFLOW}" | grep "${PARAM}: ${EXPECTED_VALUE}"
echo "${PARAMS}" | jq -c 'to_entries | .[]' | while read -r param; do
PARAM=$(echo "${param}" | jq -r '.key')
EXPECTED_VALUE=$(echo "${param}" | jq -r '.value')

if [ $? -ne 0 ]; then
echo "The parameter ${PARAM} for step ${STEP_ID} is not set to ${EXPECTED_VALUE}."
exit 1
fi
# Check the parameter in the workflow file
grep -A 5 "id: ${STEP_ID}" "${GITHUB_WORKFLOW}" | grep "${PARAM}: ${EXPECTED_VALUE}"

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

echo "The parameter ${PARAM} for step ${STEP_ID} is correctly set to ${EXPECTED_VALUE}."
done
done

0 comments on commit 515ceb4

Please sign in to comment.