Skip to content

Commit

Permalink
First generation of osc-sdk-js
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Jutteau <[email protected]>
  • Loading branch information
jerome-jutteau committed May 25, 2022
1 parent f21ba74 commit 5e35454
Show file tree
Hide file tree
Showing 2,759 changed files with 176,098 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
target-branch: "main"
schedule:
interval: "daily"
17 changes: 17 additions & 0 deletions .github/scripts/check-creds-settings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -e

exit_code=0
if [ -z "$OSC_ACCESS_KEY" ]; then
echo "OSC_ACCESS_KEY var is not set, please fix"
exit_code=1
fi
if [ -z "$OSC_SECRET_KEY" ]; then
echo "OSC_SECRET_KEY var is not set, please fix"
exit_code=1
fi
if [ -z "$OSC_REGION" ]; then
echo "OSC_REGION var is not set, please fix"
exit_code=1
fi
exit $exit_code
28 changes: 28 additions & 0 deletions .github/scripts/osc-api-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/env bash
set -e

root=$(cd "$(dirname $0)/../.." && pwd)
if [ -e "$root/.auto-release-abort" ]; then
echo "previous step triggered stop, abort"
exit 0
fi
github_url="https://api.github.com/repos/outscale/osc-api/releases"

if [ -z "$GH_TOKEN" ]; then
echo "GH_TOKEN is missing, abort."
exit 1
fi

osc_api_last_release=$(curl -s -H "Authorization: token $GH_TOKEN" $github_url | jq ".[] | select(.prerelease == false) | select(.draft == false) | .tag_name" | sort -r --version-sort | head -n 1 | cut -f 2 -d '"')
local_api_version=$(cat $root/api_version)

echo "last API version used: $local_api_version"
echo "last available version: $osc_api_last_release"

if [[ "$local_api_version" = "$osc_api_last_release" ]]; then
echo "no update needed, exiting"
touch "$root/.auto-release-abort"
exit 0
fi

echo "$osc_api_last_release" > $root/api_version
40 changes: 40 additions & 0 deletions .github/scripts/release-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/env bash
set -e

root=$(cd "$(dirname $0)/../.." && pwd)
if [ -e "$root/.auto-release-abort" ]; then
echo "previous step triggered stop, abort"
exit 0
fi
# build new version number
local_sdk_version=$(cat $root/sdk_version)
local_sdk_version_major=$(echo $local_sdk_version | cut -d '.' -f 1)
local_sdk_version_minor=$(echo $local_sdk_version | cut -d '.' -f 2)
new_sdk_version_minor=$(( local_sdk_version_minor + 1 ))
new_sdk_version="$local_sdk_version_major.$new_sdk_version_minor.0"

branch_name="autobuild-$new_sdk_version"
git branch -m $branch_name

echo "$new_sdk_version" > $root/sdk_version

# build release notes
new_api_version=$(cat $root/api_version)
release_notes="# $new_sdk_version
- SDK update for Outscale API v$new_api_version
"
echo "$release_notes$(cat $root/changelog.md)" > $root/changelog.md

# generate SDK
cd "$root"
make gen

# setup git && commit
git config user.name "Outscale Bot"
git config user.email "[email protected]"
for f in src dist; do
git add $f || true
done
git commit -asm "osc-sdk-js v$new_sdk_version"
29 changes: 29 additions & 0 deletions .github/scripts/release-check-duplicate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/env bash
set -e

root=$(cd "$(dirname $0)/../.." && pwd)
if [ -e "$root/.auto-release-abort" ]; then
echo "previous step triggered stop, abort"
exit 0
fi
# build new version number
local_sdk_version=$(cat $root/sdk_version)
local_sdk_version_major=$(echo $local_sdk_version | cut -d '.' -f 1)
local_sdk_version_minor=$(echo $local_sdk_version | cut -d '.' -f 2)
new_sdk_version_minor=$(( local_sdk_version_minor + 1 ))
new_sdk_version="$local_sdk_version_major.$new_sdk_version_minor.0"

branch_name="autobuild-$new_sdk_version"

if [ -z "$GH_TOKEN" ]; then
echo "GH_TOKEN is missing, abort."
exit 1
fi

result=$(curl -s -H "Authorization: token $GH_TOKEN" "https://api.github.com/repos/outscale/osc-sdk-js/pulls" | jq ".[] | select(.title == \"SDK v$new_sdk_version\") | .title")

if [ ! -z "$result" ]; then
echo "Pull request seems to alread exist, abort."
touch "$root/.auto-release-abort"
exit 0
fi
27 changes: 27 additions & 0 deletions .github/scripts/release-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/env bash
set -e

root=$(cd "$(dirname $0)/../.." && pwd)
if [ -e "$root/.auto-release-abort" ]; then
echo "previous step triggered stop, abort"
exit 0
fi
new_sdk_version=$(cat $root/sdk_version)
branch_name="autobuild-$new_sdk_version"
osc_api_version="$(cat $root/api_version)"

if [ -z "$GH_TOKEN" ]; then
echo "GH_TOKEN is missing, abort."
exit 1
fi

# https://docs.github.com/en/free-pro-team@latest/rest/reference/pulls#create-a-pull-request
result=$(curl -s -X POST -H "Authorization: token $GH_TOKEN" -d "{\"head\":\"$branch_name\",\"base\":\"main\",\"title\":\"SDK v$new_sdk_version\",\"body\":\"Automatic build of SDK v$new_sdk_version version based on Outscale API v$osc_api_version\"}" "https://api.github.com/repos/outscale/osc-sdk-js/pulls")

errors=$(echo $result | jq .errors)

