From dc44bbff9ec96da55c1b4a04d3938f6154d76a2e Mon Sep 17 00:00:00 2001 From: "Krzysztof Massalski (Extern)" Date: Tue, 12 Mar 2024 21:56:15 +0100 Subject: [PATCH] feat(impl):[#418] publish api to swagger hub --- .github/workflows/publish-swagger-hub.yml | 57 +++++++++++++++++++++++ .github/workflows/release.yaml | 11 +++++ CONTRIBUTING.md | 13 +++--- 3 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/publish-swagger-hub.yml diff --git a/.github/workflows/publish-swagger-hub.yml b/.github/workflows/publish-swagger-hub.yml new file mode 100644 index 0000000000..828c9a74a2 --- /dev/null +++ b/.github/workflows/publish-swagger-hub.yml @@ -0,0 +1,57 @@ +name: "Publish OpenAPI to Swaggerhub" + +on: + workflow_call: + inputs: + version: + required: true + description: Version that will be published to Swaggerhub + type: string + +jobs: + swagger-api: + runs-on: ubuntu-latest + env: + SWAGGERHUB_API_KEY: ${{ secrets.SWAGGERHUB_API_KEY }} + SWAGGERHUB_USER: ${{ secrets.SWAGGERHUB_USER }} + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Setup node + uses: actions/setup-node@v4 + + - name: Install Swagger CLI + run: | + npm i -g swaggerhub-cli + + - name: Build and run Docker Compose + run: docker-compose up -d + + - name: Extract versions + run: | + export DOWNSTREAM_VERSION="${{ inputs.version }}" + echo "DOWNSTREAM_VERSION=${DOWNSTREAM_VERSION}" >> "$GITHUB_ENV" + + # create API, will fail if exists + - name: Create API + continue-on-error: true + run: | + swaggerhub api:create ${{ env.SWAGGERHUB_USER }}/item-relationship-service/${{ env.DOWNSTREAM_VERSION }} -f docs/src/api/irs-api.yaml --visibility=public --published=unpublish + + # Post the API to SwaggerHub as "unpublished", because published APIs cannot be overwritten + - name: Publish API Specs to SwaggerHub + run: | + if [[ ${{ env.DOWNSTREAM_VERSION }} != *-SNAPSHOT ]]; then + echo "[INFO] - no snapshot, will set the API to 'published'"; + swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/item-relationship-service/${{ env.DOWNSTREAM_VERSION }} -f docs/src/api/irs-api.yaml --visibility=public --published=publish + swaggerhub api:setdefault ${{ env.SWAGGERHUB_USER }}/item-relationship-service/${{ env.DOWNSTREAM_VERSION }} + else + echo "[INFO] - snapshot, will set the API to 'unpublished'"; + swaggerhub api:update ${{ env.SWAGGERHUB_USER }}/item-relationship-service/${{ env.DOWNSTREAM_VERSION }} -f docs/src/api/irs-api.yaml --visibility=public --published=unpublish + fi diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f0b396121c..d5641838df 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -59,6 +59,17 @@ jobs: needs: - release uses: ./.github/workflows/jira-publish-release.yaml + with: + version: ${{ github.ref_name }} + secrets: inherit + + publish-to-swaggerhub: + name: "Publish OpenAPI spec to Swaggerhub" + permissions: + contents: read + needs: + - release + uses: ./.github/workflows/publish-swagger-hub.yml with: version: ${{ github.ref_name }} secrets: inherit \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d3705508cf..aded5da7aa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -176,13 +176,14 @@ https://github.com/google/google-java-format/blob/master/README.md#intellij-jre- - Check if the changelog entries for the release are complete. - Add the corresponding GitHub issue numbers to each entry if missing. 3. Update [COMPATIBILITY_MATRIX.md](COMPATIBILITY_MATRIX.md). -4. Create pull request from [release preparation branch to main](https://github.com/eclipse-tractusx/item-relationship-service/compare/chore/prepare-release-x.x.x) and merge to main. -5. Create Git tag for the desired release version `git tag x.x.x` +4. Update IRS API version in IrsApplication class and irs-api.yaml +5. Create pull request from [release preparation branch to main](https://github.com/eclipse-tractusx/item-relationship-service/compare/chore/prepare-release-x.x.x) and merge to main. +6. Create Git tag for the desired release version `git tag x.x.x` (note: the irs-helm tag will be created automatically by the GitHub workflow based on the version in the irs-helm changelog). -6. Push Git tag to repository `git push origin x.x.x` (this will trigger the GitHub release workflow). -7. Wait for release workflow to complete. -8. Merge the automatically opened PR by GitHub actions bot. -9. Notify about the release in IRS Matrix Chat using the following template: +7. Push Git tag to repository `git push origin x.x.x` (this will trigger the GitHub release workflow). +8. Wait for release workflow to complete. +9. Merge the automatically opened PR by GitHub actions bot. +10. Notify about the release in IRS Matrix Chat using the following template: > **IRS Release x.x.x** >