-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
95 lines (84 loc) · 3.41 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Generate and publish an openapi SDK
description: |
Run our OpenApi-SDK gradle tasks to generate and publish a SDK.
See https://github.com/kronostechnologies/standards/tree/master/gradle/openapi-sdk
inputs:
generator-name:
description: |
Name of the generator supported by the openapi-sdk plugin.
See https://github.com/kronostechnologies/standards/tree/master/gradle/openapi-sdk
required: true
gradle-properties:
description: Content of a gradle.properties file that will be passed to the gradle runner.
required: false
default: ""
gradle-project-path:
description: |
Gradle project path. For example: bff.
Defaults to the root project.
required: true
default: "."
is-release:
description: true if this version is a tagged release.
required: false
default: 'false'
openapi-spec-file:
description: Optionnal openapi.yaml spec file path.
required: false
default: ""
publish:
description: true to publish this SDK once built.
required: true
default: "false"
publish-pat:
description: Personal access token used to publish. Full `repo` access is required.
required: false
working-directory:
description: Relative path under $GITHUB_WORKSPACE where the root project is located.
required: false
default: "."
runs:
using: "composite"
steps:
- name: Process gradle properties
id: properties
shell: python
env:
INPUT_GENERATOR_NAME: ${{ inputs.generator-name }}
INPUT_GRADLE_PROPERTIES: ${{ inputs.gradle-properties }}
INPUT_IS_RELEASE: ${{ inputs.is-release }}
INPUT_OPENAPI_SPEC_FILE: ${{ inputs.openapi-spec-file }}
INPUT_PUBLISH: ${{ inputs.publish }}
INPUT_PUBLISH_PAT: ${{ inputs.publish-pat }}
run: |
import os
import subprocess
task = 'build'
generator = os.environ.get('INPUT_GENERATOR_NAME').title()
properties = [ '-Pis-release=' + os.environ.get('INPUT_IS_RELEASE') ]
if os.environ.get('INPUT_PUBLISH') == 'true':
task = 'publish'
properties.append('-Pgpr.write.key=' + os.environ.get('INPUT_PUBLISH_PAT'))
subprocess.run(['git', 'config', '--global', 'user.email', '41898282+github-actions[bot]@users.noreply.github.com'])
subprocess.run(['git', 'config', '--global', 'user.name', 'github-actions[bot]'])
if os.environ.get('INPUT_OPENAPI_SPEC_FILE'):
properties.append('-PopenApiSpec=' + os.environ.get('INPUT_OPENAPI_SPEC_FILE'))
properties_input: list[str] = [line for line in (line.strip() for line in os.environ.get('INPUT_GRADLE_PROPERTIES').splitlines()) if line]
properties.extend(map(lambda x: f'-P{x}' if not x.startswith('-P') else x, properties_input))
with open(os.environ.get('GITHUB_OUTPUT'), 'a') as output_file:
output_file.write(f'task-name={task}{generator}Sdk\n')
output_file.write('gradle-properties=')
output_file.write(' '.join(properties))
output_file.write('\n')
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
gradle-version: wrapper
- name: Publish SDK
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |-
./gradlew \
-p ${{ inputs.gradle-project-path }} \
${{ steps.properties.outputs.task-name }} \
${{ steps.properties.outputs.gradle-properties }}