@@ -2,7 +2,6 @@ name: Release Codegen 3.0 and Generators
22
33on :
44 workflow_dispatch :
5- branches : [ "3.0.0" ]
65
76jobs :
87 release :
@@ -112,196 +111,204 @@ jobs:
112111 - name : Run maven install for codegen
113112 if : env.RELEASE_OK == 'yes'
114113 run : |
115- SNAP_API="https://central.sonatype.com/repository/maven-snapshots"
116114 ARTIFACT_PATH="io/swagger/codegen/v3/swagger-codegen-generators"
117- ROOT_META="${SNAP_API}/${ARTIFACT_PATH}/maven-metadata.xml"
118- export LAST_SNAP=$(curl -s "$ROOT_META" | grep -oP '(?<=<version>)1\.[^<]+' | sort -V | tail -n1)
119- echo "LAST_SNAP $LAST_SNAP"
120- export GENERATORS_VERSION_PROPERTY=-Dswagger-codegen-generators-version=$LAST_SNAP
121- mvn clean install -U -Pdocker -DJETTY_TEST_HTTP_PORT=8090 -DJETTY_TEST_STOP_PORT=8089 ${GENERATORS_VERSION_PROPERTY}
122- - name : Run maven deploy/release for codegen-generators
123- if : env.RELEASE_OK == 'yes' && env.GENERATORS_RELEASE_OK == 'yes'
124- working-directory : generators-repo
125- run : |
126- mvn --no-transfer-progress -B -Prelease deploy
127- - name : Run maven deploy/release for codegen
128- if : env.RELEASE_OK == 'yes'
129- run : |
130- mvn --no-transfer-progress -B -Prelease deploy
131- - name : Set up QEMU
132- uses : docker/setup-qemu-action@v3
133- - name : Set up Docker Buildx
134- uses : docker/setup-buildx-action@v3
135- - name : preliminary checks
136- run : |
137- docker login --username=${{ secrets.DOCKERHUB_SB_USERNAME }} --password=${{ secrets.DOCKERHUB_SB_PASSWORD }}
138- set -e
139- - name : Build with Maven
140- run : |
141- mvn clean install -U -Pdocker -DJETTY_TEST_HTTP_PORT=8090 -DJETTY_TEST_STOP_PORT=8089
142- - name : docker generator build and push
143- if : env.RELEASE_OK == 'yes'
144- uses : docker/build-push-action@v5
145- with :
146- context : ./modules/swagger-generator
147- file : ./modules/swagger-generator/Dockerfile
148- push : true
149- platforms : linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
150- provenance : false
151- build-args : |
152- HIDDEN_OPTIONS_DEFAULT_PATH=hiddenOptions.yaml
153- JAVA_MEM=1024m
154- HTTP_PORT=8080
155- tags : swaggerapi/swagger-generator-v3:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3:latest
156- - name : docker generator root build and push
157- if : env.RELEASE_OK == 'yes'
158- uses : docker/build-push-action@v5
159- with :
160- context : ./modules/swagger-generator
161- file : ./modules/swagger-generator/Dockerfile_root
162- push : true
163- platforms : linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
164- provenance : false
165- build-args : |
166- HIDDEN_OPTIONS_DEFAULT_PATH=hiddenOptions.yaml
167- JAVA_MEM=1024m
168- HTTP_PORT=8080
169- tags : swaggerapi/swagger-generator-v3-root:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3-root:latest
170- - name : docker cli build and push
171- if : env.RELEASE_OK == 'yes'
172- uses : docker/build-push-action@v5
173- with :
174- context : ./modules/swagger-codegen-cli
175- file : ./modules/swagger-codegen-cli/Dockerfile
176- push : true
177- platforms : linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
178- provenance : false
179- tags : swaggerapi/swagger-codegen-cli-v3:latest,swaggerapi/swagger-codegen-cli-v3:${{ env.SC_VERSION }}
180- - name : docker minimal build and push
181- if : env.RELEASE_OK == 'yes'
182- uses : docker/build-push-action@v5
183- with :
184- context : ./modules/swagger-generator
185- file : ./modules/swagger-generator/Dockerfile_minimal
186- push : true
187- platforms : linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
188- provenance : false
189- tags : swaggerapi/swagger-generator-v3-minimal:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3-minimal:latest
190- - name : deploy
191- if : env.RELEASE_OK == 'yes'
192- run : |
193- echo "${{ env.SC_VERSION }}"
194-
195- TOKEN="${{ secrets.RANCHER2_BEARER_TOKEN }}"
196- RANCHER_HOST="rancher.tools.swagger.io"
197- CLUSTER_ID="c-n8zp2"
198- NAMESPACE_NAME="swagger-oss"
199- K8S_OBJECT_TYPE="daemonsets"
200- K8S_OBJECT_NAME="swagger-generator-v3"
201- DEPLOY_IMAGE="swaggerapi/swagger-generator-v3:${{ env.SC_VERSION }}"
202-
203- workloadStatus=""
204- getStatus() {
205- echo "Getting update status..."
206- if ! workloadStatus="$(curl -s -X GET \
207- -H "Authorization: Bearer ${TOKEN}" \
208- -H 'Content-Type: application/json' \
209- "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}/status")"
210- then
211- echo 'ERROR - get status k8s API call failed!'
212- echo "Exiting build"...
213- exit 1
214- fi
215- }
216-
217- # $1 = image to deploy
218- updateObject() {
219- local image="${1}"
220- echo "Updating image value..."
221-
222- if ! curl -s -X PATCH \
223- -H "Authorization: Bearer ${TOKEN}" \
224- -H 'Content-Type: application/json-patch+json' \
225- "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}" \
226- -d "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/image\", \"value\": \"${image}\"}]"
227- then
228- echo 'ERROR - image update k8s API call failed!'
229- echo "Exiting build..."
230- exit 1
231- fi
232- }
233-
234-
235- # Check that the TAG is valid
236- if [[ ${{ env.SC_VERSION }} =~ ^[vV]?[0-9]*\.[0-9]*\.[0-9]*$ ]]; then
237- echo ""
238- echo "This is a Valid TAG..."
239-
240- # Get current image/tag in case we need to rollback
241- getStatus
242- ROLLBACK_IMAGE="$(echo "${workloadStatus}" | jq -r '.spec.template.spec.containers[0].image')"
243- echo ""
244- echo "Current image: ${ROLLBACK_IMAGE}"
245-
246- # Update image and validate response
247- echo ""
248- updateObject "${DEPLOY_IMAGE}"
249- echo ""
250-
251- echo ""
252- echo "Waiting for pods to start..."
253- echo ""
254- sleep 60s
255-
256- # Get state of the k8s object. If numberReady == desiredNumberScheduled, consider the upgrade successful. Else raise error
257- getStatus
258- status="$(echo "${workloadStatus}" | jq '.status')"
259- echo ""
260- echo "${status}"
261- echo ""
262-
263- numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
264- numberReady="$(echo "${status}" | jq -r '.numberReady')"
265-
266- if (( numberReady == numberDesired )); then
267- echo "${K8S_OBJECT_NAME} has been upgraded to ${DEPLOY_IMAGE}"
268-
269- # If pods are not starting, rollback the upgrade and exit the build with error
270- else
271- echo "state = error...rolling back upgrade"
272- updateObject "${ROLLBACK_IMAGE}"
273- echo ""
274-
275- echo ""
276- echo "Waiting for rollback pods to start..."
277- echo ""
278- sleep 60s
279-
280- getStatus
281- status="$(echo "${workloadStatus}" | jq '.status')"
282- echo ""
283- echo "${status}"
284- echo ""
285-
286- numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
287- numberReady="$(echo "${status}" | jq -r '.numberReady')"
288-
289- if (( numberReady == numberDesired )); then
290- echo "Rollback to ${ROLLBACK_IMAGE} completed."
291- else
292- echo "FATAL - rollback failed"
293- fi
294- echo "Exiting Build..."
295- exit 1
296- fi
297-
115+ LAST_VERSION=""
116+ if [[ "${{ env.GENERATORS_RELEASE_OK }}" == 'yes' ]]; then
117+ SNAP_API="https://central.sonatype.com/repository/maven-snapshots"
118+ ROOT_META="${SNAP_API}/${ARTIFACT_PATH}/maven-metadata.xml"
119+ export LAST_VERSION=$(curl -s "$ROOT_META" | awk -F'[<>]' '/<version>1\./{print $3}' | sort -V | tail -n1)
120+ echo "Generators will be released - GENERATORS LAST_VERSION: $LAST_VERSION"
298121 else
299- echo "This TAG is not in a valid format..."
300- echo "Exiting Build..."
301- exit 0
122+ RELEASED_API="https://repo1.maven.org/maven2"
123+ ROOT_META="${RELEASED_API}/${ARTIFACT_PATH}/maven-metadata.xml"
124+ export LAST_VERSION=$(curl -s "$ROOT_META" | awk -F'[<>]' '/<version>1\./{print $3}' | sort -V | tail -n1)
125+ echo "Only codegen will be released - GENERATORS LAST_VERSION: $LAST_VERSION"
302126 fi
303- echo "Exiting Build..."
304- exit 0
127+ export GENERATORS_VERSION_PROPERTY=-Dswagger-codegen-generators-version=$LAST_VERSION
128+ mvn clean install -U -Pdocker -DJETTY_TEST_HTTP_PORT=8090 -DJETTY_TEST_STOP_PORT=8089 ${GENERATORS_VERSION_PROPERTY}
129+ # - name: Run maven deploy/release for codegen-generators
130+ # if: env.RELEASE_OK == 'yes' && env.GENERATORS_RELEASE_OK == 'yes'
131+ # working-directory: generators-repo
132+ # run: |
133+ # mvn --no-transfer-progress -B -Prelease deploy
134+ # - name: Run maven deploy/release for codegen
135+ # if: env.RELEASE_OK == 'yes'
136+ # run: |
137+ # mvn --no-transfer-progress -B -Prelease deploy
138+ # - name: Set up QEMU
139+ # uses: docker/setup-qemu-action@v3
140+ # - name: Set up Docker Buildx
141+ # uses: docker/setup-buildx-action@v3
142+ # - name: preliminary checks
143+ # run: |
144+ # docker login --username=${{ secrets.DOCKERHUB_SB_USERNAME }} --password=${{ secrets.DOCKERHUB_SB_PASSWORD }}
145+ # set -e
146+ # - name: Build with Maven
147+ # run: |
148+ # mvn clean install -U -Pdocker -DJETTY_TEST_HTTP_PORT=8090 -DJETTY_TEST_STOP_PORT=8089
149+ # - name: docker generator build and push
150+ # if: env.RELEASE_OK == 'yes'
151+ # uses: docker/build-push-action@v5
152+ # with:
153+ # context: ./modules/swagger-generator
154+ # file: ./modules/swagger-generator/Dockerfile
155+ # push: true
156+ # platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
157+ # provenance: false
158+ # build-args: |
159+ # HIDDEN_OPTIONS_DEFAULT_PATH=hiddenOptions.yaml
160+ # JAVA_MEM=1024m
161+ # HTTP_PORT=8080
162+ # tags: swaggerapi/swagger-generator-v3:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3:latest
163+ # - name: docker generator root build and push
164+ # if: env.RELEASE_OK == 'yes'
165+ # uses: docker/build-push-action@v5
166+ # with:
167+ # context: ./modules/swagger-generator
168+ # file: ./modules/swagger-generator/Dockerfile_root
169+ # push: true
170+ # platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x
171+ # provenance: false
172+ # build-args: |
173+ # HIDDEN_OPTIONS_DEFAULT_PATH=hiddenOptions.yaml
174+ # JAVA_MEM=1024m
175+ # HTTP_PORT=8080
176+ # tags: swaggerapi/swagger-generator-v3-root:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3-root:latest
177+ # - name: docker cli build and push
178+ # if: env.RELEASE_OK == 'yes'
179+ # uses: docker/build-push-action@v5
180+ # with:
181+ # context: ./modules/swagger-codegen-cli
182+ # file: ./modules/swagger-codegen-cli/Dockerfile
183+ # push: true
184+ # platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
185+ # provenance: false
186+ # tags: swaggerapi/swagger-codegen-cli-v3:latest,swaggerapi/swagger-codegen-cli-v3:${{ env.SC_VERSION }}
187+ # - name: docker minimal build and push
188+ # if: env.RELEASE_OK == 'yes'
189+ # uses: docker/build-push-action@v5
190+ # with:
191+ # context: ./modules/swagger-generator
192+ # file: ./modules/swagger-generator/Dockerfile_minimal
193+ # push: true
194+ # platforms: linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
195+ # provenance: false
196+ # tags: swaggerapi/swagger-generator-v3-minimal:${{ env.SC_VERSION }},swaggerapi/swagger-generator-v3-minimal:latest
197+ # - name: deploy
198+ # if: env.RELEASE_OK == 'yes'
199+ # run: |
200+ # echo "${{ env.SC_VERSION }}"
201+ #
202+ # TOKEN="${{ secrets.RANCHER2_BEARER_TOKEN }}"
203+ # RANCHER_HOST="rancher.tools.swagger.io"
204+ # CLUSTER_ID="c-n8zp2"
205+ # NAMESPACE_NAME="swagger-oss"
206+ # K8S_OBJECT_TYPE="daemonsets"
207+ # K8S_OBJECT_NAME="swagger-generator-v3"
208+ # DEPLOY_IMAGE="swaggerapi/swagger-generator-v3:${{ env.SC_VERSION }}"
209+ #
210+ # workloadStatus=""
211+ # getStatus() {
212+ # echo "Getting update status..."
213+ # if ! workloadStatus="$(curl -s -X GET \
214+ # -H "Authorization: Bearer ${TOKEN}" \
215+ # -H 'Content-Type: application/json' \
216+ # "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}/status")"
217+ # then
218+ # echo 'ERROR - get status k8s API call failed!'
219+ # echo "Exiting build"...
220+ # exit 1
221+ # fi
222+ # }
223+ #
224+ # # $1 = image to deploy
225+ # updateObject() {
226+ # local image="${1}"
227+ # echo "Updating image value..."
228+ #
229+ # if ! curl -s -X PATCH \
230+ # -H "Authorization: Bearer ${TOKEN}" \
231+ # -H 'Content-Type: application/json-patch+json' \
232+ # "https://${RANCHER_HOST}/k8s/clusters/${CLUSTER_ID}/apis/apps/v1/namespaces/${NAMESPACE_NAME}/${K8S_OBJECT_TYPE}/${K8S_OBJECT_NAME}" \
233+ # -d "[{\"op\": \"replace\", \"path\": \"/spec/template/spec/containers/0/image\", \"value\": \"${image}\"}]"
234+ # then
235+ # echo 'ERROR - image update k8s API call failed!'
236+ # echo "Exiting build..."
237+ # exit 1
238+ # fi
239+ # }
240+ #
241+ #
242+ # # Check that the TAG is valid
243+ # if [[ ${{ env.SC_VERSION }} =~ ^[vV]?[0-9]*\.[0-9]*\.[0-9]*$ ]]; then
244+ # echo ""
245+ # echo "This is a Valid TAG..."
246+ #
247+ # # Get current image/tag in case we need to rollback
248+ # getStatus
249+ # ROLLBACK_IMAGE="$(echo "${workloadStatus}" | jq -r '.spec.template.spec.containers[0].image')"
250+ # echo ""
251+ # echo "Current image: ${ROLLBACK_IMAGE}"
252+ #
253+ # # Update image and validate response
254+ # echo ""
255+ # updateObject "${DEPLOY_IMAGE}"
256+ # echo ""
257+ #
258+ # echo ""
259+ # echo "Waiting for pods to start..."
260+ # echo ""
261+ # sleep 60s
262+ #
263+ # # Get state of the k8s object. If numberReady == desiredNumberScheduled, consider the upgrade successful. Else raise error
264+ # getStatus
265+ # status="$(echo "${workloadStatus}" | jq '.status')"
266+ # echo ""
267+ # echo "${status}"
268+ # echo ""
269+ #
270+ # numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
271+ # numberReady="$(echo "${status}" | jq -r '.numberReady')"
272+ #
273+ # if (( numberReady == numberDesired )); then
274+ # echo "${K8S_OBJECT_NAME} has been upgraded to ${DEPLOY_IMAGE}"
275+ #
276+ # # If pods are not starting, rollback the upgrade and exit the build with error
277+ # else
278+ # echo "state = error...rolling back upgrade"
279+ # updateObject "${ROLLBACK_IMAGE}"
280+ # echo ""
281+ #
282+ # echo ""
283+ # echo "Waiting for rollback pods to start..."
284+ # echo ""
285+ # sleep 60s
286+ #
287+ # getStatus
288+ # status="$(echo "${workloadStatus}" | jq '.status')"
289+ # echo ""
290+ # echo "${status}"
291+ # echo ""
292+ #
293+ # numberDesired="$(echo "${status}" | jq -r '.desiredNumberScheduled')"
294+ # numberReady="$(echo "${status}" | jq -r '.numberReady')"
295+ #
296+ # if (( numberReady == numberDesired )); then
297+ # echo "Rollback to ${ROLLBACK_IMAGE} completed."
298+ # else
299+ # echo "FATAL - rollback failed"
300+ # fi
301+ # echo "Exiting Build..."
302+ # exit 1
303+ # fi
304+ #
305+ # else
306+ # echo "This TAG is not in a valid format..."
307+ # echo "Exiting Build..."
308+ # exit 0
309+ # fi
310+ # echo "Exiting Build..."
311+ # exit 0
305312 env :
306313 ACTIONS_ALLOW_UNSECURE_COMMANDS : true
307314 MAVEN_USERNAME : ${{ secrets.MAVEN_CENTRAL_USERNAME }}
0 commit comments