RFR: 7449: Add GitHub action to verify copyright year
Alex Ciminian
duke at openjdk.java.net
Sun Dec 5 19:39:38 UTC 2021
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
-------------
Commit messages:
- Add script to check copyright header on changed files
Changes: https://git.openjdk.java.net/jmc/pull/342/files
Webrev: https://webrevs.openjdk.java.net/?repo=jmc&pr=342&range=00
Issue: https://bugs.openjdk.java.net/browse/JMC-7449
Stats: 285 lines in 1 file changed: 285 ins; 0 del; 0 mod
Patch: https://git.openjdk.java.net/jmc/pull/342.diff
Fetch: git fetch https://git.openjdk.java.net/jmc pull/342/head:pull/342
PR: https://git.openjdk.java.net/jmc/pull/342
More information about the jmc-dev
mailing list