Skip to content

Commit bdec255

Browse files
authored
Merge pull request #10869 from swagger-api/github_actions_config
added actions for dotnet, java and js generators
2 parents 3eab3a6 + 367990b commit bdec255

15 files changed

+1471
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: 'DotNetBuild'
2+
description: 'build dotnet project'
3+
inputs:
4+
path:
5+
description: 'project root path'
6+
required: true
7+
job-name:
8+
description: 'Job name'
9+
required: true
10+
outputs:
11+
logs:
12+
description: "logs"
13+
value: ${{ steps.build.outputs.logs }}
14+
path:
15+
description: "output path"
16+
value: ${{ steps.build.outputs.path }}
17+
runs:
18+
using: "composite"
19+
steps:
20+
- id: build
21+
name: build
22+
run: |
23+
logfile=${{ inputs.job-name }}.log
24+
echo "::set-output name=logs::$(echo $logfile)"
25+
echo "::set-output name=path::$(echo generated/${{ inputs.job-name }})"
26+
echo -e "\n****** dotnet build ******\n" >> $logfile
27+
curdir=$(pwd)
28+
cd ${{ inputs.path }}
29+
echo -e "\n****** dotnet build ******\n" >> $curdir/$logfile
30+
dotnet restore src/IO.Swagger/ | tee --append $curdir/$logfile
31+
dotnet build src/IO.Swagger/ | tee --append $curdir/$logfile
32+
cd ${curdir}
33+
shell: bash

.github/actions/generate/action.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: 'Generate'
2+
description: 'codegen generate'
3+
inputs:
4+
spec-url:
5+
description: 'Url of the openapi definition'
6+
required: true
7+
default: 'https://petstore3.swagger.io/api/v3/openapi.json'
8+
language:
9+
description: 'Language to generate'
10+
required: true
11+
job-name:
12+
description: 'Job name'
13+
required: true
14+
options:
15+
description: 'Language Options'
16+
required: false
17+
default: ""
18+
outputs:
19+
logs:
20+
description: "logs"
21+
value: ${{ steps.generate.outputs.logs }}
22+
path:
23+
description: "output path"
24+
value: ${{ steps.generate.outputs.path }}
25+
runs:
26+
using: "composite"
27+
steps:
28+
- id: generate
29+
name: generate
30+
run: |
31+
logfile=${{ inputs.job-name }}.log
32+
echo "::set-output name=logs::$(echo $logfile)"
33+
chmod +x ${{ github.action_path }}/generate.sh
34+
echo -e "\n****** generate ******\n" > $logfile
35+
${{ github.action_path }}/generate.sh ${{ inputs.language }} ${{ inputs.job-name }} ${{ inputs.spec-url }} ${{ inputs.options }} >> $logfile
36+
echo "::set-output name=path::$(echo generated/${{ inputs.job-name }})"
37+
shell: bash

.github/actions/generate/generate.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
16+
executable="swagger-codegen-cli.jar"
17+
18+
LANG=$1
19+
20+
JOB_NAME=$2
21+
if [ -z "$JOB_NAME" ]
22+
then
23+
JOB_NAME=$LANG
24+
fi
25+
26+
SPEC_URL=$3
27+
if [[ $SPEC_URL == "null" ]];
28+
then
29+
SPEC_URL="https://petstore3.swagger.io/api/v3/openapi.json"
30+
fi
31+
32+
shift;
33+
shift;
34+
shift;
35+
36+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=$SCRIPT/logback.xml"
37+
ags="generate -i ${SPEC_URL} -l ${LANG} -o generated/${JOB_NAME} $@"
38+
39+
java $JAVA_OPTS -jar $executable $ags
40+
41+

.github/actions/generate/logback.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
6+
</encoder>
7+
</appender>
8+
<logger name="io.swagger" level="info"/>
9+
<root level="error">
10+
<appender-ref ref="STDOUT"/>
11+
</root>
12+
</configuration>

