Skip to content

Update specs and client libraries #257

Update specs and client libraries

Update specs and client libraries #257

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:
type-of-change:
description: "Type of change?"
required: true
default: No change
type: choice
options:
- Major
- Minor
- Patch
- No change
update-onfido-java:
description: "Update onfido-java?"
required: true
default: false
type: boolean
update-onfido-node:
description: "Update onfido-node?"
required: true
default: false
type: boolean
update-onfido-php:
description: "Update onfido-php?"
required: true
default: false
type: boolean
update-onfido-python:
description: "Update onfido-python?"
required: true
default: false
type: boolean
update-onfido-ruby:
description: "Update onfido-ruby?"
required: true
default: false
type: boolean
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 }}
java_version: ${{ steps.generator.outputs.java_version }}
typescript_axios_version: ${{ steps.generator.outputs.typescript_axios_version }}
php_version: ${{ steps.generator.outputs.php_version }}
python_version: ${{ steps.generator.outputs.python_version }}
ruby_version: ${{ steps.generator.outputs.ruby_version }}
container:
image: openapitools/openapi-generator-cli:v7.5.0
env:
OPENAPI_GENERATOR_COMMAND: docker-entrypoint.sh
BUMP_CLIENT_LIBRARY_VERSION: ${{ inputs.type-of-change }}
steps:
- name: Install pre-requisites
run: |
apt-get update
apt-get install -yqq \
gettext-base \
git \
jq \
pipx
- uses: actions/checkout@v4
with:
fetch-depth: 10
- name: Retrieve information about last commit not authored by GitHub Actions Bot
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
- 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: |
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 pull request to ${{ matrix.git_repo_id }} repository with ${{ matrix.generator }}:${{matrix.version}}"
runs-on: ubuntu-latest
needs: generate_specs_and_libraries
strategy:
matrix:
include:
- generator: java/okhttp-gson
git_repo_id: onfido-java
preCommit: |
mvn -B package --file pom.xml clean -Dmaven.test.skip
version: ${{ needs.generate_specs_and_libraries.outputs.java_version }}
update: ${{ inputs.update-onfido-java }}
- generator: typescript-axios
git_repo_id: onfido-node
preCommit: |
npx prettier --write package.json
npm install
version: ${{ needs.generate_specs_and_libraries.outputs.typescript_axios_version }}
update: ${{ inputs.update-onfido-node || true }}
- generator: php
git_repo_id: onfido-php
preCommit: |
composer update --lock
version: ${{ needs.generate_specs_and_libraries.outputs.php_version }}
update: ${{ inputs.update-onfido-php }}
- generator: python/urllib3
git_repo_id: onfido-python
preCommit: |
pipx install poetry==1.8
poetry lock
version: ${{ needs.generate_specs_and_libraries.outputs.python_version }}
update: ${{ inputs.update-onfido-python }}
- generator: ruby/faraday
git_repo_id: onfido-ruby
preCommit: |
bundle lock --update
version: ${{ needs.generate_specs_and_libraries.outputs.ruby_version }}
update: ${{ inputs.update-onfido-ruby}}
# if: github.event_name == 'workflow_dispatch'
environment: generation
steps:
- 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 }}
run: |
rsync -r --delete-after --exclude='/.git*' --exclude='/CHANGELOG*' \
--exclude='/.openapi-generator-ignore' --exclude='/.openapi-generator/FILES' \
--exclude-from=generators/${{ matrix.generator }}/exclusions.txt \
generated/artifacts/${{ matrix.generator }}/ .
- name: Run pre-commit script
continue-on-error: true
if: ${{ matrix.update }}
run: |
${{ matrix.preCommit }}
- name: Update CHANGELOG and lint .md files as needed
if: ${{ matrix.update }}
run: |
if [ "$(git status --porcelain=v1 | wc -l | sed -e 's/^[[:space:]]*//')" != "" ];
then
if [ -f CHANGELOG ];
then
git mv CHANGELOG CHANGELOG.md
fi
if [ -f CHANGELOG.md ] && [ -z "$(grep '${{ matrix.version }} ' CHANGELOG.md)" ];
then
TMP_FILE=$(mktemp)
( echo "# Changelog"; echo;
echo "## v${{ matrix.version }} `date +'%dth %B %Y' | sed -E 's/^([2,3]?)1th/\11st/;s/^([2]?)2th/\12nd/;s/^([2]?)3th/\13rd/'`";
grep -v "^# Changelog" CHANGELOG.md ) >| $TMP_FILE
mv $TMP_FILE CHANGELOG.md
fi
npx prettier --write *.md
fi
- name: Create Pull Request with changes after library update
uses: peter-evans/create-pull-request@v6
if: ${{ matrix.update }}
with:
token: whatever
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