Skip to content

Commit

Permalink
Switch to npm binary for license headers (#6)
Browse files Browse the repository at this point in the history
The license-header binary is also available as a npm binary. It
integrates nicely into npm projects because it's installed as a npm
dependency, supports configuration in package.json, idiomatic glob
ignores, and several additional typical file extensions.

Since this is a npm project, it makes sense to me to use it here.

---------

Co-authored-by: Edward McFarlane <[email protected]>
  • Loading branch information
timostamm and emcfarlane authored May 31, 2024
1 parent 791b5c7 commit f69c967
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 37 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,6 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
- uses: actions/setup-go@v5
with:
go-version: "^1.22"
cache: false
- uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-cache-${{ hashFiles('Makefile') }}
restory-keys: ${{ runner.os }}-go-cache-
- name: Build
run: |
make build
Expand Down
24 changes: 2 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ SHELL := bash
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
COPYRIGHT_YEARS := 2024
LICENSE_IGNORE := -e dist\/
BUF_VERSION ?= 1.32.2

UNAME_S := $(shell uname -s)
Expand Down Expand Up @@ -50,20 +47,8 @@ endif
$(SED_I) "s/version: [0-9]+\.[0-9]+\.[0-9]+/version: $(BUF_VERSION)/g" examples/*.yaml

.PHONY: generate
generate: $(BIN)/license-header ## Regenerate licenses
@# We want to operate on a list of modified and new files, excluding
@# deleted and ignored files. git-ls-files can't do this alone. comm -23 takes
@# two files and prints the union, dropping lines common to both (-3) and
@# those only in the second file (-2). We make one git-ls-files call for
@# the modified, cached, and new (--others) files, and a second for the
@# deleted files.
comm -23 \
<(git ls-files --cached --modified --others --no-empty-directory --exclude-standard | sort -u | grep -v $(LICENSE_IGNORE) ) \
<(git ls-files --deleted | sort -u) | \
xargs $(BIN)/license-header \
--license-type apache \
--copyright-holder "Buf Technologies, Inc." \
--year-range "$(COPYRIGHT_YEARS)"
generate: node_modules ## Regenerate licenses
npm run generate

.PHONY: checkgenerate
checkgenerate:
Expand All @@ -72,8 +57,3 @@ checkgenerate:

node_modules: package-lock.json
npm ci

$(BIN)/license-header: Makefile
@mkdir -p $(@D)
GOBIN=$(abspath $(@D)) go install \
github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v$(BUF_VERSION)
14 changes: 14 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2024 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
Expand Down
19 changes: 16 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"format": "prettier --write 'src/*.{json,js,jsx,ts,tsx,css}' --log-level error",
"lint": "eslint --max-warnings 0 src",
"lint:fix": "eslint --max-warnings 0 --fix src",
"build": "ncc build -o dist src/main.ts"
"build": "ncc build -o dist src/main.ts",
"generate": "license-header --ignore 'dist/**'"
},
"keywords": [
"actions",
Expand All @@ -18,7 +19,13 @@
],
"author": "Buf Technologies, Inc.",
"license": "Apache-2.0",
"licenseHeader": {
"licenseType": "apache",
"yearRange": "2024",
"copyrightHolder": "Buf Technologies, Inc."
},
"devDependencies": {
"@bufbuild/license-header": "^0.0.4",
"@eslint/js": "^9.2.0",
"@types/node": "^20.12.7",
"@vercel/ncc": "^0.38.1",
Expand Down

0 comments on commit f69c967

Please sign in to comment.