Skip to content

Commit 2d5cee8

Browse files
authored
Merge pull request #6266 from nickanderson/copyright-year-automation
Added a workflow to keep the help output copyright year current
2 parents 5d9789b + 266518c commit 2d5cee8

3 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Copyright year
2+
3+
# Keeps the copyright year in the help output (`--help`) current.
4+
#
5+
# The year is a plain literal in configure.ac, updated by a reviewed pull
6+
# request -- this workflow only opens that pull request, it never pushes to a
7+
# release branch. Scheduled runs act on the default branch; to refresh a
8+
# maintained branch, dispatch this workflow with that branch selected and the
9+
# pull request will target it.
10+
#
11+
# The edit itself lives in ci/update-copyright-year.sh so it can be linted and
12+
# run by hand.
13+
14+
on:
15+
schedule:
16+
# 03:00 UTC on January 2nd, by which point the year has rolled over
17+
# in every timezone.
18+
- cron: '0 3 2 1 *'
19+
workflow_dispatch:
20+
21+
permissions:
22+
contents: write
23+
pull-requests: write
24+
25+
jobs:
26+
bump_copyright_year:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
31+
- name: Update the copyright year
32+
id: bump
33+
run: |
34+
year=$(ci/update-copyright-year.sh)
35+
echo "year=$year" >> "$GITHUB_OUTPUT"
36+
echo "branch=copyright-year-${GITHUB_REF_NAME//\//-}-$year" >> "$GITHUB_OUTPUT"
37+
38+
# sign-commits creates the commit through the GitHub API so it is signed
39+
# by GitHub and shows as verified; it also ignores the committer and
40+
# author inputs, so there is no bot identity to configure here.
41+
#
42+
# If the year was already current there is nothing to commit and the
43+
# action exits without opening anything.
44+
- name: Open a pull request
45+
uses: cfengine/create-pull-request@v7
46+
with:
47+
base: ${{ github.ref_name }}
48+
branch: ${{ steps.bump.outputs.branch }}
49+
delete-branch: true
50+
sign-commits: true
51+
add-paths: configure.ac
52+
commit-message: |
53+
Updated help menu copyright year to ${{ steps.bump.outputs.year }}
54+
55+
Opened automatically by .github/workflows/copyright_year.yml.
56+
57+
Changelog: none
58+
title: Updated help menu copyright year to ${{ steps.bump.outputs.year }}
59+
body: |
60+
The copyright year shown by `--help` is a literal in `configure.ac`; this updates it to ${{ steps.bump.outputs.year }}.
61+
62+
Opened automatically by [.github/workflows/copyright_year.yml](.github/workflows/copyright_year.yml).
63+
64+
Pull requests opened with `GITHUB_TOKEN` do not trigger other workflows, so CI has not started on its own -- comment `@cf-bottom jenkins, please` to run it.

.github/workflows/shellcheck.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ jobs:
2020
- name: Run shellcheck
2121
# todo: add more places to run shellcheck besides misc/cf-support
2222
run: make -C misc check
23+
- name: Run shellcheck on ci scripts
24+
run: shellcheck ci/update-copyright-year.sh

ci/update-copyright-year.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Set the copyright year shown in the help output (`--help`).
4+
#
5+
# The year is a plain literal in configure.ac. This script rewrites that literal
6+
# and nothing else -- committing it and opening a pull request is left to the
7+
# caller, see .github/workflows/copyright_year.yml.
8+
#
9+
# The year it settled on is printed on stdout, everything else goes to stderr:
10+
#
11+
# year=$(ci/update-copyright-year.sh) # the current year
12+
# year=$(ci/update-copyright-year.sh 2027) # a specific year
13+
14+
set -eu
15+
16+
year=${1:-$(date -u +%Y)}
17+
18+
case "$year" in
19+
[0-9][0-9][0-9][0-9]) ;;
20+
*)
21+
echo "$0: '$year' is not a four digit year" >&2
22+
exit 1
23+
;;
24+
esac
25+
26+
cd "$(dirname "$0")/.."
27+
28+
current=$(sed -nE 's/^AC_DEFINE\(CF_COPYRIGHT, "([0-9]{4}) Northern\.tech AS".*/\1/p' configure.ac)
29+
30+
# Fail loudly rather than silently doing nothing if the define is ever renamed
31+
# or reformatted -- a silent no-op here is exactly how the year went three
32+
# releases without being updated.
33+
if [ -z "$current" ]; then
34+
echo "$0: no CF_COPYRIGHT define in the expected form in configure.ac, update this script" >&2
35+
exit 1
36+
fi
37+
38+
if [ "$current" = "$year" ]; then
39+
echo "configure.ac: copyright year is already $year" >&2
40+
else
41+
sed -i -E \
42+
"s/^(AC_DEFINE\(CF_COPYRIGHT, \")[0-9]{4}( Northern\.tech AS\")/\1$year\2/" \
43+
configure.ac
44+
echo "configure.ac: copyright year $current -> $year" >&2
45+
fi
46+
47+
echo "$year"

0 commit comments

Comments
 (0)