Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .github/workflows/licensecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
name: LicenseCheck

on:
push:
# 'branches-ignore' or 'branches' can be used to filter specific branches.
# By default, without any filters, it runs on every push to all branches.
# To be explicit, you can use:
branches-ignore:
- 'develop'
- 'master'
- 'rebased/*'

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Get push type
id: push-type
run: |
echo "Getting push type"
PUSH_TYPE='commit'
FETCH_DEPTH=10
if ${{ github.event.forced }} || ${{ github.event.before == '0000000000000000000000000000000000000000' }}; then
PUSH_TYPE='branch'
FETCH_DEPTH=0
fi
echo "Push type: $PUSH_TYPE"
echo "Fetch depth: $FETCH_DEPTH"
echo "push_type=$PUSH_TYPE" >> $GITHUB_OUTPUT
echo "fetch_depth=$FETCH_DEPTH" >> $GITHUB_OUTPUT

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: ${{ steps.push-type.outputs.fetch_depth }}

- name: Get changed files
id: changed-files
run: |
if ${{ steps.push-type.outputs.push_type == 'branch'}}; then
echo "First commit on feature branch or force push - getting all changed files compared to 'develop'"
CHANGED_FILES=$(git diff --name-only remotes/origin/develop ${{ github.event.after }} | xargs)
else
echo "Getting changed files from ${{ github.event.before }} to ${{ github.event.after }}"
CHANGED_FILES=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)
fi
for file in $CHANGED_FILES; do
echo "'$file' was changed"
done
echo "changed_files=$CHANGED_FILES" >> $GITHUB_OUTPUT

- name: Process changed files
id: process-files
run: |
LICENSE_LINES=''
for file in ${{ steps.changed-files.outputs.changed_files }}; do
echo "Processing '$file'..."
LICENSE_MATCH=$(cat $file | grep -Pzo '(<|")licensee("| )(\n|.)*(}|</licensee>)' | xargs)
if [ -z "$LICENSE_MATCH" ]; then
echo "...no licenses found"
else
echo "license found!"
LICENSE_LINE="<$file>
$LICENSE_MATCH
"
LICENSE_LINES="$LICENSE_LINES
$LICENSE_LINE"
fi
done
{
echo 'license_lines<<EOF'
echo "${LICENSE_LINES}"
echo EOF
} >> $GITHUB_OUTPUT

- name: Remove commit/branch if licenses found
if: ${{ steps.process-files.outputs.license_lines != '' }}
id: remove-license
run: |
if ${{ steps.push-type.outputs.push_type == 'commit'}}; then
BAD_COMMIT="${{ github.event.after }}"
echo "Removing commit $BAD_COMMIT as it contains licenses"
git reset --hard $BAD_COMMIT
git push origin ${{ github.ref }} --force-with-lease
echo "link=https://github.com/${{ github.repository }}/commits/${{ github.ref }}" >> $GITHUB_OUTPUT
echo "shortMsg=$BAD_COMMIT was removed!" >> $GITHUB_OUTPUT
echo "msg=Commit with message '${{ toJSON(github.event.head_commit.message) }}' `$BAD_COMMIT` was removed!" >> $GITHUB_OUTPUT
else
BAD_BRANCH="${{ github.ref }}"
echo "Removing branch $BAD_BRANCH as it contains licenses"
git push origin --delete $BAD_BRANCH
echo "link=https://github.com/${{ github.repository }}/branches" >> $GITHUB_OUTPUT
echo "shortMsg=$BAD_BRANCH was removed!" >> $GITHUB_OUTPUT
echo "msg=Branch '$BAD_BRANCH' was removed!" >> $GITHUB_OUTPUT
fi

- name: Find correspondences
if: ${{ steps.process-files.outputs.license_lines != '' }}
id: email
uses: slackapi/[email protected]
with:
method: users.lookupByEmail # https://api.slack.com/methods/users.lookupByEmail
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
email: [email protected]

- name: Search email detail
if: ${{ steps.email.outputs.ok }}
run: |
SLACK_USER_ID=$(echo '${{ steps.email.outputs.response }}' | jq -r '.user.id')
echo "SLACK_USER_ID=$SLACK_USER_ID" >> $GITHUB_ENV

- name: Send a direct message
if: ${{ steps.email.outputs.ok }}
uses: slackapi/[email protected]
with:
errors: true
method: chat.postMessage # https://api.slack.com/methods/chat.postMessage
token: ${{ secrets.SLACK_BOT_TOKEN }}
payload: |
"channel": "${{ env.SLACK_USER_ID }}",
"text": "${{ steps.remove-license.outputs.shortMsg }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":alert: ${{ steps.remove-license.outputs.msg }} :alert:"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "<${{ steps.remove-license.outputs.link }}>"
}
}
]
11 changes: 11 additions & 0 deletions all-products.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<license issuer="iText Group NV" library="3">
<licensee expire="2100-12-31">
<name>iText Development</name>
<email>[email protected]</email>
<company>iText Software Group</company>
<version>7.1</version>
<key>TEST-LICE-NSE0</key>
<comment>Test License</comment>
</licensee>
</license>