Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate pull requests #6

Merged
merged 26 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
permissions:
contents: read

concurrency:
group: ci-sdk-automation

jobs:
generate:
strategy:
Expand All @@ -27,10 +30,13 @@ jobs:
token: ${{ secrets.ADYEN_AUTOMATION_BOT_ACCESS_TOKEN }}
repository: Adyen/adyen-${{ matrix.project }}-api-library
path: ${{ matrix.project }}/repo
- name: Generate code for ${{ matrix.project }}
- name: Setup Gradle
uses: gradle/gradle-build-action@bd5760595778326ba7f1441bcf7e88b49de61a25 # v2.6.0
with:
arguments: ${{ matrix.project }}:services
- 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: Set PR variables
id: vars
run: |
Expand All @@ -48,3 +54,5 @@ jobs:
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
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,28 @@ For a single specific service:
./gradlew php:checkout
```

To clean up *most* (except for `repo` folders) of the generated artifacts:
To clean up spec patches:

```
./gradlew clean
./gradlew cleanSpecs
```

To clean up all the generated artifacts and repository modifications:

```
./gradlew cleanRepo
```

Typical usage during development:

```
./gradlew :dotnet:cleanRepo :dotnet:checkout
```

For Node.js, set the generator version via CLI:

```
./gradlew :node:cleanRepo :node:checkout -PopenapiGeneratorVersion=5.4.0
```

### Development
Expand All @@ -29,4 +47,10 @@ For local testing of some library:

```shell
rm -rf go/repo && ln -s ~/workspace/adyen-go-api-library go/repo
```
```

To run unit tests:

```
./gradlew :buildSrc:test
```
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import groovy.json.JsonSlurper

def uri = "https://github.com/Adyen/adyen-openapi.git"
def specsDir = "$projectDir/schema"
def checkoutDir = "$projectDir/schema/json/CheckoutService-v70.json"
def checkoutDir = "$projectDir/schema/json/CheckoutService-v71.json"

tasks.register('specs', Exec) {
group 'setup'
description 'Clone OpenAPI spec (and apply local patches).'
commandLine 'git', 'clone', '--depth', '1', uri, specsDir
outputs.dir specsDir
Expand Down Expand Up @@ -36,6 +37,7 @@ tasks.register('specs', Exec) {
}

tasks.register('pmTable', Task) {
group 'specs'
description 'Generate Checkout Payment Method Table'
dependsOn('specs')
onlyIf { file(checkoutDir).exists() }
Expand Down Expand Up @@ -75,6 +77,8 @@ tasks.register('pmTable', Task) {
}
}

tasks.register('clean', Delete) {
tasks.register('cleanSpecs', Delete) {
group 'clean'
description 'Delete OpenAPI specifications'
delete specsDir
}
16 changes: 3 additions & 13 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
// or, via Gradle Plugin Portal:
// url "https://plugins.gradle.org/m2/"
}
dependencies {
classpath "org.openapitools:openapi-generator-gradle-plugin:6.0.1"
}
}

plugins {
// Support convention plugins written in Groovy. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
id 'groovy-gradle-plugin'
}

repositories {
mavenCentral()
// Use the plugin portal to apply community plugins in convention plugins.
gradlePluginPortal()
}

dependencies {
implementation "org.openapitools:openapi-generator-gradle-plugin:6.0.1"
implementation "org.openapitools:openapi-generator-gradle-plugin:${openapiGeneratorVersion}"
testImplementation 'junit:junit:4.13'
}
1 change: 1 addition & 0 deletions buildSrc/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openapiGeneratorVersion=6.0.1
Empty file added buildSrc/settings.gradle
Empty file.
150 changes: 104 additions & 46 deletions buildSrc/src/main/groovy/adyen.sdk-automation-conventions.gradle
Original file line number Diff line number Diff line change
@@ -1,67 +1,77 @@
plugins {
id 'org.openapi.generator'
}

import com.adyen.sdk.Service
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import org.openapitools.generator.gradle.plugin.tasks.GenerateTask

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

