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

Autogenerate sdk #14

Merged
merged 3 commits into from
Jul 10, 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
17 changes: 0 additions & 17 deletions .editorconfig

This file was deleted.

35 changes: 35 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name-template: '$RESOLVED_VERSION'
tag-template: '$RESOLVED_VERSION'
categories:
- title: 'Features'
labels:
- 'feature'
- 'enhancement'
- title: 'Fixes'
labels:
- 'fix'
- 'bugfix'
- 'bug'
- title: 'Maintenance'
label: 'chore'
change-template: '- $TITLE @$AUTHOR (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
template: |
## Changes

$CHANGES

**Contributors**: $CONTRIBUTORS

**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...$RESOLVED_VERSION
10 changes: 10 additions & 0 deletions .github/sdk-gen-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"library": "javascript",
"projectName": "databox",
"licenseName": "MIT",
"projectVersion": "{VERSION}",
"projectDescription": "SDK Client for using Databox Push API feature",
"apiPackage": "databox",
"invokerPackage": "databox",
"emitModelMethods": true
}
94 changes: 94 additions & 0 deletions .github/workflows/generate_sdk_code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Generate SDK Code
on:
repository_dispatch:
types: [publish_sdk]
env:
GENERATOR_VERISON: "7.6.0"
CONFIG_FILE: "sdk-gen-config.json"
jobs:
sdk:
name: Generate SDK code
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get Latest Release
id: latest-version
uses: pozetroninc/[email protected]
with:
owner: ${{ github.repository_owner }}
repo: databox-js
excludes: prerelease, draft
token: ${{ secrets.PAT_APPROVE_PR }}

- name: Determine Version
id: version
uses: actions/github-script@v7
with:
script: |
const version = '${{ steps.latest-version.outputs.release }}';
const parts = version.split('.');
switch('${{ github.event.client_payload.labels }}') {
case 'patch':
parts[2] = parseInt(parts[2]) + 1;
break;
case 'minor':
parts[1] = parseInt(parts[1]) + 1;
break;
case 'major':
parts[0] = parseInt(parts[0]) + 1;
break;
default:
parts[2] = parseInt(parts[2]) + 1;
break;
}
const newVersion = parts.join('.');
return newVersion;

- name: Download OpenAPI Generator
run: |
curl https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${{ env.GENERATOR_VERISON }}/openapi-generator-cli-${{ env.GENERATOR_VERISON }}.jar -o ${{ runner.temp }}/openapi-generator-cli.jar

- name: Download OpenAPI Specification
uses: actions/download-artifact@v4
with:
name: ${{ github.event.client_payload.openapi_spec }}
path: ${{ runner.temp }}/openapispec
repository: databox/data-link
github-token: ${{ secrets.PAT_APPROVE_PR }}
run-id: ${{ github.event.client_payload.run_id }}

- name: Remove old SDK
run: rm -rf src/*

- name: Set API and SDK versions
run: |
cp .github/${{ env.CONFIG_FILE }} ${{ runner.temp }}/${{ env.CONFIG_FILE }}

#set SDK version
sed -i "s/{VERSION}/${{ steps.version.outputs.result }}/g" ${{ runner.temp }}/${{ env.CONFIG_FILE }}

#set API version
sed -i 's/version: "1.0"/version: ${{ github.event.client_payload.version }}/g' ${{ runner.temp }}/openapispec/openapi.yml

- name: Generate SDK
run: |
java --version
java -jar ${{ runner.temp }}/openapi-generator-cli.jar generate -i ${{ runner.temp }}/openapispec/openapi.yml -g javascript -o ./src -c ${{ runner.temp }}/${{ env.CONFIG_FILE }} --skip-validate-spec
cp ./src/README.md ./README.md

- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
base: master
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: release data-link SDK'
title: '[SDK release] Generated SDK code based on data-link ${{ github.event.client_payload.version }} API changes'
branch: 'release/${{ github.event.client_payload.version }}/${{ github.event.client_payload.timestamp }}'
body: >
This is a release of the SDK based on the API changes for `data-link` [${{ github.event.client_payload.version }}](${{ github.event.client_payload.release_url }}).
labels: |
automated
${{ github.event.client_payload.labels || 'patch' }}
109 changes: 109 additions & 0 deletions .github/workflows/publish_sdk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Publish SDK
on:
push:
branches:
- master
paths:
- 'src/**'
jobs:
release_draft:
name: Create release draft
runs-on: ubuntu-latest
outputs:
release_body: ${{ steps.create_release_draft.outputs.body }}
release_tag: ${{ steps.create_release_draft.outputs.tag_name }}
release_html_url: ${{ steps.create_release_draft.outputs.html_url }}
release_id: ${{ steps.create_release_draft.outputs.id }}
steps:
- name: "Create release draft"
id: create_release_draft
uses: release-drafter/release-drafter@v6
with:
commitish: master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

build:
name: Build and publish SDK package
runs-on: ubuntu-latest
needs: release_draft
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Maven Action
uses: s4u/[email protected]

- name: Configure Maven
uses: s4u/[email protected]
with:
servers: |
[{
"id": "github",
"username": "${{ github.actor }}",
"password": "${{ secrets.PACKAGES_PUBLISH_TOKEN }}"
}]
path: ${{ github.workspace }}/.m2/settings.xml

- name: Publish SDK
run: mvn --batch-mode -DuseGitHubPackages=true deploy -s .m2/settings.xml
env:
GITHUB_TOKEN: ${{ secrets.PACKAGES_PUBLISH_TOKEN }}
GITHUB_USERNAME: ${{ github.actor }}

release_publish:
name: Publish release
runs-on: ubuntu-latest
needs:
- release_draft
- build
steps:
- name: "Publish release"
uses: eregon/publish-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
release_id: ${{ needs.release_draft.outputs.release_id }}

post_slack_job:
name: Post info to Slack in #engeering-releases channel
needs:
- release_draft
- release_publish
runs-on: ubuntu-latest
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
steps:
- name: Format to Slack msg
uses: LoveToKnow/[email protected]
id: slack_msg_converter
with:
text: ${{needs.release_draft.outputs.release_body}}
- name: Post to a Slack channel
if: success()
id: slack
uses: slackapi/[email protected]
with:
channel-id: 'C027FC31SVD'
payload: |
{
"text": "New version post",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "New <${{ github.server_url }}/${{ github.repository }}|`${{ github.repository }}`> release <${{ github.server_url }}/${{ github.repository }}/releases/${{ needs.create_release_draft_job.outputs.release_tag }}|${{ needs.create_release_draft_job.outputs.release_tag }}> is available! :tada:"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ${{toJSON(steps.slack_msg_converter.outputs.text)}}
}
}
]
}

16 changes: 16 additions & 0 deletions .github/workflows/require-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Pull Request Labels

on:
pull_request:
types: [opened, reopened, labeled, unlabeled, edited, synchronize]
branches: [master]

jobs:
label:
runs-on: ubuntu-latest
steps:
- uses: mheap/github-action-required-labels@v5
with:
mode: exactly
count: 1
labels: "major,minor,patch"
29 changes: 0 additions & 29 deletions .gitignore

This file was deleted.

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

This file was deleted.

36 changes: 0 additions & 36 deletions CHANGELOG.md

This file was deleted.

Loading
Loading