dlc.yml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. name: Dependency License Checks
  2. on:
  3. pull_request:
  4. paths:
  5. - "go.mod"
  6. workflow_dispatch: {}
  7. permissions:
  8. contents: read
  9. env:
  10. HAS_FOSSA_KEY: ${{ secrets.FOSSA_API_KEY != '' }}
  11. jobs:
  12. fossa-scan:
  13. runs-on: ubuntu-latest
  14. steps:
  15. - uses: step-security/harden-runner@f808768d1510423e83855289c910610ca9b43176 # v2.17.0
  16. if: ${{ env.HAS_FOSSA_KEY == 'true' }}
  17. with:
  18. egress-policy: audit
  19. - name: "Checkout Code"
  20. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  21. if: ${{ env.HAS_FOSSA_KEY == 'true' }}
  22. with:
  23. persist-credentials: false
  24. - name: "Install FOSSA CLI"
  25. if: ${{ env.HAS_FOSSA_KEY == 'true' }}
  26. run: |
  27. curl -H 'Cache-Control: no-cache' https://raw.githubusercontent.com/fossas/fossa-cli/master/install-latest.sh | bash -s -- -b "$RUNNER_TEMP/bin" v3.17.1
  28. echo "$RUNNER_TEMP/bin" >> "$GITHUB_PATH"
  29. "$RUNNER_TEMP/bin/fossa" --version
  30. - name: "Run FOSSA Scan"
  31. id: fossa_scan
  32. if: ${{ env.HAS_FOSSA_KEY == 'true' }}
  33. continue-on-error: true
  34. env:
  35. FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }}
  36. FOSSA_BRANCH: ${{ github.head_ref || github.ref_name }}
  37. FOSSA_REVISION: ${{ github.event.pull_request.head.sha || github.sha }}
  38. run: |
  39. fossa analyze --debug --branch "$FOSSA_BRANCH" --revision "$FOSSA_REVISION" >"$RUNNER_TEMP/fossa-analyze.stdout" 2>"$RUNNER_TEMP/fossa-analyze.stderr"
  40. - name: "Report FOSSA Scan Failure"
  41. if: ${{ env.HAS_FOSSA_KEY == 'true' && steps.fossa_scan.outcome == 'failure' }}
  42. run: |
  43. if [ -f /tmp/fossa-analyze-scan-summary.txt ]; then
  44. echo "FOSSA analyze summary:"
  45. cat /tmp/fossa-analyze-scan-summary.txt
  46. summary=$(tail -n 20 /tmp/fossa-analyze-scan-summary.txt | tr '\n' ' ' | sed 's/%/%25/g; s/\r/%0D/g')
  47. echo "::error::${summary}"
  48. elif [ -f "$RUNNER_TEMP/fossa-analyze.stderr" ]; then
  49. echo "FOSSA analyze stderr:"
  50. cat "$RUNNER_TEMP/fossa-analyze.stderr"
  51. if grep -q "Invalid project permission" "$RUNNER_TEMP/fossa-analyze.stderr"; then
  52. echo "::warning::FOSSA scan skipped because the configured API key does not have project edit permission in the FOSSA organization."
  53. exit 0
  54. fi
  55. summary=$(tail -n 20 "$RUNNER_TEMP/fossa-analyze.stderr" | tr '\n' ' ' | sed 's/%/%25/g; s/\r/%0D/g')
  56. echo "::error::${summary}"
  57. else
  58. echo "::error::FOSSA scan failed before writing /tmp/fossa-analyze-scan-summary.txt"
  59. fi
  60. exit 1
  61. - name: "Run FOSSA Test"
  62. id: fossa_test
  63. if: ${{ env.HAS_FOSSA_KEY == 'true' && steps.fossa_scan.outcome == 'success' }}
  64. continue-on-error: true
  65. env:
  66. FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }}
  67. FOSSA_REVISION: ${{ github.event.pull_request.head.sha || github.sha }}
  68. run: |
  69. fossa test --debug --revision "$FOSSA_REVISION" >"$RUNNER_TEMP/fossa-test.stdout" 2>"$RUNNER_TEMP/fossa-test.stderr"
  70. - name: "Report FOSSA Test Failure"
  71. if: ${{ env.HAS_FOSSA_KEY == 'true' && steps.fossa_test.outcome == 'failure' }}
  72. run: |
  73. if [ -f "$RUNNER_TEMP/fossa-test.stderr" ]; then
  74. echo "FOSSA test stderr:"
  75. cat "$RUNNER_TEMP/fossa-test.stderr"
  76. summary=$(tail -n 20 "$RUNNER_TEMP/fossa-test.stderr" | tr '\n' ' ' | sed 's/%/%25/g; s/\r/%0D/g')
  77. echo "::error::${summary}"
  78. else
  79. echo "::error::FOSSA test failed. No stderr file was captured."
  80. fi
  81. exit 1