Reapply Copyright #3
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Reapply Copyright | |
on: | |
workflow_dispatch: | |
inputs: | |
file_mask: | |
description: 'File mask to reapply license header (argument to find)' | |
required: true | |
default: '-name "*.java" -o -name "*.kt" -o -name "*.kts"' | |
direct-commit: | |
type: boolean | |
default: false | |
description: Commit directly to source (instead of opening a PR) | |
jobs: | |
copyright_checker: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 | |
id: generate-token | |
with: | |
app_id: ${{ secrets.APP_ID }} | |
private_key: ${{ secrets.APP_PRIVATE_KEY }} | |
- name: Checkout repository | |
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 | |
with: | |
token: ${{ steps.generate-token.outputs.token }} | |
- name: Run Copyright Checker | |
shell: bash {0} | |
run: | | |
set +x | |
for file in $(find . -type f \( ${{ inputs.file_mask }} \)); do | |
last_modified_year=$(git log -1 --format=%ad --date=format:%Y "$file") | |
echo "Checking file $file, last modified $last_modified_year" | |
header_exists=$(head -n 2 "$file" | tail -n 1 | grep -c "Budapest University of Technology") | |
echo "Header exists for $file: $header_exists" | |
if [[ $header_exists -eq 0 ]]; then | |
echo "Adding copyright header to $file" | |
cat ./doc/copyright-header.txt "$file" > tmp_026204264 | |
mv tmp_026204264 "$file" | |
fi | |
header_year=$(head -n 2 "$file" | tail -n 1 | grep -o -E '[0-9]{4}') | |
echo "Header year for $file: $header_year" | |
if [[ "$header_year" != "$last_modified_year" ]]; then | |
echo "Updating copyright year to $last_modified_year in $file (was $header_year)" | |
sed -i "s/Copyright [0-9]\{4\}/Copyright $last_modified_year/g" "$file" | |
fi | |
done | |
- name: Create Pull Request | |
if: ${{ !inputs.direct-commit }} | |
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38 | |
with: | |
commit-message: "Reapplied copyright" | |
branch: "copyright-reapply" | |
title: '[AutoPR] Reaplied copyright' | |
token: ${{ steps.generate-token.outputs.token }} | |
committer: ThetaBotMaintainer[bot] <139346997+ThetaBotMaintainer[bot]@users.noreply.github.com> | |
author: ThetaBotMaintainer[bot] <139346997+ThetaBotMaintainer[bot]@users.noreply.github.com> | |
- name: Commit changes | |
if: ${{ inputs.direct-commit }} | |
uses: stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a | |
with: | |
commit_message: "Reapplied copyright" | |
commit_user_name: ThetaBotMaintainer[bot] | |
commit_user_email: 139346997+ThetaBotMaintainer[bot]@users.noreply.github.com | |
commit_author: ThetaBotMaintainer[bot] <139346997+ThetaBotMaintainer[bot]@users.noreply.github.com> |