Skip to content

Generate PRs to client libraries repositories #96

Generate PRs to client libraries repositories

Generate PRs to client libraries repositories #96

name: client-libraries-pull-request
run-name: Generate PRs to client libraries repositories
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: Patch
type: choice
options:
- Major
- Minor
- Patch
update-onfido-node:
description: 'Update onfido-node?'
required: true
default: false
type: boolean
env:
GITHUB_SHA: env.GITHUB_SHA
jobs:
build_client_libraries:
name: Build client libraries
runs-on: ubuntu-latest
outputs:
typescript_axios_version: ${{ steps.generator.outputs.typescript_axios_version }}
container:
image: openapitools/openapi-generator-cli:v7.3.0
env:
OPENAPI_GENERATOR_COMMAND: docker-entrypoint.sh
BUMP_CLIENT_LIBRARY_VERSION: ${{ inputs.type-of-change || 'Minor' }}
steps:
- uses: actions/checkout@v4
- name: Install pre-requisites
run: |
apt-get update
apt-get install -yqq \
gettext-base \
git \
jq
- name: Regenerate 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
!generated/artifacts/openapi*
!generators/openapi*
create_pr:
name: "${{ matrix.generator }}: commit and create pull request to ${{ matrix.git_repo_id }} repository (update: ${{matrix.update}})"
runs-on: ubuntu-latest
needs:
- build_client_libraries
strategy:
matrix:
include:
- generator: typescript-axios
git_repo_id: onfido-node
preCommit: npm install
version: ${{ needs.build_client_libraries.outputs.typescript_axios_version }}
update: ${{ inputs.update-onfido-node || true }}
if: github.event_name == 'workflow_dispatch'
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 }}
id: generator
run: |
rsync -r --delete-after --exclude='/.git*' \
--exclude-from=generators/${{ matrix.generator }}/exclusions.txt \
generated/artifacts/${{ matrix.generator }}/ .
${{ matrix.preCommit }}
echo any_change=$(git status --porcelain=v1 | wc -l | sed -e 's/^[[:space:]]*//') >> $GITHUB_OUTPUT
- name: Create Pull Request with changes after library update
uses: peter-evans/create-pull-request@v6
if: ${{ matrix.update && steps.generator.outputs.any_change }}
with:
token: ${{ secrets.GH_ACTION_ACCESS_TOKEN }}
commit-message: Client library upgrade after OpenAPI change (${{ matrix.version }})
title: Client library upgrade after OpenAPI change (${{ matrix.version }})
body: |
- Dependency updates
Auto-generated after change: ${{ github.sha }}
branch: refresh-library