Skip to content

Commit 0824c82

Browse files
committed
Added workflow to publish generated documentation on Sinch for developers
1 parent 5ec550b commit 0824c82

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Generate and upload documentation
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
version:
9+
description: 'Version to use for the documentation package in semver format (e.g. 1.2.3)'
10+
required: true
11+
12+
jobs:
13+
upload-documentation:
14+
runs-on: ubuntu-latest
15+
env:
16+
SDK_NAME: sinch-sdk-java
17+
18+
steps:
19+
- name: Checkout Code
20+
uses: actions/checkout@v4
21+
22+
- name: Resolve Version
23+
id: version
24+
run: |
25+
if [ "${{ github.event_name }}" = "release" ]; then
26+
VERSION="${{ github.event.release.tag_name }}"
27+
else
28+
VERSION="${{ inputs.version }}"
29+
fi
30+
# Strip leading 'v' if present (e.g. v1.2.3 → 1.2.3)
31+
VERSION="${VERSION#v}"
32+
echo "value=${VERSION}" >> "$GITHUB_OUTPUT"
33+
34+
- name: Validate Version Format
35+
run: |
36+
VERSION="${{ steps.version.outputs.value }}"
37+
SEMVER_REGEX='^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((alpha|beta|preview)(\.[0-9]+)?))?$'
38+
if [[ ! "$VERSION" =~ $SEMVER_REGEX ]]; then
39+
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)"
40+
exit 1
41+
fi
42+
echo "Version '$VERSION' is valid"
43+
44+
- name: Setup Java SDK
45+
uses: actions/setup-java@v4
46+
with:
47+
java-version: '21'
48+
distribution: 'temurin'
49+
cache: maven
50+
51+
- name: Generate Documentation
52+
run: mvn -B javadoc:javadoc --file pom.xml
53+
54+
- name: Package Documentation
55+
run: |
56+
cd target/site/apidocs
57+
zip -r "../../../${{ env.SDK_NAME }}-${{ steps.version.outputs.value }}.zip" .
58+
59+
- name: Upload to GitLab Registry
60+
run: |
61+
echo "Uploading documentation package to GitLab Registry..."
62+
VERSION="${{ steps.version.outputs.value }}"
63+
curl --fail --show-error --location --header "PRIVATE-TOKEN: ${{ secrets.GITLAB_REGISTRY_UPLOAD_DOC_TOKEN }}" \
64+
--upload-file "./${{ env.SDK_NAME }}-${VERSION}.zip" \
65+
"https://gitlab.com/api/v4/projects/63164411/packages/generic/${{ env.SDK_NAME }}/${VERSION}/${{ env.SDK_NAME }}-${VERSION}.zip"
66+
echo "Documentation package for version ${VERSION} uploaded to GitLab Registry"
67+
68+
- name: Trigger Downstream GitLab Pipeline
69+
run: |
70+
echo "Triggering downstream GitLab pipeline to notify about new documentation package version..."
71+
VERSION="${{ steps.version.outputs.value }}"
72+
curl --fail --show-error --location --request POST \
73+
--form "token=${{ secrets.GITLAB_NOTIFY_REGISTRY_UPLOADED_DOC_TOKEN }}" \
74+
--form "ref=main" \
75+
--form "variables[UPSTREAM_PACKAGE_NAME]=${{ env.SDK_NAME }}" \
76+
--form "variables[UPSTREAM_PACKAGE_VERSION]=${VERSION}" \
77+
"https://gitlab.com/api/v4/projects/63164411/trigger/pipeline"
78+
echo "Documentation repo notified about new package version ${VERSION}"

0 commit comments

Comments
 (0)