feat: add contributor author #14

Open
Jvlegod wants to merge 2 commits from Jvlegod/go2spec:feat/spdx-file-contributor-author into master
Contributor

本次更改是添加了提交签名的选项

  • 新增环境变量 GO2SPEC_AUTHOR 配置签名, 内容为 姓名 <邮箱>
  • 也可以通过 -author 选项覆盖环境变量的签名
  • 不设置 -authorGO2SPEC_AUTHOR 为空则不添加签名

手动演示如下.

假设已经构建完了工程, 并安装.

go build -o /tmp/go2spec .

以 github.com/xeipuuv/gojsonschema 为例.

pack, 不设置 author, 不生成 contributor

tmp=$(mktemp -d /tmp/go2spec-pack-no-author.XXXXXX)
cd "$tmp"
env -u GO2SPEC_AUTHOR /tmp/go2spec pack github.com/xeipuuv/gojsonschema
spec=$(find "$tmp" -name '*.spec' -print -quit)
echo "$spec"
rg -n '^# SPDX-FileContributor:' "$spec" || echo "no contributor"
no contributor

pack, 使用 GO2SPEC_AUTHOR

tmp=$(mktemp -d /tmp/go2spec-pack-env.XXXXXX)
cd "$tmp"
GO2SPEC_AUTHOR="Env Author <env-author@example.invalid>" \
  /tmp/go2spec pack github.com/xeipuuv/gojsonschema
spec=$(find "$tmp" -name '*.spec' -print -quit)
rg -n '^# SPDX-FileContributor:' "$spec"
3:# SPDX-FileContributor: Env Author <env-author@example.invalid>

pack, -author 优先于环境变量

tmp=$(mktemp -d /tmp/go2spec-pack-cli.XXXXXX)
cd "$tmp"
GO2SPEC_AUTHOR="Env Author <env-author@example.invalid>" \
  /tmp/go2spec pack \
  -author "CLI Author <cli-author@example.invalid>" \
  github.com/xeipuuv/gojsonschema
spec=$(find "$tmp" -name '*.spec' -print -quit)
rg -n '^# SPDX-FileContributor:' "$spec"
3:# SPDX-FileContributor: CLI Author <cli-author@example.invalid>

pack, author 格式错误会报错

tmp=$(mktemp -d /tmp/go2spec-pack-bad.XXXXXX)
cd "$tmp"
/tmp/go2spec pack \
  -author "Bad Author" \
  github.com/xeipuuv/gojsonschema
2026/07/19 15:37:21 resolve author: author must use Name <email> format

update, 不设置 author, 正常更新但不补 contributor

tmp=$(mktemp -d /tmp/go2spec-update-no-author.XXXXXX)
cd "$tmp"
GO2SPEC_AUTHOR="Seed Author <seed-author@example.invalid>" \
  /tmp/go2spec pack github.com/xeipuuv/gojsonschema
spec=$(find "$tmp" -name '*.spec' -print -quit)
perl -0pi -e 's/^(Version:\s*)\S+/${1}0.0.1/m; s/^# SPDX-FileContributor: .*\n//m' "$spec"
env -u GO2SPEC_AUTHOR /tmp/go2spec update "$tmp"
rg -n '^Version:\s*1\.2\.0' "$spec"
rg -n '^# SPDX-FileContributor:' "$spec" || echo "no contributor"
10:Version:        1.2.0
no contributor

update, 使用 GO2SPEC_AUTHOR 追加 contributor

tmp=$(mktemp -d /tmp/go2spec-update-env.XXXXXX)
cd "$tmp"
env -u GO2SPEC_AUTHOR /tmp/go2spec pack github.com/xeipuuv/gojsonschema
spec=$(find "$tmp" -name '*.spec' -print -quit)
perl -0pi -e 's/^(Version:\s*)\S+/${1}0.0.1/m' "$spec"
GO2SPEC_AUTHOR="Update Author <update-author@example.invalid>" \
  /tmp/go2spec update "$tmp"
rg -n '^# SPDX-FileContributor:' "$spec"
4:# SPDX-FileContributor: Update Author <update-author@example.invalid>

update, 同 author 不重复

tmp=$(mktemp -d /tmp/go2spec-update-same.XXXXXX)
cd "$tmp"
GO2SPEC_AUTHOR="Same Author <same-author@example.invalid>" \
  /tmp/go2spec pack github.com/xeipuuv/gojsonschema
spec=$(find "$tmp" -name '*.spec' -print -quit)
perl -0pi -e 's/^(Version:\s*)\S+/${1}0.0.1/m' "$spec"
GO2SPEC_AUTHOR="Same Author <same-author@example.invalid>" \
  /tmp/go2spec update "$tmp"
