@@ -13,7 +13,60 @@ on: # yamllint disable-line rule:truthy
1313permissions :
1414 contents : read
1515jobs :
16+ # Pandoc runs in an isolated read-only job so a compromised container cannot
17+ # use a runner-mounted contents: write credential to push.
1618 build_docs :
19+ runs-on : ubuntu-latest
20+ steps :
21+ - name : Check out README and Pandoc template
22+ uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
23+ with :
24+ persist-credentials : false
25+ sparse-checkout : |
26+ README.md
27+ .pandoc_template.html5
28+ sparse-checkout-cone-mode : false
29+ - name : Set RELEASE_VERSION based on whether run on release or on push
30+ env :
31+ RELEASE_TAG : ${{ github.event.release.tag_name }}
32+ run : |
33+ set -euxo pipefail
34+ if [ ${{ github.event_name }} = release ]; then
35+ tag_name="$RELEASE_TAG"
36+ if [[ "$tag_name" =~ ^[0-9]+[.][0-9]+[.][0-9]+$ ]]; then
37+ echo "RELEASE_VERSION=$tag_name" >> $GITHUB_ENV
38+ else
39+ echo "RELEASE_VERSION=${{ github.event.release.id }}" >> $GITHUB_ENV
40+ fi
41+ elif [ ${{ github.event_name }} = push ]; then
42+ echo "RELEASE_VERSION=latest" >> $GITHUB_ENV
43+ else
44+ echo Unsupported event
45+ exit 1
46+ fi
47+
48+ - name : Ensure that version directory exists
49+ run : mkdir -p ${{ env.RELEASE_VERSION }}
50+
51+ - name : Remove badges from README.md prior to converting to HTML
52+ run : sed -i '1,8 {/^\[\!.*actions\/workflows/d}' README.md
53+
54+ - name : Convert README.md to HTML and save to the version directory
55+ uses : docker://pandoc/core:8d7467e8ee40b0365a344c3d41067d6d2349da52e9961e4229f331094806fb14
56+ with :
57+ args : >-
58+ --from gfm --to html5 --toc --shift-heading-level-by=-1
59+ --template .pandoc_template.html5
60+ --output ${{ env.RELEASE_VERSION }}/README.html README.md
61+
62+ - name : Upload docs HTML artifact
63+ uses : actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
64+ with :
65+ name : docs-html
66+ path : ${{ env.RELEASE_VERSION }}/README.html
67+
68+ publish_docs :
69+ needs : build_docs
1770 runs-on : ubuntu-latest
1871 permissions :
1972 contents : write
2780 - name : Check out code
2881 uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
2982 with :
83+ persist-credentials : true # needed for docs branch initialization push
3084 fetch-depth : 0
3185 - name : Ensure the docs branch
3286 run : |
@@ -51,50 +105,37 @@ jobs:
51105 uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
52106 with :
53107 ref : docs
54-
55- - name : Fetch README.md and .pandoc_template.html5 template from the workflow branch
56- uses : actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
57- with :
58- sparse-checkout : |
59- README.md
60- .pandoc_template.html5
61- sparse-checkout-cone-mode : false
62- path : ref_branch
108+ persist-credentials : true # needed for commit and push
63109 - name : Set RELEASE_VERSION based on whether run on release or on push
110+ env :
111+ RELEASE_TAG : ${{ github.event.release.tag_name }}
64112 run : |
65113 set -euxo pipefail
66114 if [ ${{ github.event_name }} = release ]; then
67- echo "RELEASE_VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
115+ tag_name="$RELEASE_TAG"
116+ if [[ "$tag_name" =~ ^[0-9]+[.][0-9]+[.][0-9]+$ ]]; then
117+ echo "RELEASE_VERSION=$tag_name" >> $GITHUB_ENV
118+ else
119+ echo "RELEASE_VERSION=${{ github.event.release.id }}" >> $GITHUB_ENV
120+ fi
68121 elif [ ${{ github.event_name }} = push ]; then
69122 echo "RELEASE_VERSION=latest" >> $GITHUB_ENV
70123 else
71124 echo Unsupported event
72125 exit 1
73126 fi
74127
75- - name : Ensure that version and docs directories exist
76- run : mkdir -p ${{ env.RELEASE_VERSION }} docs
77-
78- - name : Remove badges from README.md prior to converting to HTML
79- run : sed -i '1,8 {/^\[\!.*actions\/workflows/d}' ref_branch/README.md
80-
81- - name : Convert README.md to HTML and save to the version directory
82- uses : docker://pandoc/core:latest
128+ - name : Download docs HTML artifact
129+ uses : actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7
83130 with :
84- args : >-
85- --from gfm --to html5 --toc --shift-heading-level-by=-1
86- --template ref_branch/.pandoc_template.html5
87- --output ${{ env.RELEASE_VERSION }}/README.html ref_branch/README.md
131+ name : docs-html
132+ path : ${{ env.RELEASE_VERSION }}
88133
89134 - name : Copy latest README.html to docs/index.html for GitHub pages
90135 if : env.RELEASE_VERSION == 'latest'
91- run : cp ${{ env.RELEASE_VERSION }}/README.html docs/index.html
92-
93- - name : Upload README.html as an artifact
94- uses : actions/upload-artifact@v7
95- with :
96- name : README.html
97- path : ${{ env.RELEASE_VERSION }}/README.html
136+ run : |
137+ mkdir -p docs
138+ cp ${{ env.RELEASE_VERSION }}/README.html docs/index.html
98139
99140 - name : Commit changes
100141 run : |
@@ -104,7 +145,7 @@ jobs:
104145 git commit -m "Update README.html for ${{ env.RELEASE_VERSION }}"
105146
106147 - name : Push changes
107- uses : ad-m/github-push-action@master
148+ uses : ad-m/github-push-action@881a6320fdb16eb5318c5054f31c218aec2b324c # master
108149 with :
109150 github_token : ${{ secrets.GITHUB_TOKEN }}
110151 branch : docs
0 commit comments