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

add justfile, update readme, remove coveralls #1964

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
60 changes: 26 additions & 34 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: extractions/setup-just@v2
- uses: actions/checkout@master

- name: Setup go
Expand All @@ -34,42 +35,33 @@ jobs:

- name: lint
run: |
go install honnef.co/go/tools/cmd/staticcheck@v0.4.7 &&
go install golang.org/x/tools/cmd/goimports@v0.24.0 &&
$HOME/go/bin/staticcheck &&
make vet &&
make check-gofmt
just lint format-check
test:
runs-on: ubuntu-latest
strategy:
matrix:
go:
- "1.23"
- "1.22"
- "1.21"
- "1.20"
- "1.19"
- "1.18"
- "1.17"
- "1.16"
- "1.15"
name: "Test: go v${{ matrix.go }}"
steps:
- uses: actions/checkout@v2
- name: Setup go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}
- uses: stripe/openapi/actions/stripe-mock@master
- name: Test
run: make ci-test
- name: Coveralls
run: make coverage && make coveralls
if: matrix.go == '1.16'
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_FLAG_NAME: Go-${{ matrix.go }}
runs-on: ubuntu-latest
Copy link
Member Author

@xavdid-stripe xavdid-stripe Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this block is mostly the same except coveralls is gone and just is used in favor of make. The rest of the changes are that, prettier shifted it over (it was intended by 5 spaces?)

strategy:
matrix:
go:
- "1.23"
- "1.22"
- "1.21"
- "1.20"
- "1.19"
- "1.18"
- "1.17"
- "1.16"
- "1.15"
name: "Test: go v${{ matrix.go }}"
steps:
- uses: extractions/setup-just@v2
- uses: actions/checkout@v2
- name: Setup go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}
- uses: stripe/openapi/actions/stripe-mock@master
- name: Test
run: just ci-test

publish:
name: Publish
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# NOTE: this file is deprecated and slated for deletion; prefer using the equivalent `just` commands.

all: test bench vet lint check-api-clients check-gofmt ci-test

bench:
Expand Down Expand Up @@ -43,7 +45,7 @@ codegen-format: normalize-imports
go install golang.org/x/tools/cmd/goimports@v0.24.0 && goimports -w example/generated_examples_test.go

CURRENT_MAJOR_VERSION := $(shell cat VERSION | sed 's/\..*//')
normalize-imports:
normalize-imports:
@perl -pi -e 's|github.com/stripe/stripe-go/v\d+|github.com/stripe/stripe-go/v$(CURRENT_MAJOR_VERSION)|' go.mod
@find . -name '*.go' -exec perl -pi -e 's|github.com/stripe/stripe-go/(v\d+\|\[MAJOR_VERSION\])|github.com/stripe/stripe-go/v$(CURRENT_MAJOR_VERSION)|' {} +

Expand Down
20 changes: 7 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![Go Reference](https://pkg.go.dev/badge/github.com/stripe/stripe-go)](https://pkg.go.dev/github.com/stripe/stripe-go/v81)
[![Build Status](https://github.com/stripe/stripe-go/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/stripe/stripe-go/actions/workflows/ci.yml?query=branch%3Amaster)
[![Coverage Status](https://coveralls.io/repos/github/stripe/stripe-go/badge.svg?branch=master)](https://coveralls.io/github/stripe/stripe-go?branch=master)

The official [Stripe][stripe] Go client library.

Expand Down Expand Up @@ -628,6 +627,7 @@ func make_raw_request() error {
}

```

See more examples in the [/example/v2 folder](example/v2).

## Support
Expand All @@ -641,19 +641,13 @@ the following guidelines in mind:

1. Code must be `go fmt` compliant.
2. All types, structs and funcs should be documented.
3. Ensure that `make test` succeeds.
3. Ensure that `just test` succeeds.

## Test

The test suite needs testify's `require` package to run:

github.com/stretchr/testify/require

Before running the tests, make sure to grab all of the package's dependencies:

go get -t -v
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`.

It also depends on [stripe-mock][stripe-mock], so make sure to fetch and run it from a
This package depends on [stripe-mock][stripe-mock], so make sure to fetch and run it from a
background terminal ([stripe-mock's README][stripe-mock-usage] also contains
instructions for installing via Homebrew and other methods):

Expand All @@ -662,15 +656,15 @@ instructions for installing via Homebrew and other methods):

Run all tests:

make test
just test

Run tests for one package:

go test ./invoice
just test ./invoice

Run a single test:

go test ./invoice -run TestInvoiceGet
just test ./invoice -run TestInvoiceGet

For any requests, bug or comments, please [open an issue][issues] or [submit a
pull request][pulls].
Expand Down
62 changes: 62 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
set quiet

import? '../sdk-codegen/justfile'

_default:
just --list --unsorted

# ⭐ run all unit tests, or pass a package name (./invoice) to only run those tests
test *args="./...":
go run scripts/test_with_stripe_mock/main.go -race {{ args }}

# check for potential mistakes (slow)
lint: install
go vet ./...
staticcheck

# ⭐ format all files
format: install
scripts/gofmt.sh
goimports -w example/generated_examples_test.go

# verify, but don't modify, the formatting of the files
format-check:
scripts/gofmt.sh check

# ensures all client structs are properly registered
check-api-clients:
go run scripts/check_api_clients/main.go

ci-test: test bench check-api-clients

# compile the project
build:
go build ./...

# install dependencies (including those needed for development). Mostly called by other recipes
install:
go get
go install honnef.co/go/tools/cmd/staticcheck@v0.4.7
go install golang.org/x/tools/cmd/goimports@v0.24.0

# run benchmarking to check for performance regressions
bench:
go test -race -bench . -run "Benchmark" ./form

# called by tooling. It updates the package version in the `VERSION` file and `stripe.go`
[private]
update-version version: && _normalize-imports
echo "{{ version }}" > VERSION
perl -pi -e 's|const clientversion = "[.\d\-\w]+"|const clientversion = "{{ version }}"|' stripe.go

# go imports use the package's major version in the path, so we need to update them
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only especially tricky thing- we want major_version to be evaluated lazily, but also shared throughout the recipe.

This comment is probably too detailed, but I wanted to remind myself why I did it exactly this way.

# we also generate files with a placeholder `[MAJOR_VERSION]` that we need to replace
# we can pull the major version out of the `VERSION` file
# NOTE: because we run this _after_ other recipes that modify `VERSION`, it's important that we only read the file in the argument evaluation
# (if it's a top-level variable, it's read when the file is parsed, which is too early)
# arguments are only evaluated when the recipe starts
# so, setting it as the default means we get both the variable and the lazy evaluation we need
_normalize-imports major_version=replace_regex(`cat VERSION`, '\..*', ""):
perl -pi -e 's|github.com/stripe/stripe-go/v\d+|github.com/stripe/stripe-go/v{{ major_version }}|' README.md
perl -pi -e 's|github.com/stripe/stripe-go/v\d+|github.com/stripe/stripe-go/v{{ major_version }}|' go.mod
find . -name '*.go' -exec perl -pi -e 's|github.com/stripe/stripe-go/(v\d+\|\[MAJOR_VERSION\])|github.com/stripe/stripe-go/v{{ major_version }}|' {} +
Loading