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

refactor: broke down Makefile targets #196

Draft
wants to merge 8 commits into
base: v4.x
Choose a base branch
from
Draft
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
12 changes: 7 additions & 5 deletions .github/workflows/branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
name: Install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Cache node_modules
id: cacheModules
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.npm # this is cache where npm installs from before going out to the network
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
Expand All @@ -25,12 +25,14 @@ jobs:
name: Debug
runs-on: ubuntu-latest
steps:
- uses: hmarr/debug-action@v2
- uses: hmarr/debug-action@v3

checks:
name: Check
needs: [install]
uses: ./.github/workflows/checks.yml
with:
ref: ${{ github.sha }}

# The security job can't run on pull requests opened from forks because
# Github doesn't pass down the SNYK_TOKEN environment variable.
Expand All @@ -39,8 +41,8 @@ jobs:
needs: [install]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.npm # this is cache where npm installs from before going out to the network
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
Expand Down
37 changes: 26 additions & 11 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
name: v4.x checks

on: [workflow_call]
on:
workflow_call:
inputs:
ref:
description: 'The commit the workflow should check out'
required: true
default: ${{ github.sha }}
type: string

jobs:
test-node:
Expand All @@ -12,13 +19,15 @@ jobs:
node-version: [14.x, 16.x, 18.x, 20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: actions/cache@v4
with:
path: ~/.npm # this is cache where npm installs from before going out to the network
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install --prefer-offline
Expand All @@ -28,13 +37,15 @@ jobs:
name: Browser Test Specs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: actions/cache@v4
with:
path: ~/.npm # this is cache where npm installs from before going out to the network
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- run: npm install --prefer-offline
Expand All @@ -44,8 +55,10 @@ jobs:
name: Code Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: actions/cache@v4
with:
path: ~/.npm # this is cache where npm installs from before going out to the network
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
Expand All @@ -56,8 +69,10 @@ jobs:
name: Types
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- uses: actions/cache@v4
with:
path: ~/.npm # this is cache where npm installs from before going out to the network
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ jobs:
name: Debug
runs-on: ubuntu-latest
steps:
- uses: hmarr/debug-action@v2
- uses: hmarr/debug-action@v3

install:
name: Install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Cache node_modules
id: cacheModules
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.npm # this is cache where npm installs from before going out to the network
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
Expand All @@ -43,3 +45,5 @@ jobs:
name: Checks
needs: [install]
uses: ./.github/workflows/checks.yml
with:
ref: ${{ github.event.pull_request.head.sha }}
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
name: Install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Cache node_modules
id: cacheModules
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ~/.npm # cache where "npm install" uses before going out to the network
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
Expand All @@ -31,7 +31,7 @@ jobs:
name: Debug
runs-on: ubuntu-latest
steps:
- uses: hmarr/debug-action@v2
- uses: hmarr/debug-action@v3

checks:
name: Check
Expand All @@ -45,8 +45,8 @@ jobs:
needs: [install]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.npm # cache where "npm install" uses before going out to the network
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
Expand All @@ -60,13 +60,13 @@ jobs:
runs-on: ubuntu-latest
needs: [checks, security]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
# Setup .npmrc file to publish to npm
registry-url: 'https://registry.npmjs.org'
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.npm # this is cache where npm installs from before going out to the network
key: ${{ runner.os }}-node-${{ hashFiles('**/package.json') }}
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
20
119 changes: 2 additions & 117 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include makefiles/*.mk

.PHONY: all
all: test lint typecheck

Expand Down Expand Up @@ -40,120 +42,3 @@ test/fetch-api/api.spec.js: test/fetch-api/api.spec.ts
@echo ""
@echo "=> make $@"
@npx tsc


##
# Checks

.PHONY: commitlint
commitlint: node_modules
npx commitlint --from origin/main --to HEAD --verbose

.PHONY: cov
cov:
npx nyc report --reporter=text-lcov > .reports/coverage.lcov && npx codecov

.PHONY: lint
lint:
@echo ""
@echo "=> make $@"
@npx standard

.PHONY: secure
secure:
@echo ""
@echo "=> make $@"
@npx snyk test

.PHONY: typecheck
typecheck:
@echo ""
@echo "=> make $@"
@npx tsc --lib ES6 --noEmit index.d.ts ./test/fetch-api/api.spec.ts


##
# Test groups

.PHONY: test
test: | test-browser test-node

.PHONY: test-browser
test-browser: |\
test-fetch-browser-native \
test-fetch-browser-whatwg \
test-fetch-browser-service-worker \
test-module-web-cjs \
test-module-web-esm \
test-module-react-native

.PHONY: test-node
test-node: |\
test-fetch-node-native \
test-fetch-node-fetch \
test-module-node-cjs \
test-module-node-esm


##
# Test units

.PHONY: test-fetch-browser-native
test-fetch-browser-native: | dist test/fetch-api/api.spec.js
@echo ""
@echo "=> make $@"
@./test/fetch-api/browser/run.sh

.PHONY: test-fetch-browser-whatwg
test-fetch-browser-whatwg: | dist test/fetch-api/api.spec.js
@echo ""
@echo "=> make $@"
@./test/fetch-api/whatwg/run.sh

.PHONY: test-fetch-browser-service-worker
test-fetch-browser-service-worker: dist test/fetch-api/api.spec.js
@echo ""
@echo "=> make $@"
@./test/fetch-api/service-worker/run.sh

.PHONY: test-fetch-node-native
test-fetch-node-native: | dist test/fetch-api/api.spec.js
@echo ""
@echo "=> make $@"
@./test/fetch-api/node/run.sh

.PHONY: test-fetch-node-fetch
test-fetch-node-fetch: | dist test/fetch-api/api.spec.js
@echo ""
@echo "=> make $@"
@./test/fetch-api/node-fetch/run.sh

.PHONY: test-module-web-cjs
test-module-web-cjs: | dist
@echo ""
@echo "=> make $@"
@./test/module-system/web.cjs/run.sh

.PHONY: test-module-web-esm
test-module-web-esm: | dist
@echo ""
@echo "=> make $@"
@./test/module-system/web.esm/run.sh

.PHONY: test-module-node-cjs
test-module-node-cjs: | dist
@echo ""
@echo "=> make $@"
@./test/module-system/node.cjs/run.sh

.PHONY: test-module-node-esm
test-module-node-esm: | dist
@echo ""
@echo "=> make $@"
@./test/module-system/node.esm/run.sh

.PHONY: test-module-react-native
test-module-react-native: | dist
@echo ""
@echo "=> make $@"
@./test/module-system/react-native/run.sh
17 changes: 17 additions & 0 deletions bin/is-port-in-use
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

const net = require('net')
const args = process.argv.slice(2)
const port = args[0] || 8000
const server = net.createServer().listen(port)

server.on('listening', () => {
server.close()
console.log('Port ' + port + ' is available.')
process.exit(0)
})

server.on('error', () => {
console.log('Port ' + port + ' is in use.')
process.exit(1)
})
30 changes: 30 additions & 0 deletions makefiles/checks.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

##
# Checks

.PHONY: commitlint
commitlint: node_modules
npx commitlint --from origin/main --to HEAD --verbose

.PHONY: cov
cov:
npx nyc report --reporter=text-lcov > .reports/coverage.lcov && npx codecov

.PHONY: lint
lint:
@echo ""
@echo "=> make $@"
@npx standard

.PHONY: secure
secure:
@echo ""
@echo "=> make $@"
@npx snyk test

.PHONY: typecheck
typecheck:
@echo ""
@echo "=> make $@"
@npx tsc --lib ES6 --noEmit index.d.ts ./test/fetch-api/api.spec.ts

Loading
Loading