Missed escaping a backtick again. #259
This file contains hidden or 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: 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: Watch ${{ matrix.site }} deployment | |
| needs: [setup_array, start_array] | |
| runs-on: ubuntu-slim | |
| environment: deploy_watch | |
| env: | |
| GH_TOKEN: ${{ secrets.PAT_DOC_WORKFLOW }} | |
| strategy: | |
| 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: Set $build_job_id | |
| run: echo "build_job_id=$(gh run view $deploy_run_id -R originlab/${{ matrix.site }} | grep 'publish_book / convert' | grep -oP '\(ID \K\d+')" >> "$GITHUB_ENV" | |
| - name: Set $optimize_job_id | |
| run: echo "optimize_job_id=$(gh run view $deploy_run_id -R originlab/${{ matrix.site }} | grep 'publish_book / optimize' | grep -oP '\(ID \K\d+')" >> "$GITHUB_ENV" | |
| - name: Summarize the converter run | |
| run: | | |
| echo '# Converter run' >> "$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><pre>/g' \ | |
| -e 's/^##\[endgroup\]/<\/pre><\/details>/g' \ | |
| -e 's/^##\[warning\](.*)/> [!WARNING]\n> \1/g' \ | |
| >> "$GITHUB_STEP_SUMMARY" | |
| - name: Summarize the optimization run | |
| run: | | |
| printf '# Optimization run\n' >> "$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 | |
| printf "All files are optimized without problems.\n" >> "$GITHUB_STEP_SUMMARY" | |
| else | |
| if [ -n "$warnings" ]; then | |
| echo "$warnings" | sed -E 's/^##\[warning\]Skipped `(.*)` because `(.*)`/\2\t\1/' \ | |
| | awk -F'\t' ' | |
| { | |
| msg = $1; file = $2 | |
| if (msg != "" && file != "") { | |
| count[msg]++ | |
| files[msg] = files[msg] "- " file "\n" | |
| } | |
| } | |
| END { | |
| for (msg in count) { | |
| print "\n> [!WARNING]" | |
| print "> " count[msg] " file(s) were skipped because `" msg "`\n" | |
| print "<details><summary>Show affected files</summary><pre>\n" | |
| print files[msg] | |
| print "</pre></details>" | |
| } | |
| } | |
| ' >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| if [ -n "$notices" ]; then | |
| echo "$notices" | sed -E 's/^##\[notice\]Optimized `(.*)` despite `(.*)`/\2\t\1/' \ | |
| | awk -F'\t' ' | |
| { | |
| msg = $1; file = $2 | |
| if (msg != "" && file != "") { | |
| count[msg]++ | |
| files[msg] = files[msg] "- " file "\n" | |
| } | |
| } | |
| END { | |
| for (msg in count) { | |
| print "\n> [!NOTE]" | |
| print "> " count[msg] " file(s) were optimized despite `" msg "`\n" | |
| print "<details><summary>Show affected files</summary><pre>\n" | |
| print files[msg] | |
| print "</pre></details>" | |
| } | |
| } | |
| ' >> "$GITHUB_STEP_SUMMARY" | |
| fi | |
| fi | |
| # Need some single quote to workaround a VS colorizer bug | |
| echo 'Done.' | |
| - name: Summarize artifacts | |
| run: | | |
| echo '# Artifacts' >> "$GITHUB_STEP_SUMMARY" | |
| echo '| Name | Size |' >> "$GITHUB_STEP_SUMMARY" | |
| echo '| :--- | ---: |' >> "$GITHUB_STEP_SUMMARY" | |
| gh api /repos/originlab/${{ matrix.site }}/actions/runs/$deploy_run_id/artifacts \ | |
| -q '[.artifacts[]] | sort_by(.size_in_bytes) | reverse | .[] | | |
| if .size_in_bytes < 1048576 then | |
| "| \(.name) | \((.size_in_bytes/1024*10|round)/10) KB |" | |
| else | |
| "| \(.name) | \((.size_in_bytes/1024/1024*10|round)/10) MB |" | |
| end' >> "$GITHUB_STEP_SUMMARY" |