#header #github-actions #formatter #checker #forms #multiple #distribution

app hawkeye

简单的许可证头检查器和格式化工具,支持多种分发形式

20 个版本 (稳定版)

5.8.0 2024年8月15日
5.7.0 2024年7月3日
5.6.0 2024年6月19日
5.5.1 2024年4月24日
5.4.0 2024年3月31日

#24 in 配置

Download history 262/week @ 2024-04-21 32/week @ 2024-04-28 6/week @ 2024-05-05 13/week @ 2024-05-19 1/week @ 2024-05-26 4/week @ 2024-06-02 1/week @ 2024-06-09 174/week @ 2024-06-16 20/week @ 2024-06-23 133/week @ 2024-06-30 11/week @ 2024-07-07 1/week @ 2024-07-14 22/week @ 2024-07-21 34/week @ 2024-07-28 15/week @ 2024-08-04

每月 73 次下载

Apache-2.0

105KB
2K SLoC

HawkEye

简单的许可证头检查器和格式化工具,支持多种分发形式。

用法

您可以在GitHub Actions或本地机器上使用HawkEye。HawkEye提供了三个基本命令

# check license headers
hawkeye check

# format license headers (auto-fix all files that failed the check)
hawkeye format

# remove license headers
hawkeye remove

您可以使用-h--help列出所有配置选项。

GitHub Actions

HawkEye GitHub Action允许用户通过配置文件使用HawkEye运行许可证头检查。

首先,在项目的根目录中添加一个licenserc.toml文件。适用于Apache License 2.0许可证的项目最简单的配置如下所示

[!NOTE] 完整的配置信息可以在配置部分中找到。

headerPath = "Apache-2.0.txt"

[properties]
inceptionYear = 2023
copyrightOwner = "tison <[email protected]>"

您应根据自己的信息更改版权行。

要检查GitHub Actions中的许可证头,请添加GitHub工作流中的一个步骤

- name: Check License Header
  uses: korandoru/hawkeye@v5

Docker

Alpine镜像 (~18MB)

docker run -it --rm -v $(pwd):/github/workspace ghcr.io/korandoru/hawkeye check

Arch Linux

[!NOTE] 如果遇到打包相关的问题,请联系@orhun维护的软件包或向Arch Linux GitLab报告问题。

hawkeye可以通过pacman安装

pacman -S hawkeye

Cargo安装

可以使用以下方法安装hawkeye可执行文件

cargo install hawkeye

预构建二进制文件

您可以使用以下方法将hawkeye作为预构建二进制文件安装,而不是使用cargo install

export VERSION=v5.3.1
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/korandoru/hawkeye/releases/download/$VERSION/hawkeye-installer.sh | sh

这将保留比使用cargo install更多的构建信息(由hawkeye -V输出)。

构建

此步骤需要Rust工具链。

cargo build --workspace --all-features --bin --tests --examples --benches

构建Docker镜像

docker build . -t hawkeye

配置

配置文件

# Base directory for the whole execution.
# All relative paths is based on this path.
# default: current working directory
baseDir = "."

# Inline header template.
# Either inlineHeader or headerPath should be configured, and inlineHeader is prioritized.
inlineHeader = "..."

# Path to the header template file.
# Either inlineHeader or headerPath should be configured, and inlineHeader is prioritized.
# This path is resolved by the ResourceFinder. Check ResourceFinder for the concrete strategy.
# The header template file is skipped on any execution.
headerPath = "path/to/header.txt"

# On enabled, check the license header matches exactly with whitespace.
# Otherwise, strip the header in one line and check.
# default: true
strictCheck = true

# Whether you use the default excludes. Check Default.EXCLUDES for the completed list.
# To suppress part of excludes in the list, declare exact the same pattern in `includes` list.
# default: true
useDefaultExcludes = true

# The supported patterns of includes and excludes follow gitignore pattern format, plus that:
# 1. `includes` does not support `!`
# 2. backslash does not escape letter
# 3. whitespaces and `#` are normal since we configure line by line
# See also https://git.js.cn/docs/gitignore#_pattern_format

# Patterns of path to be included on execution.
# default: all the files under `baseDir`.
includes = ["..."]