List<Service> services = [
// Payments
new Service(name: 'Checkout', version: 71),
new Service(name: 'Payout', version: 68),
new Service(name: 'Recurring', version: 68, small: true),
new Service(name: 'BinLookup', version: 54, small: true),
// Point of Sale
new Service(name: 'PosTerminalManagement', spec: 'TfmAPIService', version: 1, small: true),
// Management
new Service(name: 'Management', version: 3),
new Service(name: 'BalanceControl', version: 1, small: true),
// Adyen for Platforms
new Service(name: 'LegalEntityManagement', spec: 'LegalEntityService', version: 3),
new Service(name: 'BalancePlatform', version: 2),
new Service(name: 'Transfers', spec: 'TransferService', version: 4),
new Service(name: 'DataProtection', version: 1, small: true),
// Classic Payments
new Service(name: 'Payment', version: 68, small: true),
// Others
new Service(name: 'StoredValue', version: 46, small: true),
new Service(name: 'Disputes', spec: 'DisputeService', version: 30, small: true),
// Webhooks
new Service(name: 'ConfigurationWebhooks', spec: 'BalancePlatformConfigurationNotification', version: 1),
new Service(name: 'AcsWebhooks', spec: 'BalancePlatformAcsNotification', version: 1),
new Service(name: 'ReportWebhooks', spec: 'BalancePlatformReportNotification', version: 1),
new Service(name: 'TransferWebhooks', spec: 'BalancePlatformTransferNotification', version: 4),
new Service(name: 'TransactionWebhooks', spec: 'BalancePlatformTransactionNotification', version: 4),
new Service(name: 'ManagementWebhooks', spec: 'ManagementNotificationService', version: 3),
]

ext {
generator = project.name
templates = 'templates'
services = [
// Payments
new Service(name: 'Checkout', version: 71),
new Service(name: 'Payout', version: 68),
new Service(name: 'Recurring', version: 68),
new Service(name: 'BinLookup', version: 54),
// Point of Sale
new Service(name: 'POSTerminalManagement', spec: 'TfmAPIService', version: 1),
// Management
new Service(name: 'Management', version: 3),
new Service(name: 'BalanceControl', version: 1),
// Adyen for Platforms
new Service(name: 'LegalEntityManagement', spec: 'LegalEntityService', version: 3),
new Service(name: 'BalancePlatform', version: 2),
new Service(name: 'Transfers', spec: 'TransferService', version: 4),
new Service(name: 'DataProtection', version: 1),
// Classic Payments
new Service(name: 'Payment', version: 68),
// Others
new Service(name: 'StoredValue', version: 46),
// Webhooks
new Service(name: 'ConfigurationWebhook', spec: 'BalancePlatformConfigurationNotification', version: 1),
new Service(name: 'ACSWebhook', spec: 'BalancePlatformAcsNotification', version: 1),
new Service(name: 'ReportWebhook', spec: 'BalancePlatformReportNotification', version: 1),
new Service(name: 'TransferWebhook', spec: 'BalancePlatformTransferNotification', version: 4),
new Service(name: 'TransactionWebhook', spec: 'BalancePlatformTransactionNotification', version: 4),
new Service(name: 'ManagementWebhook', spec: 'ManagementNotificationService', version: 3),
]
serviceName = ''
}

class Service {
String name, spec
int version

String getSpec() { spec ?: "${name}Service" }

String getId() { name.toLowerCase() }
removeTags = true
setProperty('services', services)
smallServices = services.findAll { it.small }
serviceNaming = services.collectEntries { [it.id, it.name] }
serviceNamingCamel = services.collectEntries {
[it.id, it.name.substring(0, 1).toLowerCase() + it.name.substring(1)]
}
}

