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

Setup GH Actions [ch32361] #44

Merged
merged 2 commits into from
Jul 28, 2021
Merged
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
77 changes: 77 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Run specs and generate Code Climate report
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
go-versions: ['1.11', '1.12', '1.13', '1.14']
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not go 1.16?

steps:
- uses: actions/checkout@v2

- name: Set up Go ${{ matrix.go-versions }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-versions }}

- name: Run tests
run: make test

code-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Set up Go ${{ matrix.go-versions }}
uses: actions/setup-go@v2
with:
go-version: '1.14'

- name: Set ENV for codeclimate (pull_request)
run: |
git fetch --no-tags --prune --depth=1 origin +refs/heads/$GITHUB_HEAD_REF:refs/remotes/origin/$GITHUB_HEAD_REF
echo "GIT_BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
echo "GIT_COMMIT_SHA=$(git rev-parse origin/$GITHUB_HEAD_REF)" >> $GITHUB_ENV
if: github.event_name == 'pull_request'

- name: Set ENV for codeclimate (push)
run: |
echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "GIT_COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV
if: github.event_name == 'push'

- name: Install Code Climate test report
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x ./cc-test-reporter
./cc-test-reporter before-build

- name: Run test coverage
run: |
for pkg in $(go list ./... | grep -v vendor); do
go test -coverprofile=$(echo $pkg | tr / -).cover $pkg
done
echo "mode: set" > c.out
grep -h -v "^mode:" ./*.cover >> c.out
rm -f *.cover
sed -i 's#^github.com/chartmogul/chartmogul-go/##g' c.out

- name: Send Report to Code Climate
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
if: ${{ success() }}
run: ./cc-test-reporter after-build
linter:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: 'v1.28.3'

10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
linters:
disable:
- gofumpt
presets:
- format
- unused
- performance
- complexity
- bugs

11 changes: 0 additions & 11 deletions .test-coverage.sh

This file was deleted.

30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ pre-commit: .git/hooks/pre-commit lint
go test -timeout=20s --short ./...

bin/golangci-lint:
wget -O - -q https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.27.0 # Go 1.11+
curl -s -L https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.28.3 # Go 1.11+


.PHONY: lint
lint: bin/golangci-lint
Expand Down
3 changes: 3 additions & 0 deletions chartmogul_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ var matchersCases = map[string]struct {
func TestErrorMatchers(t *testing.T) {
for testName, testCase := range matchersCases {
for fnName, expected := range testCase.expectations {
t := t
expected := expected
Copy link
Contributor

Choose a reason for hiding this comment

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

why?


var fn func() bool
switch fnName {
case "IsAlreadyExists":
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/connect_subscription_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestConnectSubscriptions(t *testing.T) {
t.Fatal(err)
}
//time.Sleep(time.Minute)
msubs, err := api.MetricsListSubscriptions(&cm.Cursor{PerPage: 200}, cus.UUID)
msubs, err := api.MetricsListCustomerSubscriptions(&cm.Cursor{PerPage: 200}, cus.UUID)
if err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/create_invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func TestCreateInvoice(t *testing.T) {
},
{
Type: "subscription",
AmountInCents: 10000,
ExternalID: "ext_line_item",
SubscriptionExternalID: "ext_subscription",
AmountInCents: 10000,
ExternalID: "ext_line_item",
SubscriptionExternalID: "ext_subscription",
SubscriptionSetExternalID: "ext_subscription_set",
PlanUUID: plan.UUID,
Quantity: 10,
Expand Down
2 changes: 1 addition & 1 deletion integration_tests/retrieve_invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestRetrieveInvoice(t *testing.T) {
},
{
Type: "subscription",
AmountInCents: 10000,
AmountInCents: 10000,
ExternalID: "ext_line_item",
SubscriptionExternalID: "ext_subscription",
SubscriptionSetExternalID: "ext_subscription_set",
Expand Down
4 changes: 2 additions & 2 deletions metrics_customer_subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ type MetricsCustomerSubscription struct {
ExternalID string `json:"external_id"`
Plan string `json:"plan"`
Quantity uint32 `json:"quantity"`
BillingCycleCount uint32 `json:"billing-cycle-count"`
MRR float64 `json:"mrr"`
ARR float64 `json:"arr"`
Status string `json:"status"`
BillingCycle string `json:"billing-cycle"`
BillingCycleCount uint32 `json:"billing-cycle-count"`
StartDate string `json:"start-date"`
EndDate string `json:"end-date"`
Currency string `json:"currency"`
Expand All @@ -29,7 +29,7 @@ type MetricsCustomerSubscriptions struct {

const metricsCustomerSubscriptionsEndpoint = "customers/:uuid/subscriptions"

// MetricsListSubscriptions lists all subscriptions for cutomer of a given UUID.
// MetricsListCustomerSubscriptions lists all subscriptions for cutomer of a given UUID.
//
// See https://dev.chartmogul.com/v1.0/reference#list-customer-subscriptions
func (api API) MetricsListCustomerSubscriptions(cursor *Cursor, customerUUID string) (*MetricsCustomerSubscriptions, error) {
Expand Down
44 changes: 29 additions & 15 deletions mock_chartmogul/chartmogul.go

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

1 change: 1 addition & 0 deletions subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ func TestCancelSubscriptionParams(t *testing.T) {
}

for name, tc := range testCases {
tc := tc
t.Run(name, func(t *testing.T) {
got, err := json.Marshal(tc.param)
if err != nil {
Expand Down