.github/actions/javabuild/action.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: 'JavaBuild'
2+
description: 'build java with maven'
3+
inputs:
4+
path:
5+
description: 'project root path'
6+
required: true
7+
job-name:
8+
description: 'Job name'
9+
required: true
10+
outputs:
11+
logs:
12+
description: "logs"
13+
value: ${{ steps.build.outputs.logs }}
14+
path:
15+
description: "output path"
16+
value: ${{ steps.build.outputs.path }}
17+
runs:
18+
using: "composite"
19+
steps:
20+
- id: build
21+
name: build
22+
run: |
23+
logfile=${{ inputs.job-name }}.log
24+
echo "::set-output name=logs::$(echo $logfile)"
25+
echo "::set-output name=path::$(echo generated/${{ inputs.job-name }})"
26+
echo -e "\n****** mvn clean package ******\n" >> $logfile
27+
curdir=$(pwd)
28+
cd ${{ inputs.path }}
29+
mvn clean package | tee --append $curdir/$logfile
30+
cd ${curdir}
31+
shell: bash

.github/actions/jsbuild/action.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: 'JsBuild'
2+
description: 'build js with npm'
3+
inputs:
4+
path:
5+
description: 'project root path'
6+
required: true
7+
job-name:
8+
description: 'Job name'
9+
required: true
10+
outputs:
11+
logs:
12+
description: "logs"
13+
value: ${{ steps.build.outputs.logs }}
14+
path:
15+
description: "output path"
16+
value: ${{ steps.build.outputs.path }}
17+
runs:
18+
using: "composite"
19+
steps:
20+
- id: build
21+
name: build
22+
run: |
23+
logfile=${{ inputs.job-name }}.log
24+
echo "::set-output name=logs::$(echo $logfile)"
25+
echo "::set-output name=path::$(echo generated/${{ inputs.job-name }})"
26+
echo -e "\n****** npm i ******\n" >> $logfile
27+
curdir=$(pwd)
28+
cd ${{ inputs.path }}
29+
npm i 2>&1 | tee --append $curdir/$logfile
30+
echo -e "\n****** npm run test ******\n" >> $curdir/$logfile
31+
npm run test 2>&1 | tee --append $curdir/$logfile
32+
cd ${curdir}
33+
shell: bash
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: 'Python Build'
2+
description: 'build python project'
3+
inputs:
4+
path:
5+
description: 'project root path'
6+
required: true
7+
job-name:
8+
description: 'Job name'
9+
required: true
10+
outputs:
11+
logs:
12+
description: "logs"
13+
value: ${{ steps.build.outputs.logs }}
14+
path:
15+
description: "output path"
16+
value: ${{ steps.build.outputs.path }}
17+
runs:
18+
using: "composite"
19+
steps:
20+
- id: build
21+
name: build
22+
run: |
23+
logfile=${{ inputs.job-name }}.log
24+
echo "::set-output name=logs::$(echo $logfile)"
25+
echo "::set-output name=path::$(echo generated/${{ inputs.job-name }})"
26+
echo -e "\n****** python ******\n" >> $logfile
27+
curdir=$(pwd)
28+
cd ${{ inputs.path }}
29+
echo -e "\n****** python setup and build ******\n" >> $curdir/$logfile
30+
python3 setup.py install --user | tee --append $curdir/$logfile
31+
pip3 install nose2 --user
32+
python3 -m nose2 | tee --append $curdir/$logfile
33+
cd ${curdir}
34+
shell: bash
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
name: Test Framework DotNet
2+
3+
on:
4+
# execute on demand
5+
workflow_dispatch:
6+
branches: ["master", "test-framework", "3.0.0"]
7+
inputs:
8+
language:
9+
description: 'Language'
10+
required: true
11+
specUrl:
12+
description: 'URL of OpenAPI doc'
13+
required: true
14+
default: "https://petstore3.swagger.io/api/v3/openapi.json"
15+
options:
16+
description: 'language options'
17+
default: ''
18+
jobName:
19+
description: 'job name'
20+
required: true
21+
22+
jobs:
23+
24+
# builds codegen cli and uploads its artifact
25+
build-codegen:
26+
27+
runs-on: ubuntu-latest
28+
29+
strategy:
30+
matrix:
31+
java: [ 8 ]
32+
33+
steps:
34+
- uses: actions/checkout@v2
35+
- uses: actions/setup-java@v1
36+
with:
37+
java-version: ${{ matrix.java }}
38+
- name: build codegen
39+
run: |
40+
mvn -q -B package -DskipTests
41+
- name: prepare codegen cli
42+
run: mkdir codegen-cli && cp modules/swagger-codegen-cli/target/swagger-codegen-cli.jar codegen-cli
43+
- name: upload codegen cli
44+
uses: actions/upload-artifact@v2
45+
with:
46+
name: codegen-cli
47+
path: codegen-cli
48+
49+
generate:
50+
51+
needs: build-codegen
52+
53+
runs-on: ubuntu-latest
54+
55+
strategy:
56+
matrix:
57+
java: [ 8 ]
58+
59+
60+
outputs:
61+
generate_outcome: ${{ steps.outcome.outputs.generate_outcome }}
62+
63+
steps:
64+
- uses: actions/checkout@v2
65+
- uses: actions/setup-java@v1
66+
with:
67+
java-version: ${{ matrix.java }}
68+
- name: Download codegen cli
69+
uses: actions/download-artifact@v2
70+
with:
71+
name: codegen-cli
72+
- name: generate
73+
id: generate
74+
continue-on-error: true
75+
uses: ./.github/actions/generate
76+
with:
77+
language: $LANGUAGE
78+
job-name: ${JOB_NAME}
79+
spec-url: ${SPEC_URL}
80+
options: $OPTIONS
81+
- id: outcome
82+
run: |
83+
echo "::set-output name=generate_outcome::${{ steps.generate.outcome }}"
84+
echo ${{ steps.generate.outcome }} > generate_outcome_${{ env.JOB_NAME }}
85+
- name: upload generate outcome
86+
uses: actions/upload-artifact@v2
87+
with:
88+
name: ${{ env.JOB_NAME }}generate_outcome
89+
path: generate_outcome_${{ env.JOB_NAME }}
90+
- name: upload generate logs
91+
uses: actions/upload-artifact@v2
92+
with:
93+
name: ${{ env.JOB_NAME }}generate_logs
94+
path: ${{ steps.generate.outputs.logs }}
95+
- name: upload generated code
96+
if: contains(steps.generate.outcome, 'success')
97+
uses: actions/upload-artifact@v2
98+
with:
99+
name: ${{ env.JOB_NAME }}generated
100+
path: ${{ steps.generate.outputs.path }}
101+
102+
env:
103+
LANGUAGE: ${{ github.event.inputs.language }}
104+
JOB_NAME: ${{ github.event.inputs.jobName }}
105+
OPTIONS: ${{ github.event.inputs.options }}
106+
SPEC_URL: ${{ github.event.inputs.specUrl }}
107+
108+
build:
109+
110+
needs: generate
111+
if: contains(needs.generate.outputs.generate_outcome, 'success')
112+
runs-on: ubuntu-latest
113+
114+
strategy:
115+
matrix:
116+
dotnet-version: [3.1.x]
117+
118+
steps:
119+
- uses: actions/checkout@v2
120+
- name: Download artifacts
121+
uses: actions/download-artifact@v2
122+
with:
123+
name: ${{ env.JOB_NAME }}generated
124+
path: generated/${{ env.JOB_NAME }}
125+
- name: Download logs
126+
uses: actions/download-artifact@v2
127+
with:
128+
name: ${{ env.JOB_NAME }}generate_logs
129+
- name: Set up DotNet 3.1.x
130+
uses: actions/setup-dotnet@v1
131+
with:
132+
dotnet-version: ${{ matrix.dotnet-version }}
133+
- name: build
134+
id: build
135+
uses: ./.github/actions/dotnetbuild
136+
continue-on-error: true
137+
with:
138+
path: generated/${{ env.JOB_NAME }}
139+
job-name: ${{ env.JOB_NAME }}
140+
- id: outcome
141+
run: |
142+
echo "::set-output name=build_outcome::${{ steps.build.outcome }}"
143+
echo ${{ steps.build.outcome }} > ${{ env.JOB_NAME }}build_outcome
144+
- name: upload build outcome
145+
uses: actions/upload-artifact@v2
146+
with:
147+
name: ${{ env.JOB_NAME }}build_outcome
148+
path: ${{ env.JOB_NAME }}build_outcome
149+
- name: upload logs
150+
uses: actions/upload-artifact@v2
151+
with:
152+
name: ${{ env.JOB_NAME }}logs
153+
path: ${{ steps.build.outputs.logs }}
154+
env:
155+
LANGUAGE: ${{ github.event.inputs.language }}
156+
JOB_NAME: ${{ github.event.inputs.jobName }}
157+
OPTIONS: ${{ github.event.inputs.options }}
158+
SPEC_URL: ${{ github.event.inputs.specUrl }}

0 commit comments

Comments
 (0)