Skip to content

Commit e091857

Browse files
authored
support parsing git tags for document status (#73)
This change updates --gitstatus to parse the document status at revision 0 based on the first letter of the tag. It also causes everything after revision 0 to be considered a draft. Also, if revision is 0, it's not included in the document metadata (so the final document just has a Version).
1 parent 66caaec commit e091857

File tree

3 files changed

+143
-8
lines changed

3 files changed

+143
-8
lines changed

build.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,19 +184,32 @@ if test "${do_gitversion}" == "yes"; then
184184
fi
185185
fi
186186

187+
# Before scrubbing, grab the first character from 'major_minor'
188+
first_char=${major_minor:0:1}
189+
187190
# scrub any leading non-numerical arguments from major_minor, ie v4.0, scrub any other nonsense as well
188191
major_minor="$(tr -d "[:alpha:]" <<< "${major_minor}")"
189192

190-
extra_pandoc_options="--metadata=version:${major_minor} --metadata=revision:${revision}"
191-
193+
extra_pandoc_options+=" --metadata=version:${major_minor}"
194+
195+
# Revision 0 = no revision
196+
if [ "${revision}" -ne "0" ]; then
197+
extra_pandoc_options+=" --metadata=revision:${revision}"
198+
fi
199+
192200
# Do we set document status based on git version?
193201
if [ "${do_gitstatus}" == "yes" ]; then
194-
if [ "${revision}" == "0" ]; then
202+
# If revision is 0 and the first character of the tag is 'p' (for Published)
203+
if [ "${revision}" == "0" ] && [ "${first_char}" == "p" ]; then
195204
status="PUBLISHED"
205+
# If revision is 0 and the first character of the tag is 'r' (for Review)
206+
elif [ "${revision}" == "0" ] && [ "${first_char}" == "r" ]; then
207+
status="PUBLIC REVIEW"
208+
# Revision is not 0, or the tag doesn't begin with a p or an r.
196209
else
197210
status="DRAFT"
198211
fi
199-
extra_pandoc_options+=" --metadata=status:${status}"
212+
extra_pandoc_options+=" --metadata=status:\"${status}\""
200213
fi
201214

202215
fi # Done with git version handling

guide.md

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ to get started a little more quickly. There's a little green "Use this template"
103103

104104
![The "Use this template" button](use_template.jpg){#fig:use-template-button width=50%}
105105

106-
## GitHub Actions
106+
## GitHub Actions {#sec:basic-gh-action}
107107

108108
Even if you used the template repository, please double-check this. As the tools are being actively developed,
109109
there is probably a newer version of the tools available for you!
@@ -750,6 +750,121 @@ $$ HMAC(K, "text") \coloneq H((\bar{K} \oplus OPAD) \Vert H((\bar{K} \oplus IPAD
750750

751751
$$ HMAC(K, "text") \coloneq H((\bar{K} \oplus OPAD) \Vert H((\bar{K} \oplus IPAD) \Vert "text")) $$ {#eq:hmac-iso-bad-kerning}
752752

753+
# Advanced Features
754+
755+
In the GitHub action YAML, you can enable some advanced features.
756+
757+
## Git Version Parsing
758+
759+
Use `extra-build-options: "--gitversion"` to let Git number the document for you.
760+
761+
```yaml
762+
- name: Run the action
763+
uses: trustedcomputinggroup/markdown@latest
764+
with:
765+
extra-build-options: "--gitversion"
766+
```
767+
768+
When you do this, the tool will check for a recent [release](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) in the repository. It will use the major.minor
769+
version number from the tag as the document version, and the number of commits since that tag as the revision.
770+
This way, you don't have to manually update the version or revision numbers in your document!
771+
772+
### Conventions for Release Naming
773+
774+
The tooling expects the following conventions for tagging your releases:
775+
776+
* `vX.Y` indicates a regular draft of version X.Y.
777+
* `rX.Y` indicates a review draft of version X.Y.
778+
* `pX.Y` indicates a published version.
779+
780+
## Git Status Parsing
781+
782+
Use `extra-build-options: "--gitstatus"` to let Git number AND set the status of the document for you.
783+
784+
```yaml
785+
- name: Run the action
786+
uses: trustedcomputinggroup/markdown@latest
787+
with:
788+
extra-build-options: "--gitstatus"
789+
```
790+
791+
See [Conventions](#conventions-for-release-naming). When `--gitstatus` is enabled, the leading character
792+
(which is expected to be one of: `v`, `r`, or `p`) is used to determine the document's status at
793+
revision 0. Commits on top of any type of version are always considered to be drafts.
794+
795+
## Running Pandoc with Releases
796+
797+
@sec:basic-gh-action shows an example of a GitHub action that automatically runs Pandoc on every
798+
pull request and push to the repository.
799+
800+
You may wish to run the workflow on releases, and attach the results to the release page, for
801+
example to have it generate a docx file to send to the Technical Committee for review, or when
802+
publishing a final version of a document.
803+
804+
Use the example below as a guide for how you can have Pandoc automatically render the doc
805+
(maybe basing its [status](#git-status-parsing) on the released tag).
806+
807+
```yaml
808+
# Render the spec to PDF and Word on releases.
809+
810+
name: Render (PDF and Word)
811+
812+
on:
813+
release:
814+
types: [released]
815+
816+
jobs:
817+
render-spec-pdf:
818+
runs-on: ubuntu-latest
819+
container:
820+
image: ghcr.io/trustedcomputinggroup/pandoc:0.7.1
821+
name: Render (pdf)
822+
steps:
823+
- name: Checkout
824+
uses: actions/checkout@v3
825+
826+
- name: Render
827+
uses: trustedcomputinggroup/[email protected]
828+
with:
829+
input-md: spec.md
830+
extra-build-options: "--gitstatus"
831+
output-pdf: spec.pdf
832+
833+
- name: Upload to release
834+
uses: svenstaro/upload-release-action@v2
835+
with:
836+
repo_token: ${{ secrets.GITHUB_TOKEN }}
837+
file: spec.pdf
838+
tag: ${{ github.ref }}
839+
overwrite: true
840+
body: "Part 1 (PDF)"
841+
842+
render-spec-docx:
843+
runs-on: ubuntu-latest
844+
container:
845+
image: ghcr.io/trustedcomputinggroup/pandoc:0.6.8
846+
name: Render Part 1 (docx)
847+
steps:
848+
- name: Checkout
849+
uses: actions/checkout@v3
850+
851+
- name: Render
852+
uses: trustedcomputinggroup/[email protected]
853+
with:
854+
input-md: spec.md
855+
extra-build-options: "--gitstatus"
856+
output-docx: spec.docx
857+
858+
- name: Upload to release
859+
uses: svenstaro/upload-release-action@v2
860+
with:
861+
repo_token: ${{ secrets.GITHUB_TOKEN }}
862+
file: spec.docx
863+
tag: ${{ github.ref }}
864+
overwrite: true
865+
body: "Part 1 (Word)"
866+
```
867+
753868
\beginappendices
754869

755870
# Reporting Issues with the Tools

template/eisvogel.latex

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,13 @@ $if(template)$
641641
{}
642642
$endif$
643643

644-
\ifthenelse{\equal{\detokenize{$status$}}{\detokenize{DRAFT}}}
644+
\ifthenelse{\equal{\detokenize{$status$}}{\detokenize{PUBLISHED}}}
645+
{}
645646
{
646647
\usepackage[angle=0]{draftwatermark}
647648
% use an image for the watermark so it doesn't interfere with selection
648649
\SetWatermarkText{\includegraphics{/resources/img/draft.pdf}}
649650
}
650-
{}
651651

652652
\begin{document}
653653

@@ -700,8 +700,15 @@ $endif$
700700
\vskip 1.5em
701701
Contact: \hyperlink{mailto:[email protected]}{[email protected]}
702702
\vskip 1.5em
703+
\ifthenelse{\equal{\detokenize{$status$}}{\detokenize{PUBLIC REVIEW}}}
704+
{
705+
\textit{This document is an intermediate draft for comment only and is subject to change without notice. Readers should not design products based on this document.}
706+
\vskip 1.5em
707+
}
708+
{}
709+
703710
$if(status)$
704-
\large \textsf{$status$}\\
711+
\LARGE \textbf{$status$}\\
705712
$endif$
706713
\end{textblock*}
707714
\begin{textblock*}{2cm}(2cm,10.8cm)

0 commit comments

Comments
 (0)