Skip to content

Update specs and client libraries #607

Update specs and client libraries

Update specs and client libraries #607

name: update-specs-and-client-libraries
run-name: Update specs and client libraries
on:
push:
branches:
- master
paths-ignore:
- "generated/artifacts/**"
pull_request:
branches:
- master
workflow_dispatch:
inputs:
update-onfido-java:
description: "Refresh onfido-java?"
required: true
default: false
type: boolean
update-onfido-node:
description: "Refresh onfido-node?"
required: true
default: false
type: boolean
update-onfido-php:
description: "Refresh onfido-php?"
required: true
default: false
type: boolean
update-onfido-python:
description: "Refresh onfido-python?"
required: true
default: false
type: boolean
update-onfido-ruby:
description: "Refresh onfido-ruby?"
required: true
default: false
type: boolean
type-of-change:
description: "Type of change?"
required: true
default: No change
type: choice
options:
- Major
- Minor
- Patch
- No change
lib-version-suffix:
description: "Add a suffix to version? (e.g `-pre`)"
type: string
override-spec-version:
description: "Override onfido-spec version? (e.g `v2.8.0-beta`)"
type: string
override-lib-version:
description: "Override client library version? (e.g `3.0.1-alpha`)"
type: string
jobs:
validate_input_specs:
name: Validate multi file specification
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate OpenAPI Specification YAML
run: ./shell/run-prettier.sh check
generate_specs_and_libraries:
name: Build single-file OpenAPI specifications and client libraries
runs-on: ubuntu-latest
outputs:
last_commit_long_sha: ${{ steps.retriever.outputs.last_commit_long_sha }}
last_commit_short_sha: ${{ steps.retriever.outputs.last_commit_short_sha }}
last_commit_tag: ${{ steps.retriever.outputs.last_commit_tag }}
java_version: ${{ steps.generator.outputs.java_okhttp_gson_version }}
typescript_axios_version: ${{ steps.generator.outputs.typescript_axios_version }}
php_version: ${{ steps.generator.outputs.php_version }}
python_version: ${{ steps.generator.outputs.python_urllib3_version }}
ruby_version: ${{ steps.generator.outputs.ruby_faraday_version }}
container:
image: openapitools/openapi-generator-cli:v7.6.0
env:
OPENAPI_GENERATOR_COMMAND: docker-entrypoint.sh
BUMP_CLIENT_LIBRARY_VERSION: ${{ inputs.type-of-change }}
CLIENT_LIBRARY_VERSION_SUFFIX: ${{ inputs.lib-version-suffix }}
OVERRIDE_CLIENT_LIBRARY_VERSION: ${{ inputs.override-lib-version }}
steps:
- name: Install pre-requisites
run: |
apt-get update
apt-get install -yqq \
gettext-base \
git \
jq
- uses: actions/checkout@v4
with:
fetch-depth: 10
fetch-tags: true
- name: Retrieve information about last commit not authored by GitHub Actions Bot and release (if any)
id: retriever
run: |
git config --global --add safe.directory $(pwd)
LAST_COMMIT_LONG_SHA=$(git rev-list --perl-regexp --author='^((?!GitHub Actions Bot).*)$' HEAD | head -n 1)
echo "last_commit_long_sha=$LAST_COMMIT_LONG_SHA" >> $GITHUB_OUTPUT
echo "last_commit_short_sha=$(git rev-parse --short $LAST_COMMIT_LONG_SHA)" >> $GITHUB_OUTPUT
echo "last_commit_tag=$(git tag --contains HEAD | grep ^v | sort | tail -n 1 || true)" >> $GITHUB_OUTPUT
- name: Validate multi-file OpenAPI specification
run: |
$OPENAPI_GENERATOR_COMMAND validate -i openapi.yaml
- name: Generate specifications and client libraries
id: generator
run: |
./shell/generate.sh
- name: Store generated artifacts and finalization scripts
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}
path: |
shell/sync-lib.sh
generated/artifacts
generators/**/exclusions.txt
update_specs:
name: Update and commit single-file OpenAPI specifications
runs-on: ubuntu-latest
needs: generate_specs_and_libraries
if: github.event_name == 'push'
environment: generation
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_ACTION_ACCESS_TOKEN }}
ref: ${{ github.ref_name }}
- uses: actions/download-artifact@v4
with:
name: artifacts-${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}
- name: Create reference OpenAPI Specification and refresh Postman Collection
run: |
npm install prettier openapi-to-postmanv2
mkdir -p generated/artifacts/{openapi-reference,postman}
./shell/patch-openapi-definition.py \
generated/artifacts/openapi/openapi.json \
generated/artifacts/openapi-reference/openapi.json
npx prettier --write \
generated/artifacts/openapi-reference/openapi.json
npx openapi2postmanv2 \
-s generated/artifacts/openapi-reference/openapi.json \
-o generated/artifacts/postman/collection.json \
-p -O folderStrategy=Tags,parametersResolution=Example
./shell/publish-postman-collection.py \
generated/artifacts/postman/collection.json \
221325-8ba05649-fd5b-40eb-976b-bc1d8ef6e328
env:
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
- name: Commit and push single-file OpenAPI specifications
run: |
if [ -z "$(git status --porcelain=v1 generated/artifacts/openapi*)" ];
then
echo "no change detected"
else
echo "changes detected"
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git add generated/artifacts/openapi* && git status
git commit -m "Single file specifications refresh (${{ needs.generate_specs_and_libraries.outputs.last_commit_short_sha }})" generated/artifacts/openapi*
git push
fi
update_client_libraries:
name: "Create PR to ${{ matrix.git_repo_id }} repository using ${{ matrix.generator }} generator (${{matrix.version}})"
runs-on: ubuntu-latest
container:
image: ${{ matrix.image }}
needs: generate_specs_and_libraries
strategy:
matrix:
include:
- generator: java/okhttp-gson
git_repo_id: onfido-java
version: ${{ needs.generate_specs_and_libraries.outputs.java_version }}
update: ${{ inputs.update-onfido-java }}
- generator: typescript-axios
git_repo_id: onfido-node
version: ${{ needs.generate_specs_and_libraries.outputs.typescript_axios_version }}
update: ${{ inputs.update-onfido-node }}
- generator: php
git_repo_id: onfido-php
image: composer:2.7
version: ${{ needs.generate_specs_and_libraries.outputs.php_version }}
update: ${{ inputs.update-onfido-php }}
- generator: python/urllib3
git_repo_id: onfido-python
image: python:3.11
extra: pipx
version: ${{ needs.generate_specs_and_libraries.outputs.python_version }}
update: ${{ inputs.update-onfido-python }}
- generator: ruby/faraday
git_repo_id: onfido-ruby
image: ruby:3.2
version: ${{ needs.generate_specs_and_libraries.outputs.ruby_version }}
update: ${{ inputs.update-onfido-ruby }}
if: github.event_name == 'workflow_dispatch'
environment: generation
steps:
- name: Install pre-requisites
run: |
if [ "$(command -v rsync)" = "" ];
then
if [ "$(command -v apt-get)" != "" ];
then
apt-get update
UPDATE_COMMAND="apt-get install -yqq"
else
UPDATE_COMMAND="apk add"
fi
${UPDATE_COMMAND} \
rsync \
npm \
jq \
pipx \
${{ matrix.extra }}
fi
- uses: actions/checkout@v4
if: ${{ matrix.update }}
with:
repository: onfido/${{ matrix.git_repo_id }}
- uses: actions/download-artifact@v4
if: ${{ matrix.update }}
with:
name: artifacts-${{ github.workflow }}-${{ github.run_id }}-${{ github.run_number }}
- name: Integrate generated code (${{ matrix.version }})
if: ${{ matrix.update }}
env:
ONFIDO_OPENAPI_SPEC_FOLDER: .
run: |
chmod +x shell/sync-lib.sh
shell/sync-lib.sh $(echo ${{ matrix.git_repo_id }} | sed 's/^onfido-//') ${{ matrix.generator }}
- name: Update release file and lint .md files as needed
if: ${{ matrix.update }}
run: |
TMP_FILE=$(mktemp)
RELEASE_FILE=.release.json
if [ ! -f $RELEASE_FILE ]
then
echo "{}" > $RELEASE_FILE
fi
SOURCE_REPO_URL=https://github.com/${{ github.repository_owner }}/onfido-openapi-spec
SOURCE_SHORT_SHA=${{ needs.generate_specs_and_libraries.outputs.last_commit_short_sha }}
SOURCE_LONG_SHA=${{ needs.generate_specs_and_libraries.outputs.last_commit_long_sha }}
SOURCE_VERSION=${{ inputs.override-spec-version }}
SOURCE_VERSION=${SOURCE_VERSION:-${{ needs.generate_specs_and_libraries.outputs.last_commit_tag }}}
jq --arg source_repo_url "$SOURCE_REPO_URL" --arg source_short_sha "$SOURCE_SHORT_SHA" \
--arg source_long_sha "$SOURCE_LONG_SHA" --arg source_version "$SOURCE_VERSION" \
'. += {"source": {"repo_url": $source_repo_url, "short_sha": $source_short_sha,
"long_sha": $source_long_sha, "version": $source_version},
"release": "v${{ matrix.version }}"}' $RELEASE_FILE >| $TMP_FILE
mv $TMP_FILE $RELEASE_FILE
npx prettier --write *.md
- name: Create Pull Request with changes after library update
uses: peter-evans/create-pull-request@v6
if: ${{ matrix.update }}
with:
token: ${{ secrets.GH_ACTION_ACCESS_TOKEN }}
commit-message: Upgrade after onfido-openapi-spec change ${{ needs.generate_specs_and_libraries.outputs.last_commit_short_sha }}
title: Refresh ${{ matrix.git_repo_id }} after onfido-openapi-spec update (${{ needs.generate_specs_and_libraries.outputs.last_commit_short_sha }})
body: |
Auto-generated PR with changes till commit ${{ github.repository_owner }}/onfido-openapi-spec@${{ needs.generate_specs_and_libraries.outputs.last_commit_long_sha }} (included)
Additional changes:
- None
labels: |
automated pr
branch: release-upgrade