RFR: 7449: Add GitHub action to verify copyright year [v3]

Marcus Hirt hirt at openjdk.java.net
Sat Jan 22 14:37:03 UTC 2022


On Sat, 11 Dec 2021 20:20:44 GMT, Alex Ciminian <duke at openjdk.java.net> wrote:

>> This PR adds a script to check copyright notices on changed files. I've not added a GitHub action yet, I'd like to get some feedback before doing that �� 
>> 
>> The script is written in Kotlin and uses [JGit](https://www.eclipse.org/jgit/) to interface with the git repository. To run, it only needs the kotlin compiler which is [preinstalled on GitHub Actions runners](https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md).
>> 
>> It works as follows:
>> 
>> * diff the HEAD commit and the merge base between it and master (i.e. where the feature branch diverged from)
>> * for every changed file (except deletions), validate the copyright header
>>   - if the file is new, it should have Oracle and Datadog copyright starting from the year of the HEAD commit
>>   - if the file is not new, it should keep the existing copyright holders and update the year range if necessary
>> * we compare file contents from objects in the git repo, not the files themselves
>> * currently we don't validate we're in the correct directory or the commits
>> 
>> The output looks like this:
>> 
>> 
>> kotlinc -script scripts/copyrightchecker.main.kts                                                                                                                                                     
>> Checked out at: 759788185939b16f447e553b3ee64121187ea311 (base: 8b8aa7c299b92b655ba669a92d16f193beb406bc)
>> ⚪️ scripts/copyrightchecker.main.kts
>> ✅ Validation succeeded
>> 
>> 
>> 
>> kotlinc -script scripts/copyrightchecker.main.kts                                                                                                                                                       
>> Checked out at: 7ad43eed12c9eb85a96882c9518a9acbe12e74c5 (base: ca204424ce32336f2923aff66f619d571b1fc720)
>> ⚪️ .gitignore
>> �� application/org.openjdk.jmc.feature.flightrecorder/feature.xml
>> �� Failed to parse:    Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved.
>> ⚪️ application/org.openjdk.jmc.flightrecorder.heatmap/.classpath
>> ⚪️ application/org.openjdk.jmc.flightrecorder.heatmap/.gitignore
>> ⚪️ application/org.openjdk.jmc.flightrecorder.heatmap/META-INF/MANIFEST.MF
>> ⚪️ application/org.openjdk.jmc.flightrecorder.heatmap/build.properties
>> ⚪️ application/org.openjdk.jmc.flightrecorder.heatmap/icons/heatmap.png
>> ⚪️ application/org.openjdk.jmc.flightrecorder.heatmap/icons/heatmap at 2x.png
>> ⚪️ application/org.openjdk.jmc.flightrecorder.heatmap/plugin.properties
>> ⚪️ application/org.openjdk.jmc.flightrecorder.heatmap/plugin.xml
>> �� application/org.openjdk.jmc.flightrecorder.heatmap/pom.xml
>> Expected:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!--
>> 	Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
>> 	Copyright (c) 2021, Datadog, Inc. All rights reserved.
>> 
>> 	DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>> Actual:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!--
>>    Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
>>    Copyright (c) 2021, Datadog, Inc. All rights reserved.
>> 
>>    DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HE
>> (check whitespace if strings seem to match)
>> �� application/org.openjdk.jmc.flightrecorder.heatmap/src/main/java/org/openjdk/jmc/flightrecorder/heatmap/views/HeatmapView.java
>> �� application/org.openjdk.jmc.flightrecorder.heatmap/src/main/resources/heatmap.js
>> ⚪️ application/org.openjdk.jmc.flightrecorder.heatmap/src/main/resources/page.template
>> �� application/pom.xml
>> Expected:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!--
>> 	Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
>> 
>> 	DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>> Actual:
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!--
>>    Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
>> 
>>    DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEAD
>> (check whitespace if strings seem to match)
>> 
>> ❌ Validation failed
>
> Alex Ciminian has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Run copyright checker during validate workflow on linux

Let's stick with Java in the OpenJDK JMC project though...

-------------

PR: https://git.openjdk.java.net/jmc/pull/342


More information about the jmc-dev mailing list