Skip to content

Commit

Permalink
refactor makefile and add CI (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyinma authored Jun 24, 2022
1 parent c241503 commit b5337e2
Show file tree
Hide file tree
Showing 13 changed files with 3,837 additions and 3,740 deletions.
33 changes: 9 additions & 24 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2020-2021 Buf Technologies, Inc.
// Copyright 2020-2022 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.
Expand All @@ -12,39 +12,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.

const ignoreFiles = [".eslintrc.js", "dist/**/*"];

module.exports = {
env: {
es2021: true
es2022: true,
},
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
],
ignorePatterns: ignoreFiles,
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: "tsconfig.json",
tsconfigRootDir: __dirname,
ecmaFeatures: {
jsx: true
jsx: true,
},
ecmaVersion: 12,
sourceType: "module",
},
plugins: [
"@typescript-eslint",
],
ignorePatterns: [
".eslintrc.js",
],
rules: {
"@typescript-eslint/strict-boolean-expressions": "error",
"@typescript-eslint/no-unnecessary-condition": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/switch-exhaustiveness-check": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
"@typescript-eslint/no-invalid-void-type": "error",
"@typescript-eslint/no-base-to-string": "error"
},
plugins: ["@typescript-eslint"],
rules: {},
};
30 changes: 30 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: ci
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch: {} # support manual runs
# Prevent writing to the repository using the CI token.
# Ref: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#permissions
permissions: read-all
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.18
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Generate
run: make generate && make checkgenerate
- name: Build
run: make build && make checkgenerate
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.tmp/
node_modules/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist
67 changes: 55 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
# See https://tech.davis-hansson.com/p/make/
SHELL := bash
.DELETE_ON_ERROR:
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
COPYRIGHT_YEARS := 2020-2022
LICENSE_IGNORE := -e dist\/

.PHONY: all
all: ## Format, Lint and build (default)
$(MAKE) build

.PHONY: format
format: node_modules
npm run format

.PHONY: lint
lint: node_modules
npm run lint

.PHONY: build
build:
@tsc
@eslint ./src
@esbuild \
--minify \
--bundle \
--sourcemap \
'--define:process.env.NODE_ENV="production"' \
--outdir=dist \
--platform=node \
--target=node12 \
./src/main.ts
build: node_modules format lint
npm run build

.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)"

.PHONY: checkgenerate
checkgenerate:
@# Used in CI to verify that `make generate` doesn't produce a diff.
test -z "$$(git status --porcelain | tee /dev/stderr)"

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/[email protected]
12 changes: 6 additions & 6 deletions dist/main.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/main.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit b5337e2

Please sign in to comment.