diff --git a/.github/needs-update-template.md b/.github/needs-update-template.md new file mode 100644 index 0000000..d9b3ec4 --- /dev/null +++ b/.github/needs-update-template.md @@ -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 diff --git a/.github/workflows/check-updates.yml b/.github/workflows/check-updates.yml new file mode 100644 index 0000000..93b6564 --- /dev/null +++ b/.github/workflows/check-updates.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 03dadda..7c66846 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,10 +2,8 @@ name: Run tests on: push: - branches-ignore: - - 'dependabot/**' - tags-ignore: - - 'v*' + branches: + - 'main' pull_request_target: branches: - 'main' diff --git a/RELEASING.md b/RELEASING.md index 129c65e..2618d1b 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -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 diff --git a/bin/check-updates b/bin/check-updates new file mode 100755 index 0000000..bb94666 --- /dev/null +++ b/bin/check-updates @@ -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 diff --git a/bin/download-spec b/bin/download-spec new file mode 100755 index 0000000..a572265 --- /dev/null +++ b/bin/download-spec @@ -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 diff --git a/bin/generate b/bin/generate index fd79f79..3e0189d 100755 --- a/bin/generate +++ b/bin/generate @@ -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 \