# Patterns of path to be excluded on execution. A leading bang (!) indicates an invert exclude rule.
# default: empty; if useDefaultExcludes is true, append default excludes.
excludes = ["..."]

# Keywords that should occur in the header, case-insensitive.
# default: ["copyright"]
keywords = ["copyright", "..."]

# Whether you use the default mapping. Check DocumentType.defaultMapping() for the completed list.
# default: true
useDefaultMapping = true

# Paths to additional header style files. The model of user-defined header style can be found below.
# default: empty
additionalHeaders = ["..."]

# Mapping rules (repeated).
#
# The key of a mapping rule is a header style type (case-insensitive).
#
# Available header style types consist of those defined at `HeaderType` and user-defined ones in `additionalHeaders`.
# The name of header style type is case-insensitive.
#
# If useDefaultMapping is true, the mapping rules defined here can override the default one.
[mapping.STYLE_NAME]
filenames = ["..."]  # e.g. "Dockerfile.native"
extensions = ["..."] # e.g. "cc"

# Properties to fulfill the template.
# For a defined key-value pair, you can use ${key} in the header template, which will be substituted
# with the corresponding value.
#
# Preset properties:
# * 'hawkeye.core.filename' is the current file name, like: pom.xml.
[properties]
inceptionYear = 2023

# Options to configure Git features.
[git]
# If enabled, do not process files that are ignored by Git; possible value: ['auto', 'enable', 'disable']
# 'auto' means this feature tries to be enabled with:
#   * gix - if `basedir` is in a Git repository.
#   * ignore crate's gitignore rules - if `basedir` is not in a Git repository.
# 'enable' means always enabled with gix; failed if it is impossible.
# default: 'auto'
ignore = 'auto'
# If enabled, populate file attrs determinated by Git; possible value: ['auto', 'enable', 'disable']
# Attributes contains:
#   * 'hawkeye.git.fileCreatedYear'
#   * 'hawkeye.git.fileModifiedYear'
# 'auto' means this feature tries to be enabled with:
#   * gix - if `basedir` is in a Git repository.
# 'enable' means always enabled with gix; failed if it is impossible.
# default: 'disable'
attrs = 'disable'

头样式文件

# [REQUIRED] The name of this header.
[my_header_style]

# The first fixed line of this header. Default to none.
firstLine = "..."

# The last fixed line of this header. Default to none.
endLine = "..."

# The characters to prepend before each license header lines. Default to empty.
beforeEachLine = "..."

# The characters to append after each license header lines. Default to empty.
afterEachLine = "..."

# Only for multi-line comments: specify if blank lines are allowed.
# Default to false because most of the time, a header has some characters on each line.
allowBlankLines = false

# Specify whether this is a multi-line comment style or not.
#
# A multi-line comment style is equivalent to what we have in Java, where a first line and line will delimit
# a whole multi-line comment section.
#
# A style that is not multi-line is usually repeating in each line the characters before and after each line
# to delimit a one-line comment.
#
# Defaulut to true.
multipleLines = true

# Only for non multi-line comments: specify if some spaces should be added after the header line and before
# the `afterEachLine` characters so that all the lines are aligned.
#
# Default to false.
padLines = false

# A regex to define a first line in a file that should be skipped and kept untouched, like the XML declaration
# at the top of XML documents.
#
# Default to none.
skipLinePattern = "..."

# [REQUIRED] The regex used to detect the start of a header section or line.
firstLineDetectionPattern = "..."

# [REQUIRED] The regex used to detect the end of a header section or line.
lastLineDetectionPattern = "..."

许可证

Apache License 2.0

历史

本软件最初来自 license-maven-plugin,最初的动机是将它扩展到Maven插件之外。核心抽象如 DocumentHeaderHeaderParser 是根据Apache License 2.0条款从license-maven-plugin源代码中复制的。

后来,当我开始关注Docker镜像的大小并集成Git时,我发现Rust(GraalVM Native Image)在这方面比Java更合适。因此,我用Rust重写了核心逻辑,并保持镜像精简。

依赖项

~30–42MB
~810K SLoC