Update SDKs #254
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update SDKs | |
on: | |
workflow_dispatch: | |
push: | |
branches: [ "main" ] | |
paths-ignore: | |
- '**/README.md' | |
- README.md | |
- LICENSE | |
permissions: | |
contents: read | |
concurrency: | |
group: ci-sdk-automation | |
jobs: | |
generate: | |
strategy: | |
matrix: | |
project: [ go, php, java, node, dotnet, python, ruby ] | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '11' | |
distribution: 'temurin' | |
- name: Clone ${{ matrix.project }} repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.ADYEN_AUTOMATION_BOT_ACCESS_TOKEN }} | |
repository: Adyen/adyen-${{ matrix.project }}-api-library | |
path: ${{ matrix.project }}/repo | |
- name: Setup Gradle | |
uses: gradle/gradle-build-action@v3 | |
- name: Override properties | |
if: matrix.project == 'node' | |
run: cp ${{ matrix.project }}/gradle.properties buildSrc | |
- name: Generate code for ${{ matrix.project }} | |
run: ./gradlew ${{ matrix.project }}:services | |
- name: OpenAPI diffs | |
id: openapi-diffs | |
run: | | |
cd schema | |
COMMIT_HASH=$(git rev-parse HEAD) | |
COMMIT_HASH_BEFORE=$(git rev-parse HEAD^) | |
echo "Generate OpenAPI diff between commits [$COMMIT_HASH_BEFORE, $COMMIT_HASH]" | |
# save commit that has triggered the OpenAPI generation | |
echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV | |
# Fetch files modified by the commit | |
files=$(git diff-tree --no-commit-id --name-only -r $COMMIT_HASH) | |
for file in $files; do | |
if [[ $file == *.json ]]; then | |
# get filename | |
filename="${file%.*}" | |
# checkout file before the commit | |
temp_before_name="${filename}_before.json" | |
git show $COMMIT_HASH_BEFORE:$file > $temp_before_name | |
# checkout file after the commit | |
temp_after_name="${filename}_after.json" | |
git show $COMMIT_HASH:$file > $temp_after_name | |
docker run -v "$(pwd):/specs" --rm -t tufin/oasdiff diff \ | |
-f markup \ | |
/specs/$temp_before_name \ | |
/specs/$temp_after_name \ | |
>> "oas_diff_${filename//\//_}.md" | |
echo "$filename ✅" | |
fi | |
done | |
# upload generated openapi-diff markdowns as artifacts | |
- uses: actions/upload-artifact@v4 | |
if: matrix.project == 'java' # upload artifacts once | |
id: artifact-upload-step | |
with: | |
name: openapi-diff files (commit ${{ env.COMMIT_HASH }}) | |
path: | | |
schema/oas_diff_*.md | |
- name: Set PR variables | |
id: vars | |
run: | | |
cd schema | |
echo pr_title="Update all services" >> "$GITHUB_OUTPUT" | |
echo pr_body="OpenAPI spec or templates produced changes on $(date +%d-%m-%Y) \ | |
by [commit](https://github.com/Adyen/adyen-openapi/commit/$(git rev-parse HEAD)). \ | |
Download [OpenAPI diffs](${{ steps.artifact-upload-step.outputs.artifact-url }}) to view the changes." >> "$GITHUB_OUTPUT" | |
- name: Create Pull Request | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
path: ${{ matrix.project }}/repo | |
token: ${{ secrets.ADYEN_AUTOMATION_BOT_ACCESS_TOKEN }} | |
committer: ${{ secrets.ADYEN_AUTOMATION_BOT_EMAIL }} | |
author: ${{ secrets.ADYEN_AUTOMATION_BOT_EMAIL }} | |
branch: sdk-automation/models | |
title: ${{ steps.vars.outputs.pr_title }} | |
body: ${{ steps.vars.outputs.pr_body }} | |
commit-message: | | |
${{ contains(fromJSON('["go", "php", "node"]'), matrix.project) && '[reformat]' }}[adyen-sdk-automation] automated change |