Skip to content

Commit 421f14e

Browse files
committed
Add GHA workflow for generating WebAPI client library for Java
Signed-off-by: Yasumasa Suenaga <[email protected]>
1 parent f3c6a73 commit 421f14e

File tree

4 files changed

+222
-0
lines changed

4 files changed

+222
-0
lines changed

.github/workflows/4-release.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ env:
99
IMAGE_NAME: ${{ github.repository }}
1010

1111
jobs:
12+
detect-current-api-version:
13+
uses: ./.github/workflows/detect-webapi-version.yaml
14+
with:
15+
# We cannot use environment variables here due to workflow limitation.
16+
# https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/reusing-workflows#limitations
17+
registry: ghcr.io
18+
image-repo: ${{ github.repository }}
19+
1220
publish-container-image:
1321
runs-on: ubuntu-latest
22+
needs: detect-current-api-version
1423
permissions:
1524
packages: write
1625
steps:
@@ -41,3 +50,27 @@ jobs:
4150
tags: ${{ steps.meta.outputs.tags }}
4251
labels: ${{ steps.meta.outputs.labels }}
4352
provenance: false
53+
54+
detect-newer-api-version:
55+
needs: publish-container-image
56+
uses: ./.github/workflows/detect-webapi-version.yaml
57+
with:
58+
# We cannot use environment variables here due to workflow limitation.
59+
# https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/reusing-workflows#limitations
60+
registry: ghcr.io
61+
image-repo: ${{ github.repository }}
62+
63+
generate-webapi-clients:
64+
needs:
65+
- detect-current-api-version
66+
- detect-newer-api-version
67+
if: ${{ needs.detect-current-api-version.outputs.apiver != needs.detect-newer-api-version.outputs.apiver }}
68+
uses: ./.github/workflows/generate-webapi-clients.yaml
69+
permissions:
70+
contents: write
71+
packages: write
72+
with:
73+
# We cannot use environment variables here due to workflow limitation.
74+
# https://docs.github.com/en/enterprise-cloud@latest/actions/using-workflows/reusing-workflows#limitations
75+
registry: ghcr.io
76+
image-repo: ${{ github.repository }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Detect API version from OpenAPI document in WebAPI container image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
registry:
7+
type: string
8+
required: true
9+
image-repo:
10+
type: string
11+
required: true
12+
tag:
13+
type: string
14+
required: false
15+
default: latest
16+
outputs:
17+
image:
18+
value: ${{ jobs.make-image-name-for-pull.outputs.image }}
19+
apiver:
20+
value: ${{ jobs.detect-api-version.outputs.apiver }}
21+
22+
jobs:
23+
make-image-name-for-pull:
24+
runs-on: ubuntu-latest
25+
outputs:
26+
image: ${{ steps.make-image-name.outputs.IMAGE_NAME }}
27+
steps:
28+
- name: Make string for pulling container image
29+
id: make-image-name
30+
run: |
31+
REPO=${{ inputs.registry }}/${{ inputs.image-repo }}
32+
REPO_LOWER=${REPO,,}
33+
echo "IMAGE_NAME=$REPO_LOWER:${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
34+
35+
detect-api-version:
36+
needs: make-image-name-for-pull
37+
runs-on: ubuntu-latest
38+
services:
39+
webapi:
40+
image: ${{ needs.make-image-name-for-pull.outputs.image }}
41+
ports:
42+
- 8080:80
43+
options: >-
44+
--health-cmd "curl -sS http://localhost/health"
45+
--health-interval 3s
46+
--health-timeout 5s
47+
--health-retries 5
48+
outputs:
49+
apiver: ${{ steps.detect-api-version.outputs.CURRENT_API_VERSION }}
50+
steps:
51+
- name: Detect API version
52+
id: detect-api-version
53+
run: |
54+
API_VERSION=`curl -sS http://localhost:8080/api/v1/swagger.yaml | yq -r .info.version`
55+
echo "CURRENT_API_VERSION=$API_VERSION" >> "$GITHUB_OUTPUT"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Generate WebAPI client library for Java
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image:
7+
required: true
8+
type: string
9+
apiver:
10+
required: true
11+
type: string
12+
13+
jobs:
14+
generate-java-client:
15+
runs-on: ubuntu-latest
16+
services:
17+
webapi:
18+
image: ${{ inputs.image }}
19+
ports:
20+
- 8080:80
21+
options: >-
22+
--health-cmd "curl -sS http://localhost/health"
23+
--health-interval 3s
24+
--health-timeout 5s
25+
--health-retries 5
26+
permissions:
27+
packages: write
28+
env:
29+
API: http://localhost:8080/api/v1/swagger.yaml
30+
steps:
31+
- name: Prepare
32+
run: |
33+
mkdir work pages
34+
npm install -g @openapitools/[email protected]
35+
- name: Generate client library
36+
run: |
37+
echo '{"apiPackage": "foundation.greensoftware.carbonaware.webapi.client", "artifactDescription": "Carbon Aware SDK client library for Java", "artifactId": "casdk-client", "artifactVersion": "${{ inputs.apiver }}", "developerOrganization": "Green Software Foundation", "developerOrganizationUrl": "https://greensoftware.foundation/", "groupId": "foundation.greensoftware", "licenseName": "MIT License", "scmUrl": "${{ env.REPO }}", "artifactUrl": "${{ env.REPO }}/packages/", "scmConnection": "${{ github.repositoryUrl }}", "scmDeveloperConnection": "${{ github.repositoryUrl }}", "licenseUrl": "https://opensource.org/license/mit/", "developerName": "Green Software Foundation", "developerEmail": null}' > config.json
38+
openapi-generator-cli generate -i ${{ env.API }} -g java -o work -c config.json
39+
sed -i "s|</project>|<distributionManagement><repository><id>github</id><name>GitHub Packages</name><url>https://maven.pkg.github.com/${{ github.repository }}</url></repository></distributionManagement></project>|" work/pom.xml
40+
shell: bash
41+
- name: Setup Java 8
42+
uses: actions/setup-java@v4
43+
with:
44+
distribution: temurin
45+
java-version: 8
46+
cache: maven
47+
- name: Run Maven
48+
run: mvn -B deploy javadoc:javadoc
49+
env:
50+
GITHUB_TOKEN: ${{ github.token }}
51+
working-directory: work
52+
- name: Upload Javadoc
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: javadoc
56+
path: work/target/apidocs
57+
58+
push-javadoc:
59+
needs: generate-java-client
60+
concurrency: push-to-doc-website
61+
runs-on: ubuntu-latest
62+
env:
63+
DOCPATH: client-apidocs/${{ inputs.apiver }}/java
64+
permissions:
65+
contents: write
66+
steps:
67+
- name: Checkout doc-website branch
68+
uses: actions/checkout@v3
69+
with:
70+
ref: gh-pages
71+
- name: Prepare
72+
run: mkdir -p ${{ env.DOCPATH }}
73+
- name: Download Javadoc
74+
uses: actions/download-artifact@v4
75+
with:
76+
name: javadoc
77+
path: ${{ env.DOCPATH }}
78+
- name: Push Javadoc
79+
run: |
80+
git config --global user.name "github-actions[bot]"
81+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
82+
git add ${{ env.DOCPATH }}
83+
git commit -m "Add Javadoc for WeebAPI ${{ inputs.apiver }}"
84+
git push origin gh-pages
85+
env:
86+
GITHUB_TOKEN: ${{ github.token }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Generate WebAPI client libraries
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
registry:
7+
type: string
8+
required: true
9+
image-repo:
10+
type: string
11+
required: true
12+
tag:
13+
type: string
14+
required: false
15+
default: latest
16+
workflow_dispatch:
17+
inputs:
18+
registry:
19+
type: string
20+
required: false
21+
default: ghcr.io
22+
image-repo:
23+
type: string
24+
required: false
25+
default: "green-software-foundation/carbon-aware-sdk"
26+
tag:
27+
type: string
28+
required: false
29+
default: latest
30+
31+
permissions:
32+
contents: write
33+
packages: write
34+
35+
jobs:
36+
detect-api-version:
37+
uses: ./.github/workflows/detect-webapi-version.yaml
38+
with:
39+
registry: ${{ inputs.registry }}
40+
image-repo: ${{ inputs.image-repo }}
41+
tag: ${{ inputs.tag }}
42+
43+
generate-java-client:
44+
needs: detect-api-version
45+
uses: ./.github/workflows/generate-webapi-client-java.yaml
46+
with:
47+
image: ${{ needs.detect-api-version.outputs.image }}
48+
apiver: ${{ needs.detect-api-version.outputs.apiver }}

0 commit comments

Comments
 (0)