Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update licensegen to output the current year for new files #5852

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,30 @@ jobs:
run: |
make lint-api

lint-copyright:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
check-latest: true

- name: Check new go files for license
run: |
git fetch origin main
make copyright-check

linters-succeed:
name: All Linters Succeed
needs:
- lint-api
- lint-protos
- lint-actions
- lint-copyright
runs-on: ubuntu-latest
if: always()
env:
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,17 @@ temporal-server-debug: $(ALL_SRC)
copyright-check:
@printf $(COLOR) "Check license header..."
@go run ./cmd/tools/copyright/licensegen.go --verifyOnly
@check_failed=false; \
current_year=$$(date +'%Y'); \
for file in $$(git diff --diff-filter=A --name-only origin/main HEAD | grep '\.go$$'); do \
if ! grep -q "Copyright (c) $$current_year Temporal Technologies Inc." "$$file"; then \
printf $(RED) "New file $$file missing license information or information is invalid."; \
check_failed=true; \
fi; \
done; \
if [ "$$check_failed" = true ]; then \
printf $(RED) "Copyright check failed, aborting" && exit 1; \
fi

copyright:
@printf $(COLOR) "Fix license header..."
Expand Down
7 changes: 6 additions & 1 deletion cmd/tools/copyright/licensegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"time"
)

type (
Expand Down Expand Up @@ -195,5 +197,8 @@ func commentOutLines(str string) (string, error) {
if err := scanner.Err(); err != nil {
return "", err
}
return strings.Join(lines, ""), nil
licenseToOutput := strings.Join(lines, "")
licenseToOutput = strings.Replace(licenseToOutput, "// Copyright (c) 2020 Uber Technologies, Inc.\n//\n", "", 1)
licenseToOutput = strings.Replace(licenseToOutput, "2020", strconv.Itoa(time.Now().Year()), 1)
return licenseToOutput, nil
}