From e6536df3d9154ba9338bff7f03830c8511ffaac5 Mon Sep 17 00:00:00 2001 From: Simon Laurenz Date: Wed, 8 Dec 2021 14:17:03 +0100 Subject: [PATCH] Add files for Open Api Creation workflow --- .github/workflows/ci-openapi.yml | 67 +++++++++++++++++++ .../dgc/validation/decorator/OpenApiTest.java | 56 ++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 .github/workflows/ci-openapi.yml create mode 100644 src/test/java/eu/europa/ec/dgc/validation/decorator/OpenApiTest.java diff --git a/.github/workflows/ci-openapi.yml b/.github/workflows/ci-openapi.yml new file mode 100644 index 0000000..af39673 --- /dev/null +++ b/.github/workflows/ci-openapi.yml @@ -0,0 +1,67 @@ +name: ci-openapi +on: + workflow_dispatch: + release: + types: + - created +jobs: + release: + runs-on: ubuntu-20.04 + steps: + - uses: actions/setup-java@v2 + with: + java-version: 11 + distribution: adopt + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/cache@v2 + with: + path: | + ~/.m2/repository + key: ${{ runner.os }}-${{ hashFiles('**/pom.xml') }} + - name: version + run: >- + APP_SHA=$(git rev-parse --short ${GITHUB_SHA}); + APP_TAG=${GITHUB_REF/refs\/tags\/} + APP_VERSION=${APP_TAG}; + echo "APP_SHA=${APP_SHA}" >> ${GITHUB_ENV}; + echo "APP_TAG=${APP_TAG}" >> ${GITHUB_ENV}; + echo "APP_VERSION=${APP_VERSION}" >> ${GITHUB_ENV}; + - name: mvn + run: >- + mvn versions:set + --batch-mode + --file ./pom.xml + --settings ./settings.xml + --define newVersion="${APP_VERSION}"; + mvn clean verify + --batch-mode + --file ./pom.xml + --settings ./settings.xml + --define app.packages.username="${APP_PACKAGES_USERNAME}" + --define app.packages.password="${APP_PACKAGES_PASSWORD}"; + env: + APP_PACKAGES_USERNAME: ${{ github.actor }} + APP_PACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }} + - name: Upload Artifact + uses: actions/upload-artifact@v2 + with: + name: openapi.json + path: target/openapi.json + - name: Checkout OpenApi Doc Branch + uses: actions/checkout@v2 + with: + ref: openapi-doc + - name: Delete existing openapi.json + run: rm -f openapi.json + - name: Download openapi.json + uses: actions/download-artifact@v2 + with: + name: openapi.json + - name: Commit and Push changes + run: | + git config user.name github-actions + git config user.email github-actions@github.com + git commit -a --allow-empty -m "Update OpenAPI JSON" + git push diff --git a/src/test/java/eu/europa/ec/dgc/validation/decorator/OpenApiTest.java b/src/test/java/eu/europa/ec/dgc/validation/decorator/OpenApiTest.java new file mode 100644 index 0000000..be0b154 --- /dev/null +++ b/src/test/java/eu/europa/ec/dgc/validation/decorator/OpenApiTest.java @@ -0,0 +1,56 @@ +package eu.europa.ec.dgc.validation.decorator;/*- + * ---license-start + * eu-digital-green-certificates / dgca-validation-decorator + * --- + * Copyright (C) 2021 T-Systems International GmbH and all other contributors + * --- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ---license-end + */ + + +import java.io.BufferedInputStream; +import java.io.FileOutputStream; +import java.net.URL; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@Slf4j +@SpringBootTest( + properties = { + "server.port=8080", + "springdoc.api-docs.enabled=true", + "springdoc.api-docs.path=/openapi" + }, + webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT +) +class OpenApiTest { + + + @Test + void apiDocs() { + try (BufferedInputStream in = new BufferedInputStream(new URL("http://localhost:8080/openapi").openStream()); + FileOutputStream out = new FileOutputStream("target/openapi.json")) { + byte[] buffer = new byte[1024]; + int read; + while ((read = in.read(buffer, 0, buffer.length)) != -1) { + out.write(buffer, 0, read); + } + } catch (Exception e) { + log.error("Failed to download openapi specification.", e); + Assertions.fail(); + } + } +}