|
| 1 | +name: Check License |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - main |
| 10 | + |
| 11 | +jobs: |
| 12 | + license-check: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Check out code |
| 16 | + uses: actions/checkout@v3 |
| 17 | + |
| 18 | + - name: Find license file |
| 19 | + id: find_license |
| 20 | + run: | |
| 21 | + if [[ -f "LICENSE" ]]; then |
| 22 | + echo "filename=LICENSE" >> $GITHUB_OUTPUT |
| 23 | + elif [[ -f "LICENSE.md" ]]; then |
| 24 | + echo "filename=LICENSE.md" >> $GITHUB_OUTPUT |
| 25 | + elif [[ -f "LICENSE.txt" ]]; then |
| 26 | + echo "filename=LICENSE.txt" >> $GITHUB_OUTPUT |
| 27 | + elif [[ -f "COPYING" ]]; then |
| 28 | + echo "filename=COPYING" >> $GITHUB_OUTPUT |
| 29 | + else |
| 30 | + echo "::error::No license file found. Checked for LICENSE, LICENSE.md, LICENSE.txt, COPYING." |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | +
|
| 34 | + # The reusable workflow is in a different repository, so we check it out. |
| 35 | + # Assuming 'billnapier/licenseclassifier' is the repository on GitHub. |
| 36 | + - name: Check out licenseclassifier repository |
| 37 | + uses: actions/checkout@v3 |
| 38 | + with: |
| 39 | + repository: billnapier/licenseclassifier |
| 40 | + path: ./.licenseclassifier |
| 41 | + |
| 42 | + - name: Run license classifier |
| 43 | + id: classify |
| 44 | + uses: ./.licenseclassifier/.github/workflows/classify.yml |
| 45 | + with: |
| 46 | + file_to_classify: ${{ steps.find_license.outputs.filename }} |
| 47 | + |
| 48 | + - name: Verify license |
| 49 | + run: | |
| 50 | + license_name="${{ steps.classify.outputs.license_name }}" |
| 51 | + echo "Detected license: $license_name" |
| 52 | + # The prompt mentioned "Apahche", which is likely a typo for "Apache". |
| 53 | + if [[ "$license_name" == "Apache" || "$license_name" == "MIT" || "$license_name" == "BSD" ]]; then |
| 54 | + echo "License is compliant." |
| 55 | + else |
| 56 | + echo "::error::License '$license_name' is not one of the allowed licenses (Apache, MIT, BSD)." |
| 57 | + exit 1 |
| 58 | + fi |
0 commit comments