// Generate a full client for each service
project.ext.services.each { Service svc ->
services.each { Service svc ->
def generate = tasks.register("generate$svc.name", GenerateTask) {
group 'generate'
description "Generate a $project.name client for $svc.name."
dependsOn 'clone'
dependsOn 'cloneRepo'
dependsOn ':specs'

// Current service being processed
ext.serviceId = svc.id
project.ext.serviceName = svc.name

generatorName.set(project.ext.generator as String)
inputSpec.set("$rootDir/schema/json/${svc.spec}-v${svc.version}.json")
inputSpec.set("$rootDir/schema/json/${svc.filename}")
outputDir.set("$buildDir/services/${svc.id}")
templateDir.set("$projectDir/repo/$project.ext.templates")
engine.set('mustache')
validateSpec.set(false)
skipValidateSpec.set(true)
reservedWordsMappings.set([
Expand All @@ -70,31 +80,41 @@ project.ext.services.each { Service svc ->
additionalProperties.set([
'serviceName': project.ext.serviceName,
])
globalProperties.set([
'modelDocs' : 'false',
'modelTests': 'false'
])

if (project.ext.has('configFile')) {
configFile.set("$projectDir/repo/$project.ext.configFile")
}
}

tasks.register(svc.id) {
group 'service'
description "Base task for $svc.name."
dependsOn generate
}
}

tasks.register('services') {
description 'Generate code for multiple services.'
dependsOn project.ext.services.collect { it.id }
dependsOn services.collect { it.id }
}

tasks.named('generateCheckout', GenerateTask) {
if (project.name == 'node') {
// generator v5 does not support inlineSchemaNameMappings
return
}
inlineSchemaNameMappings.set([
'PaymentRequest_paymentMethod' : 'CheckoutPaymentMethod',
'DonationPaymentRequest_paymentMethod': 'DonationPaymentMethod',
])
}

tasks.register('clone', Exec) {
tasks.register('cloneRepo', Exec) {
group 'setup'
def uri = "https://github.com/Adyen/adyen-$project.name-api-library.git"
def dest = 'repo'
description "Clone this project's repository."
Expand All @@ -109,13 +129,51 @@ tasks.withType(GenerateTask).configureEach {
outputs.cacheIf { false }
}

tasks.register('clean', Delete) {
delete buildDir
tasks.register('cleanRepo', Delete) {
group 'clean'
description 'Clean this project state'
delete layout.buildDirectory
doLast {
exec {
// cleanTracked: discard changes to existing files
commandLine 'git', 'checkout', '.'
workingDir 'repo'
}
exec {
// cleanUntracked: discard unknown files
commandLine 'git', 'clean', '-f', '-d'
workingDir 'repo'
}
}
}

tasks.register('addPMTable', Copy) {
dependsOn("clone")
dependsOn("cloneRepo")
dependsOn(":pmTable")
from(rootProject.file('PaymentMethodOverview.md'))
into layout.projectDirectory.dir("repo")
}
}

project.ext.smallServices.each { Service svc ->
def ungroup = tasks.register("ungroup${svc.name}") {
group 'specs'
description "Remove tags from ${svc.name}"
dependsOn ':specs'
// The `removeTags` setting only works in isolation (e.g. CI). Locally, specs are shared between all projects.
onlyIf { project.ext.removeTags }
doLast {
def specFile = file("$rootDir/schema/json/${svc.filename}")
def json = new JsonSlurper().parse(specFile)

json["paths"].each { Map.Entry endpoint ->
endpoint.value.each { Map.Entry httpMethod ->
httpMethod.value.remove('tags')
}
}

specFile.text = JsonOutput.prettyPrint(JsonOutput.toJson(json))
}
}

tasks.named("generate$svc.name") { dependsOn ungroup }
}
15 changes: 15 additions & 0 deletions buildSrc/src/main/groovy/com/adyen/sdk/Service.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.adyen.sdk

class Service {
String name, spec
int version
boolean small

String getId() { name.toLowerCase() }

String getSpec() { spec ?: "${name}Service" }

String getFilename() { "${getSpec()}-v${version}.json" }

boolean isWebhook() { name.endsWith('Webhooks') }
}
Loading