if [ "$errors" != "null" ]; then
echo $errors
echo "errors while creating pull request, abort."
exit 1
fi
18 changes: 18 additions & 0 deletions .github/scripts/release-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/env bash
set -e

root=$(cd "$(dirname $0)/../.." && pwd)
if [ -e "$root/.auto-release-abort" ]; then
echo "previous step triggered stop, abort"
exit 0
fi
new_sdk_version=$(cat $root/sdk_version)
branch_name="autobuild-$new_sdk_version"

if [ -z "$SSH_PRIVATE_KEY" ]; then
echo "SSH_PRIVATE_KEY is missing, abort."
exit 1
fi

echo "$SSH_PRIVATE_KEY" > $root/bot.key
GIT_SSH_COMMAND="ssh -i $root/bot.key" git push -f origin $branch_name
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: osc-sdk-js release build
on:
workflow_dispatch:
inputs:
api_version:
description: 'Outscale API version'
required: true

jobs:
auto-build:
environment: auto-build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with:
ref: main
- uses: actions/setup-node@v3
with:
node-version: 16.3.0
- name: make nvm available
run: |
sudo cp ~/.nvm/nvm.sh /usr/local/bin/nvm
sudo chmod +x /usr/local/bin/nvm
- name: Write Outscale API version to use
run: echo "${{ github.event.inputs.api_version }}" > api_version
- name: check for release duplicate
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: make release-check-duplicate
- name: auto-generate release
run: make release-build
- name: push release branch
run: make release-push
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
- name: create pull request
run: make release-pr
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
16 changes: 16 additions & 0 deletions .github/workflows/cred-scan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Credential Scanner

on:
pull_request:
branches:
- main

jobs:
cred-scan:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Scan credentials
uses: outscale-dev/cred-scan@main
with:
scan_path: "./"
63 changes: 63 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: pull-request

on:
pull_request:
branches: [ main ]

permissions:
pull-requests: write
contents: write

jobs:
reuse-test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Reuse specification test
run: make reuse-test
examples-test:
environment: eu-west-2
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.3.0
- name: make nvm available
run: |
sudo cp ~/.nvm/nvm.sh /usr/local/bin/nvm
sudo chmod +x /usr/local/bin/nvm
- name: Example tests
env:
OSC_ACCESS_KEY: ${{ secrets.OSC_ACCESS_KEY }}
OSC_SECRET_KEY: ${{ secrets.OSC_SECRET_KEY }}
OSC_REGION: ${{ secrets.OSC_REGION }}
run: make examples-test
regeneration-test:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.3.0
- name: make nvm available
run: |
sudo cp ~/.nvm/nvm.sh /usr/local/bin/nvm
sudo chmod +x /usr/local/bin/nvm
- name: SDK re-generation test
run: make regen-test
dependabot-auto-merge:
needs: [reuse-test, examples-test, regeneration-test]
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/[email protected]
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Auto-merge
run: gh pr merge --auto --rebase "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.sdk
osc-api
node_modules
.vscode
8 changes: 8 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
README.md
Makefile
api_version
changelog.md
CONTRIBUTING.md
sdk_version
examples
osc-api
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.2.0
12 changes: 12 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: osc-sdk-js
Upstream-Contact: Outscale support <[email protected]>
Source: https://gitlab.com/outscale/osc-sdk-js/

Files: *.md
Copyright: 2019 Outscale SAS <[email protected]>
License: CC-BY-4.0

Files: Makefile sdk_version api_version *.go .git* src/* dist/* *.yml *.yaml .patch/*.patch *.sum *.mod *.patch examples/* *.json .npmignore .nvmrc
Copyright: 2019 Outscale SAS <[email protected]>
License: BSD-3-Clause
63 changes: 63 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Needed tools

- npm
- nvm
- GNU Make

# Build process overview

Here is a quick overview of what happen when calling `make gen`:
1. cleanup existing files
2. download Outscale API description (OpenAPI format) (in /osc-api)
3. call openapi-generator in order to generate typescript-based SDK (in /src)
4. call typescipt compiler to build .js and .d.ts declaration files (in /dist)

# Hacking Outscale SDK

SDK itself is generated from Outscale's [OpenAPI description](https://github.com/outscale/osc-api) using OpenAPI Genetator.

Other contributions like examples and tests are welcome!

# Versioning

This SDK follows [semantic versioning](https://semver.org/) from the SDK perspective (not API).
Some events may trigger a major (breaking) version of the SDK:
1. OpenAPI generator introduce a new major version
2. Outscale introduce a new major version of its API

When OpenAPI generator introduce a breaking change, SDK can be generated in several versions (see corresponding branches)

# Generate SDK

1. have some tools ready: GNU make, git, docker
2. edit `api_version` file and to the latest Outscale API version
3. edit `sdk_version` file and change it according to [semantic versioning](https://semver.org/)
4. launch sdk generation by running `make gen`
5. new sdk is now generated

Under the hood:
- we get official Outscale yaml
- run openapi-generator through docker to build osc folder

# Sending a Merge Request

Content in `src` folder is generated at each release.
If you plan to make some change here, consider making a pull request in [openapi-generator project](https://github.com/OpenAPITools/openapi-generator/).

Otherwise:
- your merge request must be rebased on the corresponding major version branch.
- be sure that tests still pass by running `make test`

# How to release

1. fetch outscale and be sure to be on main branch
2. update `api_version` to the last Outscale API version
3. update `sdk_version` following [semantic versioning](https://semver.org/) logic.
5. `make gen` to re-build the sdk
6. `make test` and fix any issue
8. commit changes
9. tag version
10. push to corresponding branch
11. create github release

Note that CI should automatically detect new release on osc-api, update the SDK and push a new version.
Loading

0 comments on commit 5e35454

Please sign in to comment.