Skip to content

Commit

Permalink
Merge pull request #10869 from swagger-api/github_actions_config
Browse files Browse the repository at this point in the history
added actions for dotnet, java and js generators
  • Loading branch information
HugoMario authored Jan 21, 2021
2 parents 3eab3a6 + 367990b commit bdec255
Show file tree
Hide file tree
Showing 15 changed files with 1,471 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/actions/dotnetbuild/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'DotNetBuild'
description: 'build dotnet project'
inputs:
path:
description: 'project root path'
required: true
job-name:
description: 'Job name'
required: true
outputs:
logs:
description: "logs"
value: ${{ steps.build.outputs.logs }}
path:
description: "output path"
value: ${{ steps.build.outputs.path }}
runs:
using: "composite"
steps:
- id: build
name: build
run: |
logfile=${{ inputs.job-name }}.log
echo "::set-output name=logs::$(echo $logfile)"
echo "::set-output name=path::$(echo generated/${{ inputs.job-name }})"
echo -e "\n****** dotnet build ******\n" >> $logfile
curdir=$(pwd)
cd ${{ inputs.path }}
echo -e "\n****** dotnet build ******\n" >> $curdir/$logfile
dotnet restore src/IO.Swagger/ | tee --append $curdir/$logfile
dotnet build src/IO.Swagger/ | tee --append $curdir/$logfile
cd ${curdir}
shell: bash
37 changes: 37 additions & 0 deletions .github/actions/generate/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: 'Generate'
description: 'codegen generate'
inputs:
spec-url:
description: 'Url of the openapi definition'
required: true
default: 'https://petstore3.swagger.io/api/v3/openapi.json'
language:
description: 'Language to generate'
required: true
job-name:
description: 'Job name'
required: true
options:
description: 'Language Options'
required: false
default: ""
outputs:
logs:
description: "logs"
value: ${{ steps.generate.outputs.logs }}
path:
description: "output path"
value: ${{ steps.generate.outputs.path }}
runs:
using: "composite"
steps:
- id: generate
name: generate
run: |
logfile=${{ inputs.job-name }}.log
echo "::set-output name=logs::$(echo $logfile)"
chmod +x ${{ github.action_path }}/generate.sh
echo -e "\n****** generate ******\n" > $logfile
${{ github.action_path }}/generate.sh ${{ inputs.language }} ${{ inputs.job-name }} ${{ inputs.spec-url }} ${{ inputs.options }} >> $logfile
echo "::set-output name=path::$(echo generated/${{ inputs.job-name }})"
shell: bash
41 changes: 41 additions & 0 deletions .github/actions/generate/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh

SCRIPT="$0"

while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done


executable="swagger-codegen-cli.jar"

LANG=$1

JOB_NAME=$2
if [ -z "$JOB_NAME" ]
then
JOB_NAME=$LANG
fi

SPEC_URL=$3
if [[ $SPEC_URL == "null" ]];
then
SPEC_URL="https://petstore3.swagger.io/api/v3/openapi.json"
fi

shift;
shift;
shift;

export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -Dlogback.configurationFile=$SCRIPT/logback.xml"
ags="generate -i ${SPEC_URL} -l ${LANG} -o generated/${JOB_NAME} $@"

java $JAVA_OPTS -jar $executable $ags


12 changes: 12 additions & 0 deletions .github/actions/generate/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<logger name="io.swagger" level="info"/>
<root level="error">
<appender-ref ref="STDOUT"/>
</root>
</configuration>
31 changes: 31 additions & 0 deletions .github/actions/javabuild/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: 'JavaBuild'
description: 'build java with maven'
inputs:
path:
description: 'project root path'
required: true
job-name:
description: 'Job name'
required: true
outputs:
logs:
description: "logs"
value: ${{ steps.build.outputs.logs }}
path:
description: "output path"
value: ${{ steps.build.outputs.path }}
runs:
using: "composite"
steps:
- id: build
name: build
run: |
logfile=${{ inputs.job-name }}.log
echo "::set-output name=logs::$(echo $logfile)"
echo "::set-output name=path::$(echo generated/${{ inputs.job-name }})"
echo -e "\n****** mvn clean package ******\n" >> $logfile
curdir=$(pwd)
cd ${{ inputs.path }}
mvn clean package | tee --append $curdir/$logfile
cd ${curdir}
shell: bash
33 changes: 33 additions & 0 deletions .github/actions/jsbuild/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: 'JsBuild'
description: 'build js with npm'
inputs:
path:
description: 'project root path'
required: true
job-name:
description: 'Job name'
required: true
outputs:
logs:
description: "logs"
value: ${{ steps.build.outputs.logs }}
path:
description: "output path"
value: ${{ steps.build.outputs.path }}
runs:
using: "composite"
steps:
- id: build
name: build
run: |
logfile=${{ inputs.job-name }}.log
echo "::set-output name=logs::$(echo $logfile)"
echo "::set-output name=path::$(echo generated/${{ inputs.job-name }})"
echo -e "\n****** npm i ******\n" >> $logfile
curdir=$(pwd)
cd ${{ inputs.path }}
npm i 2>&1 | tee --append $curdir/$logfile
echo -e "\n****** npm run test ******\n" >> $curdir/$logfile
npm run test 2>&1 | tee --append $curdir/$logfile
cd ${curdir}
shell: bash
34 changes: 34 additions & 0 deletions .github/actions/pythonbuild/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Python Build'
description: 'build python project'
inputs:
path:
description: 'project root path'
required: true
job-name:
description: 'Job name'
required: true
outputs:
logs:
description: "logs"
value: ${{ steps.build.outputs.logs }}
path:
description: "output path"
value: ${{ steps.build.outputs.path }}
runs:
using: "composite"
steps:
- id: build
name: build
run: |
logfile=${{ inputs.job-name }}.log
echo "::set-output name=logs::$(echo $logfile)"
echo "::set-output name=path::$(echo generated/${{ inputs.job-name }})"
echo -e "\n****** python ******\n" >> $logfile
curdir=$(pwd)
cd ${{ inputs.path }}
echo -e "\n****** python setup and build ******\n" >> $curdir/$logfile
python3 setup.py install --user | tee --append $curdir/$logfile
pip3 install nose2 --user
python3 -m nose2 | tee --append $curdir/$logfile
cd ${curdir}
shell: bash
158 changes: 158 additions & 0 deletions .github/workflows/test-framework-dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: Test Framework DotNet