rg -n '^# SPDX-FileContributor:' "$spec"
3:# SPDX-FileContributor: Same Author <same-author@example.invalid>

update, 不同 author 追加新署名

tmp=$(mktemp -d /tmp/go2spec-update-second.XXXXXX)
cd "$tmp"
GO2SPEC_AUTHOR="First Author <first-author@example.invalid>" \
  /tmp/go2spec pack github.com/xeipuuv/gojsonschema
spec=$(find "$tmp" -name '*.spec' -print -quit)
perl -0pi -e 's/^(Version:\s*)\S+/${1}0.0.1/m' "$spec"
GO2SPEC_AUTHOR="Second Author <second-author@example.invalid>" \
  /tmp/go2spec update "$tmp"
rg -n '^# SPDX-FileContributor:' "$spec"
3:# SPDX-FileContributor: First Author <first-author@example.invalid>
4:# SPDX-FileContributor: Second Author <second-author@example.invalid>

update, -author 优先于环境变量

tmp=$(mktemp -d /tmp/go2spec-update-cli.XXXXXX)
cd "$tmp"
env -u GO2SPEC_AUTHOR /tmp/go2spec pack github.com/xeipuuv/gojsonschema
spec=$(find "$tmp" -name '*.spec' -print -quit)
perl -0pi -e 's/^(Version:\s*)\S+/${1}0.0.1/m' "$spec"
GO2SPEC_AUTHOR="Env Author <env-author@example.invalid>" \
  /tmp/go2spec update \
  -author "CLI Author <cli-author@example.invalid>" \
  "$tmp"
