refactor: improve request example generation for API documentation #130
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Run Example Project | |
on: | |
pull_request: | |
branches: | |
- master | |
paths: | |
- 'src/**' # Trigger workflow only if files in src directory change | |
- 'pom.xml' # Trigger workflow only if pom.xml file changes | |
env: | |
smart-doc-version: ${{ github.run_id }} # Use the current GitHub workflow run ID as a temporary version number | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Set up JDK 8 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '8' | |
distribution: 'temurin' | |
- name: Create Logs Directory | |
run: mkdir -p logs | |
- name: Update Version in pom.xml | |
run: mvn versions:set -DnewVersion="${{ env.smart-doc-version }}" -DgenerateBackupPoms=false | |
- name: Build and Install Plugin | |
run: | | |
mvn install 2>&1 | tee logs/build.log | |
if grep -E "\[ERROR\]" logs/build.log; then | |
cat logs/build.log | |
exit 1 | |
fi | |
- name: Upload Plugin Artifact | |
id: upload-artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: smart-doc-maven-jar | |
path: ~/.m2/repository/com/ly/smart-doc | |
if-no-files-found: error | |
- name: Upload Build Log | |
if: failure() # Only run if previous steps fail | |
uses: actions/upload-artifact@v4 | |
with: | |
name: error-log-smart-doc-build | |
path: logs/build.log | |
maven-plugin-build: | |
needs: build | |
runs-on: ubuntu-latest | |
concurrency: | |
group: maven-plugin-build-${{ github.event.pull_request.number }} | |
cancel-in-progress: true | |
steps: | |
- name: Checkout Maven Plugin Repository | |
uses: actions/checkout@v4 | |
with: | |
repository: TongchengOpenSource/smart-doc-maven-plugin | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up JDK 8 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '8' | |
distribution: 'temurin' | |
- name: Create Logs Directory | |
run: mkdir -p logs | |
- name: Download Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: smart-doc-maven-jar | |
path: ./artifacts | |
- name: Move Files to Local Maven Repository | |
run: | | |
mkdir -p ~/.m2/repository/com/ly/smart-doc | |
echo "Overwriting target directory with new artifacts:" | |
rsync -av --delete ./artifacts/ ~/.m2/repository/com/ly/smart-doc/ | |
echo "Listing files in target directory:" | |
ls -lh ~/.m2/repository/com/ly/smart-doc | |
- name: Update Version in pom.xml | |
run: | | |
mvn versions:set-property -Dproperty="smart-doc.version" -DnewVersion="${{ env.smart-doc-version }}" -DgenerateBackupPoms=false | |
- name: Build and Install | |
run: | | |
mvn -DskipTests=true install 2>&1 | tee logs/install-plugin.log | |
if grep -E "\[ERROR\]" logs/install-plugin.log; then | |
cat logs/install-plugin.log | |
exit 1 | |
fi | |
- name: Upload Plugin Artifact | |
id: upload-artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: smart-doc-maven-plugin-jar | |
path: ~/.m2/repository/com/ly/smart-doc | |
if-no-files-found: error | |
- name: Upload Plugin Build Log | |
if: failure() # Only run if previous steps fail | |
uses: actions/upload-artifact@v4 | |
with: | |
name: error-log-maven-plugin-build | |
path: logs/install-plugin.log | |
generate-api-docs: | |
needs: maven-plugin-build | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
doc_type: [ rest, dubbo, javadoc, websocket ] | |
concurrency: | |
group: generate-${{ matrix.doc_type }}-api-doc-${{ github.event.pull_request.number }} | |
cancel-in-progress: true | |
steps: | |
- name: Checkout Example Project | |
uses: actions/checkout@v4 | |
with: | |
repository: smart-doc-group/smart-doc-example-cn | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Create Logs Directory | |
run: mkdir -p logs | |
- name: Download Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: smart-doc-maven-plugin-jar | |
path: ./artifacts | |
- name: Move Files to Local Maven Repository | |
run: | | |
mkdir -p ~/.m2/repository/com/ly/smart-doc | |
echo "Overwriting target directory with new artifacts:" | |
rsync -av --delete ./artifacts/ ~/.m2/repository/com/ly/smart-doc/ | |
echo "Listing files in target directory:" | |
ls -lh ~/.m2/repository/com/ly/smart-doc | |
- name: Update Smart-Doc Version in pom.xml | |
run: | | |
mvn versions:set-property -Dproperty="smart-doc.version" -DnewVersion="${{ env.smart-doc-version }}" -DgenerateBackupPoms=false | |
- name: Build and Install Example Project | |
run: | | |
mvn -DskipTests=true install 2>&1 | tee logs/build-example-project.log | |
if grep -E "\[ERROR\]" logs/build-example-project.log; then | |
cat logs/build-example-project.log | |
exit 1 | |
fi | |
- name: Generate ${{ matrix.doc_type }} API Documentation | |
run: | | |
case ${{ matrix.doc_type }} in | |
rest) | |
mvn -DskipTests=true smart-doc:adoc 2>&1 | tee logs/rest-adoc.log | |
if grep -E "\[ERROR\]" logs/rest-adoc.log; then cat logs/rest-adoc.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:html 2>&1 | tee logs/rest-html.log | |
if grep -E "\[ERROR\]" logs/rest-html.log; then cat logs/rest-html.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:jmeter 2>&1 | tee logs/rest-jmeter.log | |
if grep -E "\[ERROR\]" logs/rest-jmeter.log; then cat logs/rest-jmeter.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:markdown 2>&1 | tee logs/rest-markdown.log | |
if grep -E "\[ERROR\]" logs/rest-markdown.log; then cat logs/rest-markdown.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:openapi 2>&1 | tee logs/rest-openapi.log | |
if grep -E "\[ERROR\]" logs/rest-openapi.log; then cat logs/rest-openapi.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:postman 2>&1 | tee logs/rest-postman.log | |
if grep -E "\[ERROR\]" logs/rest-postman.log; then cat logs/rest-postman.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:swagger 2>&1 | tee logs/rest-swagger.log | |
if grep -E "\[ERROR\]" logs/rest-swagger.log; then cat logs/rest-swagger.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:word 2>&1 | tee logs/rest-word.log | |
if grep -E "\[ERROR\]" logs/rest-word.log; then cat logs/rest-word.log; exit 1; fi | |
mvn test -Dtest=com.power.doc.torna.TornaApiTest 2>&1 | tee logs/rest-TornaApiTest.log | |
if grep -E "\[ERROR\]" logs/rest-TornaApiTest.log; then cat logs/rest-TornaApiTest.log; exit 1; fi | |
;; | |
dubbo) | |
mvn -DskipTests=true smart-doc:rpc-adoc 2>&1 | tee logs/rpc-adoc.log | |
if grep -E "\[ERROR\]" logs/rpc-adoc.log; then cat logs/rpc-adoc.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:rpc-html 2>&1 | tee logs/rpc-html.log | |
if grep -E "\[ERROR\]" logs/rpc-html.log; then cat logs/rpc-html.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:rpc-markdown 2>&1 | tee logs/rpc-markdown.log | |
if grep -E "\[ERROR\]" logs/rpc-markdown.log; then cat logs/rpc-markdown.log; exit 1; fi | |
;; | |
javadoc) | |
mvn -DskipTests=true smart-doc:javadoc-adoc 2>&1 | tee logs/javadoc-adoc.log | |
if grep -E "\[ERROR\]" logs/javadoc-adoc.log; then cat logs/javadoc-adoc.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:javadoc-html 2>&1 | tee logs/javadoc-html.log | |
if grep -E "\[ERROR\]" logs/javadoc-html.log; then cat logs/javadoc-html.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:javadoc-markdown 2>&1 | tee logs/javadoc-markdown.log | |
if grep -E "\[ERROR\]" logs/javadoc-markdown.log; then cat logs/javadoc-markdown.log; exit 1; fi | |
;; | |
websocket) | |
mvn -DskipTests=true smart-doc:websocket-adoc 2>&1 | tee logs/websocket-adoc.log | |
if grep -E "\[ERROR\]" logs/websocket-adoc.log; then cat logs/websocket-adoc.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:websocket-html 2>&1 | tee logs/websocket-html.log | |
if grep -E "\[ERROR\]" logs/websocket-html.log; then cat logs/websocket-html.log; exit 1; fi | |
mvn -DskipTests=true smart-doc:websocket-markdown 2>&1 | tee logs/websocket-markdown.log | |
if grep -E "\[ERROR\]" logs/websocket-markdown.log; then cat logs/websocket-markdown.log; exit 1; fi | |
;; | |
esac | |
- name: Upload ${{ matrix.doc_type }} API Documentation | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.doc_type }}-api-doc | |
path: ${{ github.workspace }}/target/doc/ | |
if-no-files-found: error | |
- name: Upload ${{ matrix.doc_type }} API Documentation Logs | |
if: failure() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: error-log-${{ matrix.doc_type }}-api-docs | |
path: logs | |
generate-grpc-api-doc: | |
needs: maven-plugin-build | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
concurrency: | |
group: generate-grpc-api-doc-${{ matrix.os }}-${{ github.event.pull_request.number }} | |
cancel-in-progress: true | |
steps: | |
- name: Checkout Example Project | |
uses: actions/checkout@v4 | |
with: | |
repository: smart-doc-group/smart-doc-example-cn | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Create Logs Directory | |
run: mkdir -p logs | |
shell: bash | |
- name: Download Artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: smart-doc-maven-plugin-jar | |
path: ./artifacts | |
- name: Move Files to Local Maven Repository | |
run: | | |
if [[ "${{ matrix.os }}" == "ubuntu-latest" || "${{ matrix.os }}" == "macos-latest" ]]; then | |
TARGET_DIR=~/.m2/repository/com/ly/smart-doc/ | |
mkdir -p "$TARGET_DIR" || echo "Directory already exists" | |
rsync -av --delete ./artifacts/ "$TARGET_DIR" | |
elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then | |
TARGET_DIR="$USERPROFILE\\.m2\\repository\\com\\ly\\smart-doc\\" | |
mkdir -p "$TARGET_DIR" || echo "Directory already exists" | |
cp -r ./artifacts/* "$TARGET_DIR" | |
fi | |
shell: bash | |
- name: Update Smart-Doc Version in pom.xml | |
run: | | |
mvn versions:set-property -Dproperty="smart-doc.version" -DnewVersion="${{ env.smart-doc-version }}" -DgenerateBackupPoms=false | |
- name: Build and Install Example Project | |
run: | | |
mvn -DskipTests=true install 2>&1 | tee logs/build-example-project.log | |
if grep -E "\[ERROR\]" logs/build-example-project.log; then | |
cat logs/build-example-project.log | |
exit 1 | |
fi | |
shell: bash | |
- name: Generate gRPC AsciiDoc Documentation | |
run: | | |
mvn -DskipTests=true smart-doc:grpc-adoc 2>&1 | tee logs/grpc-adoc.log | |
if grep -E "\[ERROR\]" logs/grpc-adoc.log; then cat logs/grpc-adoc.log; exit 1; fi | |
shell: bash | |
- name: Generate gRPC HTML Documentation | |
run: | | |
mvn -DskipTests=true smart-doc:grpc-html 2>&1 | tee logs/grpc-html.log | |
if grep -E "\[ERROR\]" logs/grpc-html.log; then cat logs/grpc-html.log; exit 1; fi | |
shell: bash | |
- name: Generate gRPC Markdown Documentation | |
run: | | |
mvn -DskipTests=true smart-doc:grpc-markdown 2>&1 | tee logs/grpc-markdown.log | |
if grep -E "\[ERROR\]" logs/grpc-markdown.log; then cat logs/grpc-markdown.log; exit 1; fi | |
shell: bash | |
- name: Upload gRPC API Documentation | |
uses: actions/upload-artifact@v4 | |
with: | |
name: gRPC-api-doc-${{ runner.os }} | |
path: ${{ github.workspace }}/target/doc/ | |
if-no-files-found: error | |
- name: Upload ${{ runner.os }} gRPC API Documentation Log | |
if: failure() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: error-log-${{ runner.os }}-grpc-api-doc | |
path: logs |