-
Notifications
You must be signed in to change notification settings - Fork 4
144 lines (119 loc) · 4.8 KB
/
gh-pages.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
name: build self-contained READMEs
"on":
push:
branches-ignore:
- renovate/**
permissions:
contents: read
# Cancel a currently running workflow from the same PR, branch or tag when a new workflow is triggered for it
concurrency:
group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}"
cancel-in-progress: true
jobs:
asciidoctor:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
### Setup
- name: check out the codebase
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
- name: setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "2.7.0"
- name: set up python 3
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4
with:
python-version: "3.x"
- name: setup/activate pre-commit cache
uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c # v3
with:
path: ~/.cache/pre-commit
key: "${{ hashFiles('.pre-commit-config.yaml') }}"
- name: install asciidoctor and other relevant ruby gems
run: gem install --no-document asciidoctor asciidoctor-reducer rouge coderay
- name: get first line of commit message as variable
shell: bash
run: |
echo "FIRST_LINE_OF_HEAD_COMMIT_MESSAGE=${HEAD_COMMIT_MESSAGE}" | head -1 >> $GITHUB_ENV
env:
HEAD_COMMIT_MESSAGE: "${{ github.event.head_commit.message }}"
### README.orig.adoc & co.
- name: Generate README.adoc using ascidoctor-reducer.
run: asciidoctor-reducer README.orig.adoc -o README.adoc
- name: generate README.xml from README.adoc using ascidoctor
run: asciidoctor -b docbook README.adoc
- name: Generate README.md from README.xml using pandoc
uses: docker://pandoc/core@sha256:d2c4aa0c26e9480b8ab15eb952f49cb6c33ca5635417e1bb064e715a5a32a9e9
with:
args: "-f docbook -t markdown_strict README.xml -o README.md --wrap=none"
### SECURITY.adoc
- name: generate SECURITY.xml from SECURITY.adoc using ascidoctor
run: asciidoctor -b docbook SECURITY.adoc
- name: Generate SECURITY.md from SECURITY.xml using pandoc
uses: docker://pandoc/core:3.1@sha256:222badaf55d35aa19a54294721b2669a55737e8a96e78f038b89c2b70bccd13f
with:
args: "-f docbook -t markdown_strict SECURITY.xml -o SECURITY.md --wrap=none"
### Commit
- name: add 'changes will be lost' comment to generated files
run: |
sed -i \
'1s|^|This file is being generated by .github/workflows/gh-pages.yml - all local changes will be lost eventually!\n|' \
README.adoc README.md SECURITY.md
sed -i '1s|\(.*\)|<!-- \1 -->|' README.md SECURITY.md
sed -i '1s|\(.*\)|// \1|' README.adoc
- name: pre-commit generated .md files
run: |
python3 -m pip install pre-commit
pre-commit run --files README.md SECURITY.md || true
pre-commit run --files README.md SECURITY.md || true
- name: Commit generated files.
uses: stefanzweifel/git-auto-commit-action@49620cd3ed21ee620a48530e81dba0d139c9cb80 # tag=v4
with:
commit_message: "${{ env.FIRST_LINE_OF_HEAD_COMMIT_MESSAGE }}\n${{ github.sha }}"
file_pattern: README.adoc README.md SECURITY.md
disable_globbing: true
### Deploy README.adoc
- name: Generate HTML
run: asciidoctor --backend=html5 --destination-dir docs --out-file index.html README.adoc
if: github.ref == 'refs/heads/master'
- name: upload docs directory for job transfer
uses: actions/upload-artifact@v3
with:
name: docs
path: ./docs
if: github.ref == 'refs/heads/master'
gh-pages:
runs-on: ubuntu-latest
needs: asciidoctor
if: github.ref == 'refs/heads/master'
permissions:
contents: read
pages: write
id-token: write
environment:
name: github-pages
url: "${{ steps.deployment.outputs.page_url }}"
steps:
### Deploy README.adoc
- name: download docs directory from previous job
uses: actions/download-artifact@v3
with:
name: docs
path: ./docs
- name: Setup Pages
uses: actions/configure-pages@b8130d9ab958b325bbde9786d62f2c97a9885a0e # v3
- name: Upload Pages Artifact
uses: actions/upload-pages-artifact@a753861a5debcf57bf8b404356158c8e1e33150c # v2
with:
path: "./docs/"
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@de14547edc9944350dc0481aa5b7afb08e75f254 # v2
- name: docs artifact no longer needed
uses: geekyeggo/delete-artifact@v2
with:
name: docs
failOnError: false