rg -n '^# SPDX-FileContributor:' "$spec"
4:# SPDX-FileContributor: CLI Author <cli-author@example.invalid>
本次更改是添加了提交签名的选项 - 新增环境变量 `GO2SPEC_AUTHOR` 配置签名, 内容为 `姓名 <邮箱>` - 也可以通过 `-author` 选项覆盖环境变量的签名 - 不设置 `-author` 和 `GO2SPEC_AUTHOR` 为空则不添加签名 手动演示如下. 假设已经构建完了工程, 并安装. ```bash go build -o /tmp/go2spec . ``` 以 github.com/xeipuuv/gojsonschema 为例. ## pack, 不设置 author, 不生成 contributor ```bash tmp=$(mktemp -d /tmp/go2spec-pack-no-author.XXXXXX) cd "$tmp" env -u GO2SPEC_AUTHOR /tmp/go2spec pack github.com/xeipuuv/gojsonschema spec=$(find "$tmp" -name '*.spec' -print -quit) echo "$spec" rg -n '^# SPDX-FileContributor:' "$spec" || echo "no contributor" ``` ```bash no contributor ``` ## pack, 使用 GO2SPEC_AUTHOR ```bash tmp=$(mktemp -d /tmp/go2spec-pack-env.XXXXXX) cd "$tmp" GO2SPEC_AUTHOR="Env Author <env-author@example.invalid>" \ /tmp/go2spec pack github.com/xeipuuv/gojsonschema spec=$(find "$tmp" -name '*.spec' -print -quit) rg -n '^# SPDX-FileContributor:' "$spec" ``` ```bash 3:# SPDX-FileContributor: Env Author <env-author@example.invalid> ``` ## pack, -author 优先于环境变量 ```bash tmp=$(mktemp -d /tmp/go2spec-pack-cli.XXXXXX) cd "$tmp" GO2SPEC_AUTHOR="Env Author <env-author@example.invalid>" \ /tmp/go2spec pack \ -author "CLI Author <cli-author@example.invalid>" \ github.com/xeipuuv/gojsonschema spec=$(find "$tmp" -name '*.spec' -print -quit) rg -n '^# SPDX-FileContributor:' "$spec" ``` ```bash 3:# SPDX-FileContributor: CLI Author <cli-author@example.invalid> ``` ## pack, author 格式错误会报错 ```bash tmp=$(mktemp -d /tmp/go2spec-pack-bad.XXXXXX) cd "$tmp" /tmp/go2spec pack \ -author "Bad Author" \ github.com/xeipuuv/gojsonschema ``` ```bash 2026/07/19 15:37:21 resolve author: author must use Name <email> format ``` ## update, 不设置 author, 正常更新但不补 contributor ```bash tmp=$(mktemp -d /tmp/go2spec-update-no-author.XXXXXX) cd "$tmp" GO2SPEC_AUTHOR="Seed Author <seed-author@example.invalid>" \ /tmp/go2spec pack github.com/xeipuuv/gojsonschema spec=$(find "$tmp" -name '*.spec' -print -quit) perl -0pi -e 's/^(Version:\s*)\S+/${1}0.0.1/m; s/^# SPDX-FileContributor: .*\n//m' "$spec" env -u GO2SPEC_AUTHOR /tmp/go2spec update "$tmp" rg -n '^Version:\s*1\.2\.0' "$spec" rg -n '^# SPDX-FileContributor:' "$spec" || echo "no contributor" ``` ```bash 10:Version: 1.2.0 no contributor ``` ## update, 使用 GO2SPEC_AUTHOR 追加 contributor ```bash tmp=$(mktemp -d /tmp/go2spec-update-env.XXXXXX) cd "$tmp" env -u GO2SPEC_AUTHOR /tmp/go2spec pack github.com/xeipuuv/gojsonschema spec=$(find "$tmp" -name '*.spec' -print -quit) perl -0pi -e 's/^(Version:\s*)\S+/${1}0.0.1/m' "$spec" GO2SPEC_AUTHOR="Update Author <update-author@example.invalid>" \ /tmp/go2spec update "$tmp" rg -n '^# SPDX-FileContributor:' "$spec" ``` ```bash 4:# SPDX-FileContributor: Update Author <update-author@example.invalid> ``` ## update, 同 author 不重复 ```bash tmp=$(mktemp -d /tmp/go2spec-update-same.XXXXXX) cd "$tmp" GO2SPEC_AUTHOR="Same Author <same-author@example.invalid>" \ /tmp/go2spec pack github.com/xeipuuv/gojsonschema spec=$(find "$tmp" -name '*.spec' -print -quit) perl -0pi -e 's/^(Version:\s*)\S+/${1}0.0.1/m' "$spec" GO2SPEC_AUTHOR="Same Author <same-author@example.invalid>" \ /tmp/go2spec update "$tmp" rg -n '^# SPDX-FileContributor:' "$spec" ``` ```bash 3:# SPDX-FileContributor: Same Author <same-author@example.invalid> ``` ## update, 不同 author 追加新署名 ```bash tmp=$(mktemp -d /tmp/go2spec-update-second.XXXXXX) cd "$tmp" GO2SPEC_AUTHOR="First Author <first-author@example.invalid>" \ /tmp/go2spec pack github.com/xeipuuv/gojsonschema spec=$(find "$tmp" -name '*.spec' -print -quit) perl -0pi -e 's/^(Version:\s*)\S+/${1}0.0.1/m' "$spec" GO2SPEC_AUTHOR="Second Author <second-author@example.invalid>" \ /tmp/go2spec update "$tmp" rg -n '^# SPDX-FileContributor:' "$spec" ``` ```bash 3:# SPDX-FileContributor: First Author <first-author@example.invalid> 4:# SPDX-FileContributor: Second Author <second-author@example.invalid> ``` ## update, -author 优先于环境变量 ```bash tmp=$(mktemp -d /tmp/go2spec-update-cli.XXXXXX) cd "$tmp" env -u GO2SPEC_AUTHOR /tmp/go2spec pack github.com/xeipuuv/gojsonschema spec=$(find "$tmp" -name '*.spec' -print -quit) perl -0pi -e 's/^(Version:\s*)\S+/${1}0.0.1/m' "$spec" GO2SPEC_AUTHOR="Env Author <env-author@example.invalid>" \ /tmp/go2spec update \ -author "CLI Author <cli-author@example.invalid>" \ "$tmp" rg -n '^# SPDX-FileContributor:' "$spec" ``` ```bash 4:# SPDX-FileContributor: CLI Author <cli-author@example.invalid> ```
Jvlegod added 2 commits 2026-07-19 07:51:58 +00:00
Jvlegod changed title from Feat/spdx file contributor author to feat: add contributor author 2026-07-19 07:52:32 +00:00
Owner

"SPDX-FileContributor" 应该只有人类进行手动更改的情况下才加上,直接使用的话不应该加上这个;如果这样看的话,这也意味着不应该由机器生成?🤔

"SPDX-FileContributor" 应该只有人类进行手动更改的情况下才加上,直接使用的话不应该加上这个;如果这样看的话,这也意味着不应该由机器生成?🤔
Author
Contributor

确实, 如果这么来看, 这个 feature 确实和工具的初衷相违背了

确实, 如果这么来看, 这个 feature 确实和工具的初衷相违背了
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u https://git.openruyi.cn/Jvlegod/go2spec feat/spdx-file-contributor-author:Jvlegod-feat/spdx-file-contributor-author
git checkout Jvlegod-feat/spdx-file-contributor-author
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: misaka00251/go2spec#14