Skip to content

Add workflow

Add workflow #9

Workflow file for this run

name: JavaDoc to Documentation Portal
on:
workflow_dispatch:
inputs:
branch:
description: 'Branch to clone'
required: false
default: 'rel/5.23.0'
push:
branches:
- javadoc-aggregate-delombok
env:
JAVA_VERSION: 17
DOCS_REPO: SAP/cloud-sdk
PROJECTS: "!:rfc,!:dwc-cf,!:datamodel-metadata-generator,!:odata-generator,!:odata-generator-maven-plugin,!:odata-generator-utility,!:odata-v4-generator,!:odata-v4-generator-maven-plugin,!:s4hana-connectivity,!:soap,!:testutil,!:s4hana-core"
jobs:
build:
name: "JavaDoc to Documentation Portal"
runs-on: ubuntu-latest
steps:
- name: "Prepare git"
run: |
git config --global user.email "cloudsdk@sap.com"
git config --global user.name "SAP Cloud SDK Bot"
- name: "Checkout Repository"
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Switch branch"
run: git checkout "${{ github.event.inputs.branch || 'rel/5.23.0' }}"
- name: "Set up JDK 17"
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
- name: "Determine Major Version"
id: determine-major-version
run: |
echo "MAJOR_VERSION=$(jq -r '.version' latest.json | cut -d '.' -f 1)" >> $GITHUB_OUTPUT
echo ${GITHUB_OUTPUT}
#- name: "Install project (skip tests)"
# run: mvn install -DskipTests --quiet
- name: "Process sources"
run: mvn process-sources -Drelease --fail-at-end --projects "${PROJECTS}" --quiet
- name: "Copy delombok sources"
run: find . -type d -path "*/target/delombok" -exec sh -c 'cp -r "$1"/* "$(dirname $(dirname "$1"))/src/main/java/"' _ {} \;
- name: "Generate aggregated Javadoc"
run: |
mvn clean javadoc:aggregate -Drelease -Djava.failOnWarning=false -Djavadoc.sourcepath=src/main/java --projects "${PROJECTS}" --quiet
ls -lA target
- name: "Save JavaDoc path"
id: javadoc-path
run: echo "JAVADOC_DIR=$(pwd)/target" >> $GITHUB_OUTPUT
- name: "Checkout Docs Repository"
uses: actions/checkout@v4
with:
repository: ${{ env.DOCS_REPO }}
path: .cloud-sdk-docs
token: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
- name: "Replace JavaDoc"
id: replace-javadoc
run: |
TARGET_DIR=./.cloud-sdk-docs/static/java-api/v${{ steps.determine-major-version.outputs.MAJOR_VERSION }}
ls -lA target
rm -rf $TARGET_DIR
mkdir -p $TARGET_DIR
mv target $TARGET_DIR
cd ./.cloud-sdk-docs
git add -A .
exit 1
CHANGED_FILES="$(git status -s)"
if [[ -z "$CHANGED_FILES" ]]; then
echo "[DEBUG] No changes to API docs detected, skipping Pull Request creation."
echo "CREATE_PR=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "CREATE_PR=true" >> $GITHUB_OUTPUT
BRANCH_NAME=java/release-docs-${{ needs.bump-version.outputs.release-version }}
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT
git switch --create $BRANCH_NAME
git commit -m "chore: Update JavaDocs for release ${{ needs.bump-version.outputs.release-version }}"
COMMIT_SHA=$(git log -1 --pretty=format:"%H")
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_OUTPUT
git push origin $BRANCH_NAME
- name: "Create JavaDoc PR"
id: create-javadoc-pr
if: ${{ steps.replace-javadoc.outputs.CREATE_PR == 'true' }}
working-directory: ./.cloud-sdk-docs
run: |
PR_TITLE="Java: Update JavaDocs for release ${{ needs.bump-version.outputs.release-version }}"
PR_BODY="Replace the contents of v${{ steps.determine-major-version.outputs.MAJOR_VERSION }} API docs with the latest release of the SDK."
PR_URL=$(gh pr create --title "$PR_TITLE" --body "$PR_BODY" --repo "${{ env.DOCS_REPO }}")
echo "PR_URL=$PR_URL" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}