Skip to content

Commit

Permalink
fix: if no fossa targets, set fossaAnalyze to N/A
Browse files Browse the repository at this point in the history
move custom property values to fossa job env
  • Loading branch information
elaguerta-nr committed May 23, 2024
1 parent f27e6f2 commit 0d20afe
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/fossa-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
ORG: ${{ github.repository_owner }}
REPO: ${{ github.repository }}
CUSTOM_PROPS_PAT: ${{ secrets.FOSSA_PAT }}
HAS_FOSSA_TARGETS: ""
FOSSA_ANALYZE_RESULT: ""

steps:
- uses: actions/checkout@v3
Expand All @@ -39,15 +41,16 @@ jobs:
then
echo "::error::fossa list-targets ran with errors."
cat $LIST_TARGETS_ERR_FILE
echo "HAS_FOSSA_TARGETS=Error" >> "$GITHUB_OUTPUT"
echo "HAS_FOSSA_TARGETS=Error" >> "$GITHUB_ENV"
elif [[ $(cat $LIST_TARGETS_OUT_FILE | wc -l) -gt 0 ]]
then
echo "::notice::Fossa found analysis targets."
cat $LIST_TARGETS_OUT_FILE
echo "HAS_FOSSA_TARGETS=True" >> "$GITHUB_OUTPUT"
echo "HAS_FOSSA_TARGETS=True" >> "$GITHUB_ENV"
else
echo "::warning::Fossa did not find any analysis targets."
echo "HAS_FOSSA_TARGETS=False" >> "$GITHUB_OUTPUT"
echo "HAS_FOSSA_TARGETS=False" >> "$GITHUB_ENV"
echo "FOSSA_ANALYZE_RESULT=N/A" >> "$GITHUB_ENV"
fi
- name: Set fossaHasTargets custom property
run: |
Expand All @@ -57,7 +60,7 @@ jobs:
-H "Authorization: Bearer $CUSTOM_PROPS_PAT" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$ORG/properties/values \
-d '{"repository_names":["'"${REPO##*/}"'"],"properties":[{"property_name":"fossaHasTargets","value":"'"${{ steps.fossa-list-targets.outputs.HAS_FOSSA_TARGETS }}"'"}]}'
-d '{"repository_names":["'"${REPO##*/}"'"],"properties":[{"property_name":"fossaHasTargets","value": "'"$HAS_FOSSA_TARGETS"'"]}'
- id: fossa-analyze
name: Run fossa analyze
if: ${{ steps.fossa-list-targets.outputs.HAS_FOSSA_TARGETS == 'True'}}
Expand All @@ -69,10 +72,10 @@ jobs:
then
echo "::error::fossa analyze ran with errors."
cat $ANALYZE_ERR_FILE
echo "FOSSA_ANALYZE_RESULT=Error" >> "$GITHUB_OUTPUT"
echo "FOSSA_ANALYZE_RESULT=Error" >> "$GITHUB_ENV"
else
cat $ANALYZE_OUT_FILE
echo "FOSSA_ANALYZE_RESULT=Success" >> "$GITHUB_OUTPUT"
echo "FOSSA_ANALYZE_RESULT=Success" >> "$GITHUB_ENV"
fi
- name: Set fossaAnalyzeResult custom property
run: |
Expand All @@ -82,7 +85,7 @@ jobs:
-H "Authorization: Bearer $CUSTOM_PROPS_PAT" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$ORG/properties/values \
-d '{"repository_names":["'"${REPO##*/}"'"],"properties":[{"property_name":"fossaAnalyzeResult","value":"'"${{ steps.fossa-analyze.outputs.FOSSA_ANALYZE_RESULT }}"'"}]}'
-d '{"repository_names":["'"${REPO##*/}"'"],"properties":[{"property_name":"fossaAnalyzeResult","value": "'"$FOSSA_ANALYZE_RESULT"'"]}'
- name: Exit
if: ${{ steps.fossa-list-targets.outputs.HAS_FOSSA_TARGETS == 'Error' || steps.fossa-analyze.outputs.FOSSA_ANALYZE_RESULT == 'Error' }}
run: exit 1

0 comments on commit 0d20afe

Please sign in to comment.