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 check-updates workflow #29

Merged
merged 5 commits into from
Mar 5, 2024
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
9 changes: 9 additions & 0 deletions .github/needs-update-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Changes to the API spec detected
---

Changes to the API specification were found, which suggests a new release for this library is needed.

Please run `bin/generate`, review the changes and publish a new release.

cc @tremendous-rewards/platform
20 changes: 20 additions & 0 deletions .github/workflows/check-updates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Check if the Open API has changed
on:
schedule:
- cron: '0 */6 * * *'

jobs:
check-update:
if: github.repository == 'tremendous-rewards/tremendous-node'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: check-update
run: ./bin/check-updates

- id: create-issue
if: ${{ steps.check-update.outputs.changed == 'true' }}
uses: JasonEtco/create-an-issue@1b14a70e4d8dc185e5cc76d3bec9eab20257b2c5
with:
update_existing: false
filename: .github/needs-update-template.md
6 changes: 2 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ name: Run tests

on:
push:
branches-ignore:
- 'dependabot/**'
tags-ignore:
- 'v*'
branches:
- 'main'
pull_request_target:
branches:
- 'main'
Expand Down
22 changes: 12 additions & 10 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
## Step 1 - How to re-generate the SDK
## Step 1 - Re-generate the SDK source code

The source code from this repo is generated using [OpenAPI generator][1] and the Open API specification for the Tremendous API, available to Tremendous engineers.
The source code from this repo is generated using [OpenAPI generator][1] and the Open API specification for the Tremendous API. The `.ts` files can be re-generated and compiled with the following commands:

```console
# generate a fresh Open API spec file
cd core && bin/openapi-bundle

# generate new `.ts` files and compile them into `./dist`
cd tremendous-node-spike && bin/generate [PATH TO YML] && npm run build
bin/generate && npm run build
```

After that, please review the changes to double check that the changes to the API spec were
generated correctly. Please open a Pull Request with the file changes and wait for the test pipeline
before merging it to master.

## Step 2 - Update the version on `package.json`

Bump the version on `package.json` manually following [Semantic Versioning][2] practices - most changes here should be backwards compatible and deserve a MINOR version update
The Pull Request with the changes to the generated files should update the version on `package.json`
following [Semantic Versioning][2] practices - most changes here should be backwards compatible and
deserve a MINOR version update

## Step 3 - Publish a new release on GitHub

The [publish.yml](.github/workflows/publish.yml) workflow is responsible for publishing the package to NPM when a new release is published on GitHub.

The [publish.yml](.github/workflows/publish.yml) workflow is responsible for publishing the package to
NPM when a new release is published on GitHub.

[1]: https://openapi-generator.tech
[2]: https://semver.org
19 changes: 19 additions & 0 deletions bin/check-updates
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

test -f "$1" && spec="$1" || spec=$(./bin/download-spec)

current=$(cat ./*.ts | md5sum | awk '{print $1}')

./bin/generate "$spec"

changed=$(cat ./*.ts | md5sum | awk '{print $1}')

if [[ "$current" == "$changed" ]]; then
echo "Generated code hasn't changed"
test -n "$CI" && echo "changed=false" >> "$GITHUB_OUTPUT"
else
echo "Changes found"
test -n "$CI" && echo "changed=true" >> "$GITHUB_OUTPUT"
fi
9 changes: 9 additions & 0 deletions bin/download-spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

path="./tmp/spec.yml"

rm -rf $path && \
curl -o $path https://cdn.tremendous.com/openapi/spec.yml && \
echo $path
4 changes: 1 addition & 3 deletions bin/generate
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

set -e

spec="$1"

test -f "$spec" || (echo "USAGE: $0 [PATH TO SPEC FILE]" && exit 1)
test -f "$1" && spec="$1" || spec=$(./bin/download-spec)

docker run --rm \
-v ./:/output \
Expand Down