on:
# execute on demand
workflow_dispatch:
branches: ["master", "test-framework", "3.0.0"]
inputs:
language:
description: 'Language'
required: true
specUrl:
description: 'URL of OpenAPI doc'
required: true
default: "https://petstore3.swagger.io/api/v3/openapi.json"
options:
description: 'language options'
default: ''
jobName:
description: 'job name'
required: true

jobs:

# builds codegen cli and uploads its artifact
build-codegen:

runs-on: ubuntu-latest

strategy:
matrix:
java: [ 8 ]

steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: build codegen
run: |
mvn -q -B package -DskipTests
- name: prepare codegen cli
run: mkdir codegen-cli && cp modules/swagger-codegen-cli/target/swagger-codegen-cli.jar codegen-cli
- name: upload codegen cli
uses: actions/upload-artifact@v2
with:
name: codegen-cli
path: codegen-cli

generate:

needs: build-codegen

runs-on: ubuntu-latest

strategy:
matrix:
java: [ 8 ]


outputs:
generate_outcome: ${{ steps.outcome.outputs.generate_outcome }}

steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Download codegen cli
uses: actions/download-artifact@v2
with:
name: codegen-cli
- name: generate
id: generate
continue-on-error: true
uses: ./.github/actions/generate
with:
language: $LANGUAGE
job-name: ${JOB_NAME}
spec-url: ${SPEC_URL}
options: $OPTIONS
- id: outcome
run: |
echo "::set-output name=generate_outcome::${{ steps.generate.outcome }}"
echo ${{ steps.generate.outcome }} > generate_outcome_${{ env.JOB_NAME }}
- name: upload generate outcome
uses: actions/upload-artifact@v2
with:
name: ${{ env.JOB_NAME }}generate_outcome
path: generate_outcome_${{ env.JOB_NAME }}
- name: upload generate logs
uses: actions/upload-artifact@v2
with:
name: ${{ env.JOB_NAME }}generate_logs
path: ${{ steps.generate.outputs.logs }}
- name: upload generated code
if: contains(steps.generate.outcome, 'success')
uses: actions/upload-artifact@v2
with:
name: ${{ env.JOB_NAME }}generated
path: ${{ steps.generate.outputs.path }}

env:
LANGUAGE: ${{ github.event.inputs.language }}
JOB_NAME: ${{ github.event.inputs.jobName }}
OPTIONS: ${{ github.event.inputs.options }}
SPEC_URL: ${{ github.event.inputs.specUrl }}

build:

needs: generate
if: contains(needs.generate.outputs.generate_outcome, 'success')
runs-on: ubuntu-latest

strategy:
matrix:
dotnet-version: [3.1.x]

steps:
- uses: actions/checkout@v2
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: ${{ env.JOB_NAME }}generated
path: generated/${{ env.JOB_NAME }}
- name: Download logs
uses: actions/download-artifact@v2
with:
name: ${{ env.JOB_NAME }}generate_logs
- name: Set up DotNet 3.1.x
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ matrix.dotnet-version }}
- name: build
id: build
uses: ./.github/actions/dotnetbuild
continue-on-error: true
with:
path: generated/${{ env.JOB_NAME }}
job-name: ${{ env.JOB_NAME }}
- id: outcome
run: |
echo "::set-output name=build_outcome::${{ steps.build.outcome }}"
echo ${{ steps.build.outcome }} > ${{ env.JOB_NAME }}build_outcome
- name: upload build outcome
uses: actions/upload-artifact@v2
with:
name: ${{ env.JOB_NAME }}build_outcome
path: ${{ env.JOB_NAME }}build_outcome
- name: upload logs
uses: actions/upload-artifact@v2
with:
name: ${{ env.JOB_NAME }}logs
path: ${{ steps.build.outputs.logs }}
env:
LANGUAGE: ${{ github.event.inputs.language }}
JOB_NAME: ${{ github.event.inputs.jobName }}
OPTIONS: ${{ github.event.inputs.options }}
SPEC_URL: ${{ github.event.inputs.specUrl }}
Loading

0 comments on commit bdec255

Please sign in to comment.