Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Build and Push Standard Library Documentation #42

Build and Push Standard Library Documentation

Build and Push Standard Library Documentation #42

Workflow file for this run

name: "Build and Push Standard Library Documentation"
on:
workflow_dispatch:
workflow_run:
workflows:
- Java CI
- Publish Release
types:
- completed
jobs:
check:
runs-on: ubuntu-latest
name: Test packages changed-files
outputs:
any_changed: ${{ steps.changed-files-in-packages.outputs.any_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get changed files in packages
id: changed-files-in-packages
uses: tj-actions/changed-files@v45
with:
files: packages/**
build:
runs-on: ubuntu-latest
needs: check
if: contains(needs.check.outputs.any_changed, 'true')
outputs:
jolie_version: ${{ steps.jolie_version.outputs.jolie_version }}
summary_string: ${{ steps.generate.outputs.summary_string }}
steps:
- uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: 21
cache: 'maven'
- name: Build with Maven
run: mvn install --file pom.xml
- name: "Set up JOLIE_HOME environment"
shell: bash
run: |
echo "JOLIE_HOME=${{ github.workspace }}/dist/jolie" >> "$GITHUB_ENV"
- name: Set up PATH environment
shell: bash
run: |
echo "${{ github.workspace }}/dist/launchers/unix" >> $GITHUB_PATH
- name: Generate Documentation
id: generate
shell: bash
run: |
mkdir -p docs
SUMMARY=""
LINTERIGNORE="<!-- markdownlint-disable -->\n<!-- editorconfig-checker-disable -->\n<!-- cSpell:disable -->\n\n"
find ${{ github.workspace }}/packages -maxdepth 1 -type f -not -regex ".*_.*" -print | sort | ( while read -r file; do
MODULE_NAME="$(basename -- "$file")"
SERVICE_NAME="$(a=($(cat $file | grep -o -E '^service.*{$'));echo ${a[1]})"
SUMMARY="$SUMMARY - [${MODULE_NAME%.ol}](language-tools-and-standard-library/standard-library-api/${MODULE_NAME%.ol}.md)\n"
# run joliedoc
joliedoc "$file" --internals --out-type md
# insert module name and move necessary file to docs
IPLOCALFILES="$(grep -rnwl 'joliedoc/' --exclude="index.md" --exclude="Overview.md" -e "local")"
# select input port document file
if echo $IPLOCALFILES | tr ' ' '\n'| grep -qiF "$SERVICE_NAME"; then
# try find the file by service name
IPLOCALFILE="$(echo $IPLOCALFILES | tr ' ' '\n' | grep -iF $SERVICE_NAME)"
else
# select first file
IPLOCALFILE="$(echo $IPLOCALFILES | tr ' ' '\n' | head -1)"
fi
# insert service name
sed -i "s/# Service/${LINTERIGNORE}# Service $SERVICE_NAME\n\n> from ${MODULE_NAME%.ol} import $SERVICE_NAME/" "$IPLOCALFILE"
# move file to docs
mv "$IPLOCALFILE" "${{ github.workspace }}/docs/${MODULE_NAME%.ol}.md"
echo "generated doc for '$file', found '$SERVICE_NAME', moved generated doc file '$IPLOCALFILE' to 'docs/$MODULE_NAME'";
# remove joliedoc
rm -rf ${{ github.workspace }}/joliedoc
done
echo "summary_string<<EOF" >> $GITHUB_OUTPUT
echo "$SUMMARY" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT )
- name: Cache Docs
id: cache-docs
uses: actions/cache/save@v4
with:
path: docs
key: docs-${{ github.sha }}
- name: Retrieve Jolie version
id: jolie_version
run:
echo "jolie_version=$(cat pom.xml | grep -o -P '(?<=<jolie.version>).*(?=</jolie.version>)')" >> $GITHUB_OUTPUT
push:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache/restore@v4
id: cache
with:
path: docs
key: docs-${{ github.sha }}
- name: echo jolie version
run: echo ${{ needs.build.outputs.jolie_version }}
- name: get jolie docs branch
id: jolie_branch
run: echo "jolie_branch=v$(echo ${{ needs.build.outputs.jolie_version }} | sed -E 's/(.*)([[:digit:]]+)/\1x/')" >> $GITHUB_OUTPUT
- name: Push to docs repository
env:
API_TOKEN_GITHUB: ${{ secrets.JOLIE_DOCS_WRITE_CONTENTS }}
BRANCH: ${{ steps.jolie_branch.outputs.jolie_branch }}
DOC_PATH: src/language-tools-and-standard-library/standard-library-api
run: |
CLONE_DIR=$(mktemp -d)
DEST_COPY=$CLONE_DIR/$DOC_PATH
echo "Clone docs repository"
git config --global user.email "[email protected]"
git config --global user.name "GitAction"
git clone --single-branch --branch "$BRANCH" "https://x-access-token:[email protected]/jolie/docs.git" "$CLONE_DIR"
echo "Copy generated doc to docs repository"
mkdir -p "$DEST_COPY"
cp -R "docs/." "$DEST_COPY"
cd "$CLONE_DIR"
# replace SUMMARY.md
SUMMARY="${{ needs.build.outputs.summary_string }}"
sed -z -i "s|/standard-library-api/README.md).*# Errors|/standard-library-api/README.md)\n$SUMMARY\n\n# Errors|" src/SUMMARY.md
echo "Add git commit"
git add .
if git status | grep -q "Changes to be committed"
then
git commit --message "Update stdlib docs from Jolie commit/${GITHUB_SHA}"
echo "Pushing git commit"
git push -u origin HEAD:"$BRANCH"
else
echo "No changes detected"
fi