forked from swagger-api/swagger-codegen
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/3.0.0' into swagger_build_for_…
…v3_jsvt
- Loading branch information
Showing
679 changed files
with
44,000 additions
and
2,266 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: 'Builder' | ||
description: 'build project' | ||
inputs: | ||
path: | ||
description: 'project root path' | ||
required: true | ||
job-name: | ||
description: 'Job name' | ||
required: true | ||
build-commands: | ||
description: 'Build Commands' | ||
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: | | ||
buildlogfile=${{ inputs.job-name }}-build.log | ||
echo "path=$(echo generated/${{ inputs.job-name }})" >> $GITHUB_OUTPUT | ||
curdir=$(pwd) | ||
echo -e "\n****** BUILD ******\n" >> $curdir/$buildlogfile | ||
cd ${{ inputs.path }} | ||
echo -e "${{ inputs.build-commands }}" > $curdir/buildcommands.log | ||
echo "logs=$(echo $curdir/$buildlogfile)" >> $GITHUB_OUTPUT | ||
buildcommands=$(cat $curdir/buildcommands.log) | ||
while [ "$buildcommands" ] ;do | ||
iter=${buildcommands%%__&&__*} | ||
echo -e "\n****** executing: $iter ******\n" | ||
echo -e "\n****** executing: $iter ******\n" >> $curdir/$buildlogfile | ||
$iter 2>&1 | tee --append $curdir/$buildlogfile | ||
[ "$buildcommands" = "$iter" ] && \ | ||
buildcommands='' || \ | ||
buildcommands="${buildcommands#*__&&__}" | ||
done | ||
echo -e "\n****** executed all buildcommands ******\n" | ||
echo -e "\n****** executed all buildcommand ******\n" >> $curdir/$buildlogfile | ||
cd ${curdir} | ||
echo "logs=$(echo $curdir/$buildlogfile)" >> $GITHUB_OUTPUT | ||
shell: bash |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
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 | ||
chmod +x ${{ github.action_path }}/generate.sh | ||
echo "${{ inputs.language }} ${{ inputs.job-name }} ${{ inputs.spec-url }} ${{ inputs.options }}" | ||
echo -e "\n****** generate ******\n" > $logfile | ||
echo "logs=$(echo $logfile)" >> $GITHUB_OUTPUT | ||
${{ github.action_path }}/generate.sh ${{ inputs.language }} ${{ inputs.job-name }} ${{ inputs.spec-url }} ${{ inputs.options }} 2>&1 | tee --append $logfile | ||
echo "path=$(echo generated/${{ inputs.job-name }})" >> $GITHUB_OUTPUT | ||
echo "logs=$(echo $logfile)" >> $GITHUB_OUTPUT | ||
shell: bash |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/bin/bash | ||
|
||
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 | ||
|
||
echo "LANGUAGE $LANG" | ||
|
||
JOB_NAME=$2 | ||
|
||
echo "JOB_NAME $JOB_NAME" | ||
|
||
if [ -z "$JOB_NAME" ] | ||
then | ||
JOB_NAME=$LANG | ||
fi | ||
|
||
SPEC_URL=$3 | ||
|
||
echo "SPEC_URL PARAM $SPEC_URL" | ||
|
||
if [[ $SPEC_URL == "null" ]]; | ||
then | ||
SPEC_URL="https://petstore3.swagger.io/api/v3/openapi.json" | ||
fi | ||
|
||
echo "SPEC_URL $SPEC_URL" | ||
|
||
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 | ||
|
||
|
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
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="debug"/> | ||
<root level="debug"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
</configuration> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: 2 | ||
updates: | ||
- package-ecosystem: "maven" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
ignore: | ||
- dependency-name: "*" | ||
update-types: ["version-update:semver-major"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: 'Dependency Review' | ||
on: [pull_request] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
dependency-review: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 'Checkout Repository' | ||
uses: actions/checkout@v4 | ||
- name: Dependency Review | ||
uses: actions/dependency-review-action@v3 | ||
with: | ||
fail-on-severity: high |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
name: Build And Push Docker Release 3.0 | ||
|
||
on: | ||
workflow_dispatch: | ||
branches: [ "3.0.0" ] | ||
inputs: | ||
tag: | ||
description: tag/version to release | ||
required: true | ||
jobs: | ||
build_push_docker_release_30: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
name: git checkout 3.0.0 | ||
with: | ||
ref: 3.0.0 | ||
- name: Set up Java | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: temurin | ||
cache: maven | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: preliminary checks | ||
run: | | ||
docker login --username=${{ secrets.DOCKERHUB_SB_USERNAME }} --password=${{ secrets.DOCKERHUB_SB_PASSWORD }} | ||
set -e | ||
# fail if templates/generators contain carriage return '\r' | ||
/bin/bash ./bin/utils/detect_carriage_return.sh | ||
# fail if generators contain merge conflicts | ||
/bin/bash ./bin/utils/detect_merge_conflict.sh | ||
# fail if generators contain tab '\t' | ||
/bin/bash ./bin/utils/detect_tab_in_java_class.sh | ||
- uses: s4u/[email protected] | ||
name: setup maven settings.xml | ||
with: | ||
servers: | | ||
[{ | ||
"id": "sonatype-nexus-staging", | ||
"username": "${{ secrets.OSSRH_USERNAME }}", | ||
"password": "${{ secrets.OSSRH_TOKEN }}" | ||
}, | ||
{ | ||
"id": "sonatype-nexus-snapshots", | ||
"username": "${{ secrets.OSSRH_USERNAME }}", | ||
"password": "${{ secrets.OSSRH_TOKEN }}" | ||
}] | ||
- name: Build with Maven | ||
run: | | ||
mvn clean install -U -Pdocker -DJETTY_TEST_HTTP_PORT=8090 -DJETTY_TEST_STOP_PORT=8089 | ||
- name: docker generator build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ./modules/swagger-generator | ||
file: ./modules/swagger-generator/Dockerfile | ||
push: true | ||
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x | ||
provenance: false | ||
build-args: | | ||
HIDDEN_OPTIONS_DEFAULT_PATH=hiddenOptions.yaml | ||
JAVA_MEM=1024m | ||
HTTP_PORT=8080 | ||
tags: swaggerapi/swagger-generator-v3:latest,swaggerapi/swagger-generator-v3:${{ env.TAG }} | ||
- name: docker generator root build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ./modules/swagger-generator | ||
file: ./modules/swagger-generator/Dockerfile_root | ||
push: true | ||
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x | ||
provenance: false | ||
build-args: | | ||
HIDDEN_OPTIONS_DEFAULT_PATH=hiddenOptions.yaml | ||
JAVA_MEM=1024m | ||
HTTP_PORT=8080 | ||
tags: swaggerapi/swagger-generator-v3-root:latest,swaggerapi/swagger-generator-v3-root:${{ env.TAG }},swaggerapi/swagger-generator-v3:${{ env.TAG }}-root | ||
- name: docker cli build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ./modules/swagger-codegen-cli | ||
file: ./modules/swagger-codegen-cli/Dockerfile | ||
push: true | ||
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x | ||
provenance: false | ||
tags: swaggerapi/swagger-codegen-cli-v3:latest,swaggerapi/swagger-codegen-cli-v3:${{ env.TAG }} | ||
- name: docker minimal build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: ./modules/swagger-generator | ||
file: ./modules/swagger-generator/Dockerfile_minimal | ||
push: true | ||
platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x | ||
provenance: false | ||
tags: swaggerapi/swagger-generator-v3-minimal:latest,swaggerapi/swagger-generator-v3-minimal:${{ env.TAG }} | ||
- name: deploy | ||
run: | | ||
echo "${{ env.TAG }}" | ||
TOKEN="${{ secrets.RANCHER2_BEARER_TOKEN }}" | ||
RANCHER_HOST="rancher.tools.swagger.io" | ||
CLUSTER_ID="c-n8zp2" | ||
NAMESPACE_NAME="swagger-oss" | ||
K8S_OBJECT_TYPE="daemonsets" | ||
K8S_OBJECT_NAME="swagger-generator-v3" | ||
DEPLOY_IMAGE="swaggerapi/swagger-generator-v3:${{ env.TAG }}" | ||
workloadStatus="" | ||
getStatus() { | ||
echo "Getting update status..." | ||
if ! workloadStatus="$(curl -s -X GET \ | ||
-H "Authorization: Bearer ${TOKEN}" \ | ||
-H 'Content-Type: application/json' \ | ||
"https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}/status")" | ||
then | ||
echo 'ERROR - get status k8s API call failed!' | ||
echo "Exiting build"... | ||
exit 1 | ||
fi | ||
} | ||
# $1 = image to deploy | ||
updateObject() { | ||
local image="${1}" | ||
echo "Updating image value..." | ||
if ! curl -s -X PATCH \ | ||
-H "Authorization: Bearer ${TOKEN}" \ | ||
-H 'Content-Type: application/json-patch+json' \ | ||
"https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}" \ | ||
-d "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/image\", \"value\": \"${image}\"}]" | ||
then | ||
echo 'ERROR - image update k8s API call failed!' | ||
echo "Exiting build..." | ||
exit 1 | ||
fi | ||
} | ||
# Check that the TAG is valid | ||
if [[ ${{ env.TAG }} =~ ^[vV]?[0-9]*\.[0-9]*\.[0-9]*$ ]]; then | ||
echo "" | ||
echo "This is a Valid TAG..." | ||
# Get current image/tag in case we need to rollback | ||
getStatus | ||
ROLLBACK_IMAGE="$(echo "${workloadStatus}" | jq -r '.spec.template.spec.containers[0].image')" | ||
echo "" | ||
echo "Current image: ${ROLLBACK_IMAGE}" | ||
# Update image and validate response | ||
echo "" | ||
updateObject "${DEPLOY_IMAGE}" | ||
echo "" | ||
echo "" | ||
echo "Waiting for pods to start..." | ||
echo "" | ||
sleep 60s | ||
# Get state of the k8s object. If numberReady == desiredNumberScheduled, consider the upgrade successful. Else raise error | ||
getStatus | ||
status="$(echo "${workloadStatus}" | jq '.status')" | ||
echo "" | ||
echo "${status}" | ||
echo "" | ||
numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')" | ||
numberReady="$(echo "${status}" | jq -r '.numberReady')" | ||
if (( numberReady == numberDesired )); then | ||
echo "${K8S_OBJECT_NAME} has been upgraded to ${DEPLOY_IMAGE}" | ||
# If pods are not starting, rollback the upgrade and exit the build with error | ||
else | ||
echo "state = error...rolling back upgrade" | ||
updateObject "${ROLLBACK_IMAGE}" | ||
echo "" | ||
echo "" | ||
echo "Waiting for rollback pods to start..." | ||
echo "" | ||
sleep 60s | ||
getStatus | ||
status="$(echo "${workloadStatus}" | jq '.status')" | ||
echo "" | ||
echo "${status}" | ||
echo "" | ||
numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')" | ||
numberReady="$(echo "${status}" | jq -r '.numberReady')" | ||
if (( numberReady == numberDesired )); then | ||
echo "Rollback to ${ROLLBACK_IMAGE} completed." | ||
else | ||
echo "FATAL - rollback failed" | ||
fi | ||
echo "Exiting Build..." | ||
exit 1 | ||
fi | ||
else | ||
echo "This TAG is not in a valid format..." | ||
echo "Exiting Build..." | ||
exit 0 | ||
fi | ||
echo "Exiting Build..." | ||
exit 0 | ||
env: | ||
TAG: ${{ github.event.inputs.tag }} |
Oops, something went wrong.