From 0626af84ca2881eae7a42a0bcbdce3c08cf79538 Mon Sep 17 00:00:00 2001 From: linwumingshi Date: Thu, 25 Jul 2024 22:34:42 +0800 Subject: [PATCH] ci: :construction_worker: add workflows for doc generation and version update - Introduce GitHub Actions to automatically generate API documentation when a Smart Doc PR is opened. - Add a new workflow to update the Smart Doc plugin version in the Maven repository. - Refactor the code to use the context class loader for doc building in tests. - Bump up the Smart Doc version to 3.0.6 in the pom.xml. --- .../workflows/run-gen-doc-when-dispatch.yml | 61 +++++++++++++++++++ .../workflows/update-smart-doc-version.yml | 36 +++++++++++ pom.xml | 2 +- .../java/com/power/doc/word/WordTest.java | 6 +- 4 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/run-gen-doc-when-dispatch.yml create mode 100644 .github/workflows/update-smart-doc-version.yml diff --git a/.github/workflows/run-gen-doc-when-dispatch.yml b/.github/workflows/run-gen-doc-when-dispatch.yml new file mode 100644 index 0000000..21b899d --- /dev/null +++ b/.github/workflows/run-gen-doc-when-dispatch.yml @@ -0,0 +1,61 @@ +name: Run Plugin + +on: + repository_dispatch: + types: [run-plugin] + +jobs: + use-artifact: + runs-on: ubuntu-latest + + steps: + - name: Checkout Example Repository + uses: actions/checkout@v4 + with: + ref: master + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Build and Install Plugin + run: mvn -DskipTests=true install + + + - name: Set Artifact URL + run: | + ARTIFACT_ID="${{ github.event.client_payload.artifact_id }}" + if [ -z "$ARTIFACT_ID" ]; then + echo "Error: ARTIFACT_ID is not set." + exit 1 + fi + ARTIFACT_URL="https://api.github.com/repos/TongchengOpenSource/smart-doc/actions/artifacts/${ARTIFACT_ID}/zip" + echo "artifact_url=$ARTIFACT_URL" >> $GITHUB_ENV + + - name: Download Artifact + run: | + echo "Downloading artifact from ${{ env.artifact_url }}" + curl -L -o smart-doc-maven-jar.zip -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "${{ env.artifact_url }}" + + - name: Create Directory and Move File + run: | + mkdir -p ~/.m2/repository/com/ly/smart-doc + mv smart-doc-maven-jar.zip ~/.m2/repository/com/ly/smart-doc/ + echo "Listing files in target directory:" + ls -lh ~/.m2/repository/com/ly/smart-doc + + - name: Unzip Artifact + run: | + unzip -o -d ~/.m2/repository/com/ly/smart-doc ~/.m2/repository/com/ly/smart-doc/smart-doc-maven-jar.zip || (echo "Unzip failed" && exit 1) + ls -lh ~/.m2/repository/com/ly/smart-doc + + - name: Build and Install Plugin Again + run: mvn -DskipTests=true install + + + - name: Generate doc + run: mvn -DskipTests=true smart-doc:html + + diff --git a/.github/workflows/update-smart-doc-version.yml b/.github/workflows/update-smart-doc-version.yml new file mode 100644 index 0000000..5a23685 --- /dev/null +++ b/.github/workflows/update-smart-doc-version.yml @@ -0,0 +1,36 @@ +name: Update Plugin Version + +on: + repository_dispatch: + types: [update-plugin-version] + +jobs: + update-version: + runs-on: ubuntu-latest + + steps: + - name: Checkout Example Repository + uses: actions/checkout@v4 + with: + ref: master + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Update Smart-Doc Version in pom.xml + run: | + version=${{ github.event.client_payload.version }} + mvn versions:set-property -Dproperty=smart-doc.version -DnewVersion=$version -DgenerateBackupPoms=false + + - name: Commit and Push Changes + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com' + git add pom.xml + git commit -m "chore(pom.xml): :arrow_up: update smart-doc version to ${{ github.event.client_payload.version }}" + git push origin master diff --git a/pom.xml b/pom.xml index e9b5a57..19fbcd8 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ UTF-8 17 2.2.2 - 3.0.5 + 3.0.6 com.ly.smart-doc ${project.basedir}/src/docs/asciidoc ${project.build.directory}/asciidoc/generated diff --git a/src/test/java/com/power/doc/word/WordTest.java b/src/test/java/com/power/doc/word/WordTest.java index 4b2d8b1..6157e1a 100644 --- a/src/test/java/com/power/doc/word/WordTest.java +++ b/src/test/java/com/power/doc/word/WordTest.java @@ -72,7 +72,8 @@ public void renderWord() throws Exception { builderTemplate.checkAndInit(config, Boolean.TRUE); config.setParamsDataToTree(false); ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); - IDocBuildTemplate docBuildTemplate = BuildTemplateFactory.getDocBuildTemplate(config.getFramework()); + IDocBuildTemplate docBuildTemplate = BuildTemplateFactory.getDocBuildTemplate(config.getFramework(), + Thread.currentThread().getContextClassLoader()); ApiSchema apiData = docBuildTemplate.getApiData(configBuilder); List apiDocList = apiData.getApiDatas(); System.out.println(apiDocList); @@ -163,7 +164,8 @@ private ApiConfig config(boolean isAll) { private List list(ApiConfig config, JavaProjectBuilder javaProjectBuilder) { ProjectDocConfigBuilder configBuilder = new ProjectDocConfigBuilder(config, javaProjectBuilder); - IDocBuildTemplate docBuildTemplate = BuildTemplateFactory.getDocBuildTemplate(config.getFramework()); + IDocBuildTemplate docBuildTemplate = BuildTemplateFactory.getDocBuildTemplate(config.getFramework(), + Thread.currentThread().getContextClassLoader()); ApiSchema apiData = docBuildTemplate.getApiData(configBuilder); List apiDocList = apiData.getApiDatas(); if (config.isAllInOne()) {