Skip to content

Commit 4062f0b

Browse files
committed
Put the annotations to the source file.
1 parent 5a4e493 commit 4062f0b

2 files changed

Lines changed: 72 additions & 3 deletions

File tree

.github/workflows/converter.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ name: Build and run the converter
22

33
on:
44
workflow_call:
5+
outputs:
6+
chm_name:
7+
description: The folder name representing the chm file name
8+
value: ${{ jobs.build_and_run.outputs.chm_name }}
59
inputs:
610
run_tests:
711
type: boolean
@@ -15,6 +19,8 @@ on:
1519
jobs:
1620

1721
build_and_run:
22+
outputs:
23+
chm_name: ${{ case(inputs.is_index, '', steps.get_chm_name.outputs.result) }}
1824
env:
1925
build_config: Release
2026
book_folder: ${{ github.event.repository.name }}${{ case(inputs.is_index, '/index', '') }}
@@ -29,6 +35,11 @@ jobs:
2935
with:
3036
path: ${{ env.book_folder }}
3137

38+
- name: Get the folder name representing the chm file name
39+
id: get_chm_name
40+
if: ${{ !inputs.is_index }}
41+
run: echo "result=$(ls ${{ env.book_folder }}/en)" >> "$GITHUB_OUTPUT"
42+
3243
- name: Checkout Index with Converter
3344
uses: actions/checkout@v6
3445
with:

.github/workflows/publish_book.yml

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
is_index:
77
type: boolean
88

9-
109
jobs:
1110

1211
convert:
@@ -33,23 +32,82 @@ jobs:
3332
name: converted
3433
path: pages
3534

35+
- name: Checkout book.xml
36+
if: ${{ !inputs.is_index }}
37+
uses: actions/checkout@v6
38+
with:
39+
sparse-checkout: |
40+
en/${{ jobs.convert.outputs.chm_name }}/book.xml
41+
sparse-checkout-cone-mode: false
42+
path: book
43+
3644
- name: Install tools
3745
run: |
3846
sudo apt-get install -y webp minify parallel
3947
4048
- name: Setup Optimization Helpers
4149
run: |
4250
cat << 'EOF' > helpers.sh
51+
get_source_path() {
52+
local file=$1
53+
54+
file="${file#pages/}"
55+
56+
if [ "${{ inputs.is_index }}" = "true" ]; then
57+
if [[ "$file" =~ ^[a-z]{2}/ ]] || [[ "$file" =~ ^programming/ ]]; then
58+
echo "index/${file}"
59+
else
60+
echo "converter/templates/wwwroot/${file}"
61+
fi
62+
else
63+
if [[ "$file" =~ ^[a-z]{2}/ ]]; then
64+
local lang="${file%%/*}"
65+
echo "${lang}/${{ jobs.convert.outputs.chm_name }}/${file#*/}"
66+
else
67+
if [[ "$file" != */index.html ]]; then
68+
echo "$file"
69+
return
70+
fi
71+
72+
# Find the url needed in the book.xml
73+
local dir_path="${file%/index.html}"
74+
local last_folder="${dir_path##*/}"
75+
local lang="en"
76+
local url=""
77+
78+
if [[ "$last_folder" =~ ^[a-z]{2}$ ]]; then
79+
lang="$last_folder"
80+
url="${dir_path%/$lang}"
81+
else
82+
url="$dir_path"
83+
fi
84+
85+
local source_page_path
86+
87+
local xml_path="book/en/${{ jobs.convert.outputs.chm_name }}/book.xml"
88+
local u="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
89+
local l="abcdefghijklmnopqrstuvwxyz"
90+
91+
source_page_path=$(xmllint --xpath "string(//page[translate(@url, '$u', '$l')='$url']/@file)" "$xml_path" 2>/dev/null)
92+
93+
echo "${lang}/${source_page_path}"
94+
fi
95+
fi
96+
}
97+
4398
log_msg() {
4499
local status=$1; local file=$2; local msg=$3
100+
local source_file=$(get_source_path "$file")
101+
45102
if [ $status -eq 0 ]; then
46103
if [ -n "$msg" ]; then
47-
echo "::notice file=$file::Optimized \`$file\` despite \`$msg\`"
104+
echo "::notice file=$source_file::Optimized \`$file\` despite \`$msg\`"
48105
fi
49106
else
50-
echo "::warning file=$file::Skipped \`$file\` because \`$msg\`"
107+
echo "::warning file=$source_file::Skipped \`$file\` because \`$msg\`"
51108
fi
52109
}
110+
export -f get_source_path
53111
export -f log_msg
54112
EOF
55113
chmod +x helpers.sh

0 commit comments

Comments
 (0)