From 0824c82f0c43f6b737c0b53b523526072cd8f4ef Mon Sep 17 00:00:00 2001 From: Eduardo San Segundo Date: Fri, 12 Jun 2026 09:18:55 +0200 Subject: [PATCH] Added workflow to publish generated documentation on Sinch for developers --- .../generate-upload-documentation.yml | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/generate-upload-documentation.yml diff --git a/.github/workflows/generate-upload-documentation.yml b/.github/workflows/generate-upload-documentation.yml new file mode 100644 index 000000000..b2a5fd038 --- /dev/null +++ b/.github/workflows/generate-upload-documentation.yml @@ -0,0 +1,78 @@ +name: Generate and upload documentation + +on: + release: + types: [published] + workflow_dispatch: + inputs: + version: + description: 'Version to use for the documentation package in semver format (e.g. 1.2.3)' + required: true + +jobs: + upload-documentation: + runs-on: ubuntu-latest + env: + SDK_NAME: sinch-sdk-java + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Resolve Version + id: version + run: | + if [ "${{ github.event_name }}" = "release" ]; then + VERSION="${{ github.event.release.tag_name }}" + else + VERSION="${{ inputs.version }}" + fi + # Strip leading 'v' if present (e.g. v1.2.3 → 1.2.3) + VERSION="${VERSION#v}" + echo "value=${VERSION}" >> "$GITHUB_OUTPUT" + + - name: Validate Version Format + run: | + VERSION="${{ steps.version.outputs.value }}" + SEMVER_REGEX='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((alpha|beta|preview)(\.[0-9]+)?))?$' + if [[ ! "$VERSION" =~ $SEMVER_REGEX ]]; then + echo "::error::Invalid version format: '$VERSION'. Expected semver (e.g. 1.2.3, 1.2.3-alpha, 1.2.3-beta.1, 1.2.3-preview)" + exit 1 + fi + echo "Version '$VERSION' is valid" + + - name: Setup Java SDK + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + cache: maven + + - name: Generate Documentation + run: mvn -B javadoc:javadoc --file pom.xml + + - name: Package Documentation + run: | + cd target/site/apidocs + zip -r "../../../${{ env.SDK_NAME }}-${{ steps.version.outputs.value }}.zip" . + + - name: Upload to GitLab Registry + run: | + echo "Uploading documentation package to GitLab Registry..." + VERSION="${{ steps.version.outputs.value }}" + curl --fail --show-error --location --header "PRIVATE-TOKEN: ${{ secrets.GITLAB_REGISTRY_UPLOAD_DOC_TOKEN }}" \ + --upload-file "./${{ env.SDK_NAME }}-${VERSION}.zip" \ + "https://gitlab.com/api/v4/projects/63164411/packages/generic/${{ env.SDK_NAME }}/${VERSION}/${{ env.SDK_NAME }}-${VERSION}.zip" + echo "Documentation package for version ${VERSION} uploaded to GitLab Registry" + + - name: Trigger Downstream GitLab Pipeline + run: | + echo "Triggering downstream GitLab pipeline to notify about new documentation package version..." + VERSION="${{ steps.version.outputs.value }}" + curl --fail --show-error --location --request POST \ + --form "token=${{ secrets.GITLAB_NOTIFY_REGISTRY_UPLOADED_DOC_TOKEN }}" \ + --form "ref=main" \ + --form "variables[UPSTREAM_PACKAGE_NAME]=${{ env.SDK_NAME }}" \ + --form "variables[UPSTREAM_PACKAGE_VERSION]=${VERSION}" \ + "https://gitlab.com/api/v4/projects/63164411/trigger/pipeline" + echo "Documentation repo notified about new package version ${VERSION}"