Skip to content

Let's not create from cache for now, as ul is changed. #316

Let's not create from cache for now, as ul is changed.

Let's not create from cache for now, as ul is changed. #316

Workflow file for this run

name: Publish all books to Pages
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
publish_index:
uses: ./.github/workflows/publish_index.yml
setup_array:
runs-on: ubuntu-slim
outputs:
sites: ${{ steps.set_sites.outputs.sites }}
steps:
- name: Writing the book url names into a sharable matrix input
id: set_sites
run: |
{
echo 'sites<<EOF'
cat << 'JSON'
[
"user-guide",
"tutorials",
"quick-help",
"origin-help",
"x-function",
"originc",
"labtalk",
"python",
"externalpython",
"com",
"labview",
"app",
"appdev",
"codebuild",
"orglab",
"license"
]
JSON
echo 'EOF'
} >> "$GITHUB_OUTPUT"
start_array:
name: Start ${{ matrix.site }} deployment
needs: [setup_array, publish_index]
runs-on: ubuntu-slim
environment: deploy
env:
GH_TOKEN: ${{ secrets.PAT_DOC_WORKFLOW }}
strategy:
matrix:
site: ${{ fromJson(needs.setup_array.outputs.sites) }}
steps:
- name: Dispatch deploy.yml and capture the run url
id: dispatch
run: echo "deploy_run_url=$(gh workflow run deploy.yml --repo originlab/${{ matrix.site }})" >> "$GITHUB_ENV"
- name: Save the run id
run: echo "$deploy_run_url" | grep -oE "[0-9]+$" >> run_id.txt
- uses: actions/upload-artifact@v7
with:
name: run_id-${{ matrix.site }}
path: run_id.txt
retention-days: 1
get_result:
name: The ${{ matrix.site }} deployment
needs: [setup_array, start_array]
runs-on: ubuntu-slim
environment: deploy_watch
env:
GH_TOKEN: ${{ secrets.PAT_DOC_WORKFLOW }}
strategy:
fail-fast: false
matrix:
site: ${{ fromJson(needs.setup_array.outputs.sites) }}
steps:
- name: Download run_id-${{ matrix.site }}
uses: actions/download-artifact@v8
with:
name: run_id-${{ matrix.site }}
- name: Set $deploy_run_id
run: echo "deploy_run_id=$(cat run_id.txt)" >> "$GITHUB_ENV"
- name: Delete run_id-${{ matrix.site }}
run: |
gh api /repos/originlab/originlab.github.io/actions/runs/$GITHUB_RUN_ID/artifacts \
-q '.artifacts[] | select(.name == "run_id-${{ matrix.site }}") | .id' \
| xargs -I {} gh api --method DELETE /repos/originlab/originlab.github.io/actions/artifacts/{}
- name: Watch the deployment
run: gh run watch $deploy_run_id -R originlab/${{ matrix.site }} -i 10 --exit-status
- name: Find SHA, job IDs, and durations
run: |
run_view_json=$(gh run view "$deploy_run_id" -R "originlab/${{ matrix.site }}" --json jobs,headSha)
echo "$run_view_json" | jq -r '
(.jobs[] | select(.name | startswith("publish_book / convert"))) as $build
| (.jobs[] | select(.name == "publish_book / optimize")) as $optimize
| "run_sha=\(.headSha)",
"build_job_id=\($build.databaseId)",
"optimize_job_id=\($optimize.databaseId)",
"build_duration=\(($build.completedAt | fromdateiso8601) - ($build.startedAt | fromdateiso8601))",
"optimize_duration=\(($optimize.completedAt | fromdateiso8601) - ($optimize.startedAt | fromdateiso8601))"
' >> "$GITHUB_ENV"
echo 'Done.'
- name: Setup helper scripts
run: |
cat << 'EOF' > helpers.sh
#!/bin/bash
get_human_time() {
local total_seconds=$1
if [ "$total_seconds" -eq 0 ]; then
echo "0s"
return
fi
local hours=$((total_seconds / 3600))
local minutes=$(((total_seconds % 3600) / 60))
local seconds=$((total_seconds % 60))
local result=""
[ $hours -gt 0 ] && result+="${hours}h "
[ $minutes -gt 0 ] && result+="${minutes}m "
[ $seconds -gt 0 ] && result+="${seconds}s"
# Trim trailing spaces
echo "$result" | xargs
}
get_sorted_groups() {
awk -F'\t' '
{
k = $1; v = $2
if (k != "" && v != "") {
n[k]++
vs[k] = vs[k] "#" v
}
}
END {
for (k in n) {
print n[k] "\t" k "\t" vs[k]
}
}
' \
| sort -rn -t$'\t' -k1,1
}
get_human_bytes() {
local bytes=$1
if [ -z "$bytes" ] || [ "$bytes" -eq 0 ]; then
echo "0 B"
return
fi
if [ "$bytes" -gt 1048576 ]; then
awk "BEGIN {printf \"%.1f MB\", $bytes/1048576}"
else
awk "BEGIN {printf \"%.1f KB\", $bytes/1024}"
fi
}
EOF
chmod +x helpers.sh
- name: Summarize the conversion run
run: |
source ./helpers.sh
echo "# Conversion <sub><sup>:stopwatch:$(get_human_time "$build_duration")</sup></sub>" >> "$GITHUB_STEP_SUMMARY"
gh run view $deploy_run_id -j $build_job_id -R originlab/${{ matrix.site }} --log \
| awk '/generator\.dll"/ {f=1} /upload-artifact/ {f=0} f' \
| cut -f3- | cut -d' ' -f2- \
| sed -E \
-e 's/\r//g' \
-e 's/\^\[\[[0-9;]*[a-zA-Z]//g' \
-e 's/^##\[group\](.*)/<details><summary>\1<\/summary>\n/g' \
-e 's/^##\[endgroup\]/<\/details>/g' \
-e 's/^##\[warning\](.*)/> [!WARNING]\n> \1/g' \
| awk -v sha="$run_sha" -v site="${{ matrix.site }}" '
/^File: / {
file_path = $2
print "- File: [" file_path "](https://github.com/originlab/" site "/blob/" sha "/" file_path ")"
next
}
/^[[:space:]]+Ln [0-9]+,/ {
match($0, /Ln [0-9]+/)
line_num = substr($0, RSTART + 3, RLENGTH - 3)
print " - [Ln " line_num ", " substr($0, index($0, "Col")) "](https://github.com/originlab/" site "/blob/" sha "/" file_path "#L" line_num ")"
next
}
{ print }
' >> "$GITHUB_STEP_SUMMARY"
echo 'Done.'
- name: Summarize the optimization run
run: |
source ./helpers.sh
echo "# Optimization <sub><sup>:stopwatch:$(get_human_time "$optimize_duration")</sup></sub>" >> "$GITHUB_STEP_SUMMARY"
opt_log=$(gh run view $deploy_run_id -j $optimize_job_id -R originlab/${{ matrix.site }} --log \
| awk '/find pages\// {f=1} /upload-artifact/ {f=0} f' \
| cut -f3- | cut -d' ' -f2- \
| sed -E -e 's/\r//g' -e 's/\^\[\[[0-9;]*[a-zA-Z]//g')
warnings=$(echo "$opt_log" | grep '^##\[warning\]' || true)
notices=$(echo "$opt_log" | grep '^##\[notice\]' || true)
if [ -z "$warnings" ] && [ -z "$notices" ]; then
echo ':white_check_mark: All files are optimized without problems.' >> "$GITHUB_STEP_SUMMARY"
else
if [ -n "$warnings" ]; then
echo "$warnings" \
| sed -E 's/^##\[warning\]Skipped `(.*)` because `(.*)`/\2\t\1/' \
| get_sorted_groups \
| awk -F'\t' '
{
cnt = $1; msg = $2; fls = $3
gsub(/#/, "\n- ", fls)
print "\n> [!WARNING]"
print "> " cnt " file(s) were skipped because :x:`" msg "`"
print fls
}
' >> "$GITHUB_STEP_SUMMARY"
fi
if [ -n "$notices" ]; then
echo "$notices" \
| sed -E 's/^##\[notice\]Optimized `(.*)` despite `(.*)`/\2\t\1/' \
| get_sorted_groups \
| awk -F'\t' '
{
cnt = $1; msg = $2; fls = $3
gsub(/#/, "\n- ", fls)
print "\n> [!NOTE]"
print "> " cnt " file(s) were optimized despite :warning:`" msg "`"
print "<details><summary>Show affected files</summary>"
print fls
print "</details>"
}
' >> "$GITHUB_STEP_SUMMARY"
fi
fi
# Need some single quote to workaround a VS colorizer bug
echo 'Done.'
- name: Summarize artifacts
run: |
source ./helpers.sh
artifacts_json=$(gh api /repos/originlab/${{ matrix.site }}/actions/runs/$deploy_run_id/artifacts)
converted_size=$(echo "$artifacts_json" | jq -r '.artifacts[] | select(.name == "converted") | .size_in_bytes // 0' | head -n 1)
optimized_size=$(echo "$artifacts_json" | jq -r '.artifacts[] | select(.name == "optimized") | .size_in_bytes // 0' | head -n 1)
if [ -z "$converted_size" ] || [ "$converted_size" -eq 0 ] || [ -z "$optimized_size" ] || [ "$optimized_size" -eq 0 ]; then
header="# Artifacts"
else
bytes_delta=$((converted_size - optimized_size))
if [ "$bytes_delta" -ge 0 ]; then
desc_delta=":green_circle: Saved"
else
desc_delta=":yellow_circle: Increased"
bytes_delta=$((optimized_size - converted_size))
fi
pct_delta=$(( 100 * bytes_delta / converted_size ))
size_delta=$(get_human_bytes "$bytes_delta")
header="# Artifacts <sub><sup>$desc_delta $size_delta ($pct_delta%)</sup></sub>"
fi
echo "$header" >> "$GITHUB_STEP_SUMMARY"
echo "| Name | Size |" >> "$GITHUB_STEP_SUMMARY"
echo "| :--- | ---: |" >> "$GITHUB_STEP_SUMMARY"
echo "$artifacts_json" \
| jq -c '[.artifacts[]] | sort_by(.size_in_bytes) | reverse | .[]' \
| while read -r artifact; do
name=$(echo "$artifact" | jq -r '.name')
size_bytes=$(echo "$artifact" | jq -r '.size_in_bytes')
size_human=$(get_human_bytes "$size_bytes")
echo "| $name | $size_human |" >> "$GITHUB_STEP_SUMMARY"
done
echo 'Done.'
- name: Print additional links
run: |
{
echo '# Links'
echo "- Workflow Run: https://github.com/originlab/${{ matrix.site }}/actions/runs/$deploy_run_id"
echo "- Deployed URL: https://docs.originlab.com/${{ matrix.site }}"
} >> "$GITHUB_STEP_SUMMARY"
echo 'Done.'