Skip to content

Release Codegen 3.0 and Generators #43

Release Codegen 3.0 and Generators

Release Codegen 3.0 and Generators #43

name: Release Codegen 3.0 and Generators
on:
workflow_dispatch:
branches: [ "3.0.0" ]
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout swagger-codegen (3.0.0)
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: 3.0.0
- name: Checkout swagger-codegen-generators
uses: actions/checkout@v4
with:
repository: swagger-api/swagger-codegen-generators
token: ${{ secrets.GITHUB_TOKEN }}
ref: master
path: generators-repo
- uses: tibdex/github-app-token@v2
id: generate-token
with:
app_id: ${{ secrets.APP_ID }}
private_key: ${{ secrets.APP_PRIVATE_KEY }}
- name: Set up Java and Maven
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
server-id: central
cache: maven
overwrite-settings: false
server-username: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
server-password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
gpg-private-key: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE
- name: Add Central-Portal snapshot repo to settings.xml
uses: s4u/[email protected]
with:
repositories: '[{"id":"central-portal-snapshots","name":"Sonatype Central Portal snapshots","url":"https://central.sonatype.com/repository/maven-snapshots/","releases":{"enabled":false},"snapshots":{"enabled":true}}]'
servers: '[{"id":"central","username":"${{ secrets.MAVEN_CENTRAL_USERNAME }}","password":"${{ secrets.MAVEN_CENTRAL_PASSWORD }}"}]'
- name: Cache Maven repository
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
- name: configure git user email
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
git config --global hub.protocol https
git remote set-url origin https://\${{ secrets.GITHUB_TOKEN }}:[email protected]/swagger-api/swagger-codegen.git
- name: Check Release Version codegen
id: preRelease
run: |
# export GPG_TTY=$(tty)
export MY_POM_VERSION=`mvn -q -Dexec.executable="echo" -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
if [[ $MY_POM_VERSION =~ ^.*SNAPSHOT$ ]];
then
echo "not releasing snapshot version: " ${MY_POM_VERSION}
echo "RELEASE_OK=no" >> $GITHUB_ENV
else
echo "RELEASE_OK=yes" >> $GITHUB_ENV
fi
echo "SC_VERSION=$MY_POM_VERSION" >> $GITHUB_ENV
- name: Check Release Version codegen-generators
id: preReleaseGenerators
if: env.RELEASE_OK == 'yes'
working-directory: generators-repo
run: |
# export GPG_TTY=$(tty)
SNAP_API="https://central.sonatype.com/repository/maven-snapshots"
ARTIFACT_PATH="io/swagger/codegen/v3/swagger-codegen"
ROOT_META="${SNAP_API}/${ARTIFACT_PATH}/maven-metadata.xml"
export LAST_SNAP=$(curl -s "$ROOT_META" | grep -oP '(?<=<version>)3\.[^<]+' | sort -V | tail -n1)
echo "LAST_SNAP $LAST_SNAP"
export CODEGEN_VERSION_PROPERTY=-Dswagger-codegen-version=$LAST_SNAP
export MY_POM_VERSION_GENERATORS=`mvn -q -Dexec.executable="echo" ${CODEGEN_VERSION_PROPERTY} -Dexec.args='${projects.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec`
echo "generator version: " ${MY_POM_VERSION_GENERATORS}
if [[ $MY_POM_VERSION_GENERATORS =~ ^.*SNAPSHOT$ ]];
then
echo "not releasing codegen-generators snapshot version: " ${MY_POM_VERSION_GENERATORS}
echo "GENERATORS_RELEASE_OK=no" >> $GITHUB_ENV
else
GROUP_ID="io.swagger.codegen.v3"
ARTIFACT_ID="swagger-codegen-generators"
if mvn -q dependency:get -DgroupId=${GROUP_ID} -DartifactId=${ARTIFACT_ID} -Dversion=${MY_POM_VERSION_GENERATORS} > /dev/null 2>&1; then
echo "Version ${MY_POM_VERSION_GENERATORS} already exists in Maven Central."
echo "GENERATORS_RELEASE_OK=no" >> $GITHUB_ENV
else
echo "Version ${MY_POM_VERSION_GENERATORS} does not exist in Maven Central. Will be deployed."
echo "GENERATORS_RELEASE_OK=yes" >> $GITHUB_ENV
fi
fi
echo "generators version: " ${MY_POM_VERSION_GENERATORS}
echo "SC_VERSION_GENERATORS=${MY_POM_VERSION_GENERATORS}" >> $GITHUB_ENV
- name: Run maven install for codegen-generators
if: env.RELEASE_OK == 'yes'
working-directory: generators-repo
run: |
SNAP_API="https://central.sonatype.com/repository/maven-snapshots"
ARTIFACT_PATH="io/swagger/codegen/v3/swagger-codegen"
ROOT_META="${SNAP_API}/${ARTIFACT_PATH}/maven-metadata.xml"
export LAST_SNAP=$(curl -s "$ROOT_META" | grep -oP '(?<=<version>)3\.[^<]+' | sort -V | tail -n1)
echo "LAST_SNAP $LAST_SNAP"
export CODEGEN_VERSION_PROPERTY=-Dswagger-codegen-version=$LAST_SNAP
mvn clean install -U ${CODEGEN_VERSION_PROPERTY}
- name: Run maven install for codegen
if: env.RELEASE_OK == 'yes'
run: |
SNAP_API="https://central.sonatype.com/repository/maven-snapshots"
ARTIFACT_PATH="io/swagger/codegen/v3/swagger-codegen-generators"
ROOT_META="${SNAP_API}/${ARTIFACT_PATH}/maven-metadata.xml"
export LAST_SNAP=$(curl -s "$ROOT_META" | grep -oP '(?<=<version>)1\.[^<]+' | sort -V | tail -n1)
echo "LAST_SNAP $LAST_SNAP"
export GENERATORS_VERSION_PROPERTY=-Dswagger-codegen-generators-version=$LAST_SNAP
mvn clean install -U -Pdocker -DJETTY_TEST_HTTP_PORT=8090 -DJETTY_TEST_STOP_PORT=8089 ${GENERATORS_VERSION_PROPERTY}
- name: Run maven deploy/release for codegen-generators
if: env.RELEASE_OK == 'yes' && env.GENERATORS_RELEASE_OK == 'yes'
working-directory: generators-repo
run: |
mvn --no-transfer-progress -B -Prelease deploy
- name: Run maven deploy/release for codegen
if: env.RELEASE_OK == 'yes'
run: |
mvn --no-transfer-progress -B -Prelease deploy
- 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
- 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
if: env.RELEASE_OK == 'yes'
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:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3:latest
- name: docker generator root build and push
if: env.RELEASE_OK == 'yes'
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:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3-root:latest
- name: docker cli build and push
if: env.RELEASE_OK == 'yes'
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.SC_VERSION }}
- name: docker minimal build and push
if: env.RELEASE_OK == 'yes'
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:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3-minimal:latest
- name: deploy
if: env.RELEASE_OK == 'yes'
run: |
echo "${{ env.SC_VERSION }}"
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.SC_VERSION }}"
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.SC_VERSION }} =~ ^[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:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SC_VERSION:
SC_VERSION_GENERATORS:
GPG_PRIVATE_KEY: ${{ secrets.OSSRH_GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_PRIVATE_PASSPHRASE }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_PRIVATE_PASSPHRASE }}