Skip to content

Commit 055bfff

Browse files
add justfile, remove coveralls, tweak ESLint (#2249)
* add justfile, remove coveralls * fix ci * fix ci * better CI Logging * now come on * clean up CI and make more reliable * update readme instructions * update justfile import * try pinning to ubuntu 24.04 * clean up CI * split out recipes
1 parent 2fda90e commit 055bfff

File tree

11 files changed

+161
-353
lines changed

11 files changed

+161
-353
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ indent_size = 2
77
indent_style = space
88
insert_final_newline = true
99
trim_trailing_whitespace = true
10+
11+
[justfile]
12+
indent_size = 4

.eslintrc.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,19 @@ module.exports = {
242242
parserOptions: {
243243
ecmaVersion: 2018,
244244
},
245-
plugins: ['prettier', 'import'],
246-
extends: ['plugin:prettier/recommended'],
245+
plugins: ['import'],
246+
// disable formatting rules - prettier will handle this itself
247+
extends: ['prettier'],
247248
overrides: [
248249
{
249250
files: ['**/*.ts'],
250-
plugins: ['@typescript-eslint', 'prettier'],
251+
plugins: ['@typescript-eslint'],
251252
extends: [
252253
'eslint:recommended',
253254
'plugin:@typescript-eslint/eslint-recommended',
254255
'plugin:@typescript-eslint/recommended',
255-
'plugin:prettier/recommended',
256+
// disable formatting rules - prettier will handle this itself
257+
'prettier',
256258
],
257259
rules: {
258260
'@typescript-eslint/no-use-before-define': 0,

.github/workflows/main.yml

+23-25
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ on:
1717
- sdk-release/**
1818
- feature/**
1919

20-
2120
jobs:
2221
build:
23-
name: Build
24-
runs-on: ubuntu-latest
22+
name: 'Static Checks'
23+
runs-on: 'ubuntu-24.04'
2524

2625
steps:
26+
- uses: extractions/setup-just@v2
2727
- uses: actions/checkout@v2
2828

2929
- name: Setup node
@@ -41,30 +41,32 @@ jobs:
4141
restore-keys: |
4242
${{ runner.os }}-yarn-
4343
44-
- name: Build Typescript
45-
run: yarn && yarn build
44+
- name: Verify Linting
45+
run: just lint-check
4646

47-
- name: Lint
48-
run: yarn lint
47+
- name: Verify Formatting
48+
run: just format-check
4949

5050
test:
5151
name: Test (${{ matrix.node }})
5252
needs: [build]
5353
strategy:
54+
fail-fast: false
5455
matrix:
5556
os:
56-
- "ubuntu-latest"
57+
- 'ubuntu-24.04'
5758
node:
5859
# should include even numbers >= 12
5960
# see: https://nodejs.org/en/about/previous-releases
60-
- "22"
61-
- "20"
62-
- "18"
63-
- "16"
64-
- "14"
65-
- "12"
61+
- '22'
62+
- '20'
63+
- '18'
64+
- '16'
65+
- '14'
66+
- '12'
6667
runs-on: ${{ matrix.os }}
6768
steps:
69+
- uses: extractions/setup-just@v2
6870
- uses: actions/checkout@v2
6971

7072
- name: Setup node
@@ -75,6 +77,7 @@ jobs:
7577
- name: Print Node.js version
7678
run: node -v
7779

80+
# used for one of the integration tests
7881
- name: Setup Deno
7982
uses: denoland/setup-deno@v1
8083
with:
@@ -91,22 +94,15 @@ jobs:
9194
id: yarn-cache
9295
with:
9396
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
94-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
97+
# searching very deep deps can time out, so only cache on the root yarn.lock
98+
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
9599
restore-keys: |
96100
${{ runner.os }}-yarn-
97101
98102
- uses: stripe/openapi/actions/stripe-mock@master
99103

100104
- name: Test
101-
run: make ci-test
102-
103-
- name: Coveralls
104-
run: yarn report && yarn coveralls
105-
if: env.COVERALLS_REPO_TOKEN && matrix.node == '18'
106-
env:
107-
GITHUB_TOKEN: ${{ secrets.github_token }}
108-
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
109-
COVERALLS_FLAG_NAME: node-${{ matrix.node }}
105+
run: just ci-test
110106

111107
publish:
112108
name: Publish
@@ -115,8 +111,10 @@ jobs:
115111
startsWith(github.ref, 'refs/tags/v') &&
116112
endsWith(github.actor, '-stripe')
117113
needs: [build, test]
118-
runs-on: ubuntu-latest
114+
runs-on: 'ubuntu-24.04'
119115
steps:
116+
# just is called in `yarn prepack`, which is called during the `publish` operation
117+
- uses: extractions/setup-just@v2
120118
- uses: actions/checkout@v2
121119
- run: sudo apt-get install -y oathtool
122120
- name: Publish to NPM

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# internal files of the nextjs example
2+
.next

Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# NOTE: this file is deprecated and slated for deletion; prefer using the equivalent `just` commands.
2+
13
.PHONY: codegen-format update-version test ci-test
24
update-version:
35
@echo "$(VERSION)" > VERSION

README.md

+21-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[![Version](https://img.shields.io/npm/v/stripe.svg)](https://www.npmjs.org/package/stripe)
44
[![Build Status](https://github.com/stripe/stripe-node/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/stripe/stripe-node/actions?query=branch%3Amaster)
5-
[![Coverage Status](https://coveralls.io/repos/github/stripe/stripe-node/badge.svg?branch=master)](https://coveralls.io/github/stripe/stripe-node?branch=master)
65
[![Downloads](https://img.shields.io/npm/dm/stripe.svg)](https://www.npmjs.com/package/stripe)
76
[![Try on RunKit](https://badge.runkitcdn.com/stripe.svg)](https://runkit.com/npm/stripe)
87

@@ -598,50 +597,56 @@ New features and bug fixes are released on the latest major version of the `stri
598597

599598
[Contribution guidelines for this project](CONTRIBUTING.md)
600599

601-
Run all tests:
600+
The tests depend on [stripe-mock][stripe-mock], so make sure to fetch and
601+
run it from a background terminal ([stripe-mock's README][stripe-mock-usage]
602+
also contains instructions for installing via Homebrew and other methods):
602603

603604
```bash
604-
$ yarn install
605-
$ yarn test
605+
go get -u github.com/stripe/stripe-mock
606+
stripe-mock
606607
```
607608

608-
If you do not have `yarn` installed, you can get it with `npm install --global yarn`.
609+
We use [just](https://github.com/casey/just) for conveniently running development tasks. You can use them directly, or copy the commands out of the `justfile`. To our help docs, run `just`.
609610

610-
The tests also depends on [stripe-mock][stripe-mock], so make sure to fetch and
611-
run it from a background terminal ([stripe-mock's README][stripe-mock-usage]
612-
also contains instructions for installing via Homebrew and other methods):
611+
Run all tests (installing the dependencies first, if needed)
613612

614613
```bash
615-
go get -u github.com/stripe/stripe-mock
616-
stripe-mock
614+
just test
615+
# or: yarn && yarn test
617616
```
618617

619-
Run a single test suite without a coverage report:
618+
If you do not have `yarn` installed, consult its [installation instructions](https://classic.yarnpkg.com/lang/en/docs/install/).
619+
620+
Run a single test suite:
620621

621622
```bash
622-
$ yarn mocha-only test/Error.spec.ts
623+
just test test/Error.spec.ts
624+
# or: yarn test test/Error.spec.ts
623625
```
624626

625627
Run a single test (case sensitive) in watch mode:
626628

627629
```bash
628-
$ yarn mocha-only test/Error.spec.ts --grep 'Populates with type' --watch
630+
just test test/Error.spec.ts --grep 'StripeError' --watch
631+
# or: yarn test test/Error.spec.ts --grep 'StripeError' --watch
629632
```
630633

631634
If you wish, you may run tests using your Stripe _Test_ API key by setting the
632635
environment variable `STRIPE_TEST_API_KEY` before running the tests:
633636

634637
```bash
635-
$ export STRIPE_TEST_API_KEY='sk_test....'
636-
$ yarn test
638+
export STRIPE_TEST_API_KEY='sk_test....'
639+
just test
640+
# or: yarn test
637641
```
638642

639643
Run prettier:
640644

641645
Add an [editor integration](https://prettier.io/docs/en/editors.html) or:
642646

643647
```bash
644-
$ yarn fix
648+
just format
649+
# or: yarn prettier src/**/*.ts --write
645650
```
646651

647652
[api-keys]: https://dashboard.stripe.com/account/apikeys

justfile

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
set quiet
2+
3+
import? '../sdk-codegen/utils.just'
4+
5+
# make locally installed binaries available throughout the tree without a longer specifier
6+
# this is useful in this file, but also depended on by webhook tests that expect to be able to call `eslint` and (I think) don't set it up correctly themselves.
7+
export PATH := `pwd` + "/node_modules/.bin:" + env('PATH')
8+
9+
_default:
10+
just --list --unsorted
11+
12+
# this uses positional-args so that mixed quoted and unquoted arguments
13+
# (like filtering for a certain test) work the way we expect
14+
# ⭐ run unit tests
15+
[positional-arguments]
16+
test *args: install build
17+
mocha "$@"
18+
19+
# try to compile the example TS file to make sure exports work
20+
types-test: build
21+
tsc --build types/test
22+
23+
# run full integration tests by installing a bunch of packages and starting servers (slow)
24+
integrations-test: build
25+
RUN_INTEGRATION_TESTS=1 mocha test/Integration.spec.ts
26+
27+
# run the full test suite; you probably want `test`
28+
ci-test: install test types-test integrations-test
29+
30+
_build mode packageType: install
31+
mkdir -p {{ mode }}
32+
tsc -p tsconfig.{{ mode }}.json
33+
echo '{"type":"{{ packageType }}"}' > {{ mode }}/package.json
34+
35+
[private]
36+
build-esm: (_build "esm" "module")
37+
38+
[private]
39+
build-cjs: (_build "cjs" "commonjs")
40+
41+
# generate CJS and ESM versions of the package; mostly used as a pre-req for other steps
42+
build: build-esm build-cjs
43+
44+
# ⭐ run style checks, fixing issues if possible
45+
lint: (lint-check "--fix")
46+
47+
# run style checks without changing anything
48+
lint-check *args: install
49+
eslint --ext .js,.ts . {{ args }}
50+
51+
# reinstall dependencies, if needed
52+
install:
53+
yarn {{ if is_dependency() == "true" { "--silent" } else { "" } }}
54+
55+
[no-exit-message]
56+
[private]
57+
prettier *args: install
58+
# all the project-relevant JS code
59+
prettier "{src,examples,scripts,test,types}/**/*.{ts,js}" {{ args }}
60+
61+
# ⭐ format all files
62+
format: (prettier "--write --loglevel silent") _update-api-version
63+
64+
# verify formatting of files (without changes)
65+
format-check: (prettier "--check")
66+
67+
# propagate automatic changes; should be run after generation
68+
# in practice, that means it runs after formatting, since that's the only recipe that the generator calls
69+
_update-api-version:
70+
./scripts/updateAPIVersion.js
71+
72+
# called by tooling
73+
[private]
74+
update-version version:
75+
echo "{{ version }}" > VERSION
76+
perl -pi -e 's|"version": "[.\-\d\w]+"|"version": "{{ version }}"|' package.json
77+
perl -pi -e "s|Stripe.PACKAGE_VERSION = '[.\-\d\w]+'|Stripe.PACKAGE_VERSION = '{{ version }}'|" src/stripe.core.ts
78+
79+
# remove build artifacts
80+
clean:
81+
rm -rf ./node_modules/.cache ./esm ./cjs

package.json

+2-14
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@typescript-eslint/parser": "^4.33.0",
3636
"chai": "^4.3.6",
3737
"chai-as-promised": "~7.1.1",
38-
"coveralls": "^3.1.1",
3938
"eslint": "^7.32.0",
4039
"eslint-config-prettier": "^8.5.0",
4140
"eslint-plugin-chai-friendly": "^0.7.2",
@@ -60,19 +59,8 @@
6059
},
6160
"license": "MIT",
6261
"scripts": {
63-
"build": "yarn build-esm && yarn build-cjs",
64-
"build-esm": "mkdir -p esm && tsc -p tsconfig.esm.json && echo '{\"type\":\"module\"}' > esm/package.json",
65-
"build-cjs": "mkdir -p cjs && tsc -p tsconfig.cjs.json && echo '{\"type\":\"commonjs\"}' > cjs/package.json",
66-
"clean": "rm -rf ./.nyc_output ./node_modules/.cache ./coverage ./esm ./cjs",
67-
"prepack": "yarn install && yarn build",
68-
"mocha": "nyc mocha",
69-
"mocha-only": "mocha",
70-
"test": "yarn build && yarn test-typescript && yarn mocha",
71-
"test-typescript": "tsc --build types/test",
72-
"lint": "eslint --ext .js,.jsx,.ts .",
73-
"fix": "yarn lint --fix && ./scripts/updateAPIVersion.js",
74-
"report": "nyc -r text -r lcov report",
75-
"coveralls": "cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js"
62+
"test": "tsc -p tsconfig.cjs.json && mocha",
63+
"prepack": "just install && just build"
7664
},
7765
"exports": {
7866
"types": "./types/index.d.ts",

scripts/updateAPIVersion.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#!/usr/bin/env node
22

3+
/**
4+
* Reads the current API version from src/apiVersion.ts and updates all
5+
* references to it in the types/ directory.
6+
*/
7+
38
/* eslint-disable no-sync,no-nested-ternary */
49
const fs = require('fs');
510
const path = require('path');
@@ -12,7 +17,7 @@ const API_VERSION = '2[0-9][2-9][0-9]-[0-9]{2}-[0-9]{2}.[a-z]+';
1217

1318
const main = () => {
1419
const matches = [
15-
...read('src/apiVersion.ts').matchAll(/ApiVersion . '([^']*)'/g),
20+
...read('src/apiVersion.ts').matchAll(/ApiVersion = '([^']*)'/g),
1621
];
1722
if (matches.length !== 1) {
1823
throw new Error(

test/Integration.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ import {FAKE_API_KEY} from './testUtils.js';
44
const nodeVersion = parseInt(process.versions.node.split('.')[0], 10);
55

66
describe('Integration test', function() {
7+
// these tests are expensive and start processes they don't clean up
8+
// so, skip them in the regular test suite (which we run locally) and run them via `just test-integrations`
9+
// (which is also called in CI)
10+
before(function() {
11+
if (process.env.RUN_INTEGRATION_TESTS !== '1') {
12+
this.skip();
13+
}
14+
});
15+
716
this.timeout(50000);
817
const testExec = (cmd: string): Promise<void> => {
918
const child = childProcess.exec(cmd);

0 commit comments

Comments
 (0)