Skip to content

Commit 26a9658

Browse files
Merge pull request #16 from getsentry/hubertdeng123/parse-logs-fossa
Parse logs for FOSSA action to determine actual license scan failures
2 parents 8e3c899 + 3b732d7 commit 26a9658

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

β€Žaction.yml

+41-31
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ runs:
99
shell: bash
1010
run: echo "This action should only run on getsentry repos" && exit 1
1111

12-
- name: 'Pick a FOSSA API key'
12+
- name: 'Pick a FOSSA API key and install FOSSA cli'
1313
id: set_key
1414
shell: bash
1515
env:
@@ -27,50 +27,60 @@ runs:
2727
# here in this file and gives us at least basic pass/fail.
2828
#
2929
# See also: https://docs.fossa.com/docs/api-reference#api-tokens
30-
3130
FALLBACK="9fc50c40b136c68873ad05aec573cf3e"
3231
echo "key=${PREFERRED:-$FALLBACK}" >> "$GITHUB_OUTPUT"
32+
# Install specific version of fossa-cli to guarantee stability of parsing fossa job outputs
33+
curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/v3.7.5/install-latest.sh | bash
3334
3435
- name: 'Checkout Code'
3536
uses: actions/checkout@v2
3637

37-
- name: 'Run FOSSA Scan'
38+
- name: 'Run `fossa analyze`'
3839
id: analyze
3940
continue-on-error: true
40-
uses: fossas/fossa-action@5913e730490ebf75ae47b59687b7e590289eed92
41-
with:
42-
api-key: ${{ steps.set_key.outputs.key }}
43-
44-
- if: steps.analyze.outcome == 'failure'
45-
name: 'Send error to Sentry on FOSSA scan failure'
46-
shell: bash
4741
env:
48-
SENTRY_URL: https://self-hosted.getsentry.net/
49-
SENTRY_ORG: self-hosted
50-
SENTRY_PROJECT: test
51-
SENTRY_DSN: https://[email protected]/4
42+
FOSSA_API_KEY: ${{ steps.set_key.outputs.key }}
43+
shell: bash
5244
run: |
53-
curl -sL https://sentry.io/get-cli/ | sh
54-
# Environment variables will automatically be sent, so we just want some minimal information
55-
sentry-cli send-event -m "FOSSA scan failure in $GITHUB_REPOSITORY" -e url:$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID
45+
exec &> >(tee -a "analyze_logs.txt")
46+
fossa analyze
5647
57-
# We only want to run license compliance test if FOSSA scan succeeds. This is to unblock CI
48+
# We only want to run license compliance test if `fossa test` succeeds. This is to unblock CI
5849
# on FOSSA outages.
5950
- if: steps.analyze.outcome == 'success'
60-
name: 'Run FOSSA Test'
51+
name: 'Run `fossa test`'
6152
id: test
62-
uses: fossas/fossa-action@5913e730490ebf75ae47b59687b7e590289eed92
63-
with:
64-
api-key: ${{ steps.set_key.outputs.key }}
65-
run-tests: true
53+
continue-on-error: true
54+
env:
55+
FOSSA_API_KEY: ${{ steps.set_key.outputs.key }}
56+
shell: bash
57+
run: |
58+
exec &> >(tee -a "test_logs.txt")
59+
# Set timeout to 5 minutes (default of 60 minutes is waaaay too long to block CI)
60+
fossa test --timeout 300
6661
67-
- if: github.repository_owner == 'getsentry' && failure()
68-
name: 'Handle errors'
62+
- if: steps.analyze.outcome == 'failure' || steps.test.outcome == 'failure'
63+
name: 'Send error to Sentry on `fossa-cli` errors'
6964
shell: bash
65+
env:
66+
SENTRY_DSN: https://[email protected]/4505031352713216
7067
run: |
71-
echo
72-
echo "πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ "
73-
echo
74-
echo "Eep! It seems that this PR introduces a license violation. Did you add any libraries? Do they use the GPL or some weird license? Am I a confused bot? If you need a hand, cc: @getsentry/open-source in a comment. πŸ™"
75-
echo
76-
echo "πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ "
68+
if [[ ${{ steps.analyze.outcome }} == 'failure' ]]; then
69+
curl -sL https://sentry.io/get-cli/ | sh
70+
# Environment variables will automatically be sent, so we just want some minimal information
71+
error_msg=$(cat analyze_logs.txt | grep -zoP '(?<=>>> Relevant errors\n\n Error\n\n ).*?(?=\n)' || echo 'unknown error message')
72+
sentry-cli send-event -m "analyze: $error_msg" -t repo:$GITHUB_REPOSITORY -e url:$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID --logfile analyze_logs.txt
73+
exit 0
74+
fi
75+
if grep -q "The scan has revealed issues. Number of issues found:" test_logs.txt; then
76+
echo
77+
echo "πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ "
78+
echo
79+
echo "Eep! It seems that this PR introduces a license violation. Did you add any libraries? Do they use the GPL or some weird license? Am I a confused bot? If you need a hand, cc: @getsentry/open-source in a comment. πŸ™"
80+
echo
81+
echo "πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ πŸ›‘ "
82+
exit 1
83+
fi
84+
curl -sL https://sentry.io/get-cli/ | sh
85+
error_msg=$(cat test_logs.txt | grep -zoP '(?<=>>> Relevant errors\n\n Error\n\n ).*?(?=\n)' || echo 'unknown error message')
86+
sentry-cli send-event -m "test: $error_msg" -t repo:$GITHUB_REPOSITORY -e url:$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID --logfile test_logs.txt

0 commit comments

Comments
Β (0)