Skip to content

Commit 0dbc6a8

Browse files
committed
support --versioned_filenames
1 parent ee2272b commit 0dbc6a8

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

.github/workflows/docker-publish.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ jobs:
103103
uses: trustedcomputinggroup/markdown@latest
104104
with:
105105
input-md: guide.tcg
106+
extra-build-options: "--versioned_filenames"
106107
output-pdf: guide.pdf
107108
output-tex: guide.tex
108109
output-docx: guide.docx
@@ -111,7 +112,7 @@ jobs:
111112
uses: actions/upload-artifact@master
112113
with:
113114
name: PDF
114-
path: guide.pdf
115+
path: guide.*.pdf
115116

116117
# (In case of release only)
117118
# Use the container we just built to build the guide and attach it to the release
@@ -149,24 +150,26 @@ jobs:
149150
uses: trustedcomputinggroup/markdown@latest
150151
with:
151152
input-md: guide.tcg
152-
extra-build-options: "--gitstatus --plain_quotes"
153+
extra-build-options: "--versioned_filenames"
153154
output-pdf: guide.pdf
154155
output-docx: guide.docx
155156

156157
- name: Upload to release
157158
uses: svenstaro/upload-release-action@v2
158159
with:
159160
repo_token: ${{ secrets.GITHUB_TOKEN }}
160-
file: guide.pdf
161+
file: guide.*.pdf
161162
tag: ${{ github.ref }}
162163
overwrite: true
164+
file_glob: true
163165
body: "Guide (PDF)"
164166

165167
- name: Upload to release
166168
uses: svenstaro/upload-release-action@v2
167169
with:
168170
repo_token: ${{ secrets.GITHUB_TOKEN }}
169-
file: guide.docx
171+
file: guide.*.docx
170172
tag: ${{ github.ref }}
171173
overwrite: true
174+
file_glob: true
172175
body: "Guide (Word)"

.github/workflows/render-samples.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ jobs:
6868
*.lof
6969
*.lot
7070
*.toc
71+
*.convert.pdf
7172
key: latex-${{ github.run_id }}
7273
restore-keys: latex
7374

7475
- name: Run the action on guide
7576
uses: trustedcomputinggroup/markdown@latest
7677
with:
7778
input-md: guide.tcg
79+
extra-build-options: "--versioned_filenames"
7880
output-pdf: guide.pdf
7981
output-tex: guide.tex
8082
output-docx: guide.docx
@@ -83,17 +85,17 @@ jobs:
8385
uses: actions/upload-artifact@master
8486
with:
8587
name: PDF
86-
path: guide.pdf
88+
path: guide.*.pdf
8789

8890
- name: Upload TeX
8991
uses: actions/upload-artifact@master
9092
with:
9193
name: TeX
92-
path: guide.tex
94+
path: guide.*.tex
9395

9496
- name: Upload Docx
9597
uses: actions/upload-artifact@master
9698
with:
9799
name: Word
98-
path: guide.docx
100+
path: guide.*.docx
99101

build.sh

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ latex_output=""
1111
pdflog_output=""
1212
table_rules="no"
1313
block_quotes_are_informative_text="no"
14+
versioned_filenames="no"
1415

1516
# Start up the dbus daemon (drawio will use it later)
1617
dbus-daemon --system || echo "Failed to start dbus daemon"
@@ -49,10 +50,11 @@ print_usage() {
4950
echo " --table_rules: legacy flag, no effect (default starting with 0.9.0)"
5051
echo " --plain_quotes: legacy flag, no effect (default starting with 0.9.0)"
5152
echo " --noplain_quotes: use block-quote syntax as informative text"
53+
echo " --versioned_filenames: insert version information before the file extension for outputs"
5254
}
5355

5456

55-
if ! options=$(getopt --longoptions=help,puppeteer,notmp,gitversion,gitstatus,nogitversion,table_rules,plain_quotes,noplain_quotes,pdf:,latex:,pdflog:,docx:,html:,resourcedir: --options="" -- "$@"); then
57+
if ! options=$(getopt --longoptions=help,puppeteer,notmp,gitversion,gitstatus,nogitversion,table_rules,plain_quotes,noplain_quotes,versioned_filenames,pdf:,latex:,pdflog:,docx:,html:,resourcedir: --options="" -- "$@"); then
5658
echo "Incorrect options provided"
5759
print_usage
5860
exit 1
@@ -118,6 +120,10 @@ while true; do
118120
table_rules="yes"
119121
shift
120122
;;
123+
--versioned_filenames)
124+
versioned_filenames="yes"
125+
shift
126+
;;
121127
--help)
122128
print_usage
123129
shift
@@ -263,6 +269,48 @@ if test "${do_gitversion}" == "yes"; then
263269

264270
fi # Done with git version handling
265271

272+
prefix_filename() {
273+
local PREFIX=$1
274+
local FULL_FILENAME=$2
275+
local DIRNAME=$(dirname "${FULL_FILENAME}")
276+
local FILENAME=$(basename "${FULL_FILENAME}")
277+
local EXTENSION="${FILENAME##*.}"
278+
local STRIPPED="${FILENAME%.*}"
279+
local RESULT=""
280+
if [ ! -z "${DIRNAME}" ]; then
281+
RESULT="${DIRNAME}/"
282+
fi
283+
RESULT="${RESULT}${STRIPPED}${PREFIX}.${EXTENSION}"
284+
echo "${RESULT}"
285+
}
286+
287+
# Rename output files based on version info
288+
if [ "${versioned_filenames}" == "yes" ]; then
289+
version_prefix=""
290+
if [ ! -z "${GIT_VERSION}" ]; then
291+
version_prefix="${version_prefix}.${GIT_VERSION}"
292+
fi
293+
if [ ! -z "${GIT_PRERELEASE}" ]; then
294+
version_prefix="${version_prefix}.${GIT_PRERELEASE}"
295+
fi
296+
if [ ! -z "${GIT_REVISION}" ]; then
297+
version_prefix="${version_prefix}.${GIT_REVISION}"
298+
fi
299+
300+
if [ ! -z "${docx_output}" ]; then
301+
docx_output=$(prefix_filename "${version_prefix}" "${docx_output}")
302+
fi
303+
if [ ! -z "${pdf_output}" ]; then
304+
pdf_output=$(prefix_filename "${version_prefix}" "${pdf_output}")
305+
fi
306+
if [ ! -z "${latex_output}" ]; then
307+
latex_output=$(prefix_filename "${version_prefix}" "${latex_output}")
308+
fi
309+
if [ ! -z "${html_output}" ]; then
310+
html_output=$(prefix_filename "${version_prefix}" "${html_output}")
311+
fi
312+
fi
313+
266314
echo "Starting Build with"
267315
echo "file: ${input_file}"
268316
echo "docx: ${docx_output:-none}"

0 commit comments

Comments
 (0)