Skip to content

Commit 12915cb

Browse files
committed
ci: Add markdownlint, test_html_build, and build_docs workflows
- markdownlint runs against README.md to avoid any issues with converting it to HTML - test_converting_readme converts README.md > HTML and uploads this test artifact to ensure that conversion works fine - build_docs converts README.md > HTML and pushes the result to the docs branch to publish dosc to GitHub pages site. - Fix markdown issues in README.md Signed-off-by: Sergei Petrosian <spetrosi@redhat.com>
1 parent e9a6b84 commit 12915cb

File tree

8 files changed

+845
-186
lines changed

8 files changed

+845
-186
lines changed

.ansible-lint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ skip_list:
1818
exclude_paths:
1919
- tests/roles/
2020
- .github/
21+
- .markdownlint.yaml
2122
- examples/roles/
2223
mock_roles:
2324
- linux-system-roles.storage

.github/workflows/ansible-test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
- name: Convert role to collection format
3939
run: |
4040
set -euxo pipefail
41+
# Remove to avoid running ansible-test on unrelated file
42+
rm -f .pandoc_template.html5
4143
TOXENV=collection lsr_ci_runtox
4244
# copy the ignore files
4345
coll_dir=".tox/ansible_collections/$LSR_ROLE2COLL_NAMESPACE/$LSR_ROLE2COLL_NAME"

.github/workflows/build_docs.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
---
2+
# yamllint disable rule:line-length
3+
name: Convert README.md to HTML and push to docs branch
4+
on: # yamllint disable-line rule:truthy
5+
push:
6+
branches:
7+
- main
8+
paths:
9+
- README.md
10+
release:
11+
types:
12+
- published
13+
permissions:
14+
contents: read
15+
jobs:
16+
build_docs:
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
steps:
21+
- name: Update pip, git
22+
run: |
23+
set -euxo pipefail
24+
sudo apt update
25+
sudo apt install -y git
26+
27+
- name: Check out code
28+
uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0
31+
- name: Ensure the docs branch
32+
run: |
33+
set -euxo pipefail
34+
branch=docs
35+
existed_in_remote=$(git ls-remote --heads origin $branch)
36+
37+
if [ -z "${existed_in_remote}" ]; then
38+
echo "Creating $branch branch"
39+
git config --global user.name "${{ github.actor }}"
40+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
41+
git checkout --orphan $branch
42+
git reset --hard
43+
git commit --allow-empty -m "Initializing $branch branch"
44+
git push origin $branch
45+
echo "Created $branch branch"
46+
else
47+
echo "Branch $branch already exists"
48+
fi
49+
50+
- name: Checkout the docs branch
51+
uses: actions/checkout@v3
52+
with:
53+
ref: docs
54+
55+
- name: Fetch README.md and .pandoc_template.html5 template from the workflow branch
56+
uses: actions/checkout@v3
57+
with:
58+
sparse-checkout: |
59+
README.md
60+
.pandoc_template.html5
61+
sparse-checkout-cone-mode: false
62+
path: ref_branch
63+
- name: Set RELEASE_VERSION based on whether run on release or on push
64+
run: |
65+
set -euxo pipefail
66+
if [ ${{ github.event_name }} = release ]; then
67+
echo "RELEASE_VERSION=${{ github.event.release.tag_name }}" >> $GITHUB_ENV
68+
elif [ ${{ github.event_name }} = push ]; then
69+
echo "RELEASE_VERSION=latest" >> $GITHUB_ENV
70+
else
71+
echo Unsupported event
72+
exit 1
73+
fi
74+
75+
- name: Ensure that version and docs directories exist
76+
run: mkdir -p ${{ env.RELEASE_VERSION }} docs
77+
78+
- name: Convert README.md to HTML and save to the version directory
79+
uses: docker://pandoc/core:latest
80+
with:
81+
args: >-
82+
--from gfm --to html5 --toc --shift-heading-level-by=-1
83+
--template ref_branch/.pandoc_template.html5
84+
--output ${{ env.RELEASE_VERSION }}/README.html ref_branch/README.md
85+
86+
- name: Copy latest README.html to docs/index.html for GitHub pages
87+
if: env.RELEASE_VERSION == 'latest'
88+
run: cp ${{ env.RELEASE_VERSION }}/README.html docs/index.html
89+
90+
- name: Commit changes
91+
run: |
92+
git config --global user.name "${{ github.actor }}"
93+
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
94+
git add ${{ env.RELEASE_VERSION }}/README.html docs/index.html
95+
git commit -m "Update README.html for ${{ env.RELEASE_VERSION }}"
96+
97+
- name: Push changes
98+
uses: ad-m/github-push-action@master
99+
with:
100+
github_token: ${{ secrets.GITHUB_TOKEN }}
101+
branch: docs

.github/workflows/markdownlint.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
# yamllint disable rule:line-length
3+
name: Markdown Lint
4+
on: # yamllint disable-line rule:truthy
5+
pull_request:
6+
merge_group:
7+
branches:
8+
- main
9+
types:
10+
- checks_requested
11+
push:
12+
branches:
13+
- main
14+
workflow_dispatch:
15+
permissions:
16+
contents: read
17+
jobs:
18+
markdownlint:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Update pip, git
22+
run: |
23+
set -euxo pipefail
24+
sudo apt update
25+
sudo apt install -y git
26+
27+
- name: Check out code
28+
uses: actions/checkout@v3
29+
30+
- name: Lint README.md
31+
uses: docker://avtodev/markdown-lint:master
32+
with:
33+
args: README.md
34+
config: .markdownlint.yaml
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
# yamllint disable rule:line-length
3+
name: Test converting README.md to README.html
4+
on: # yamllint disable-line rule:truthy
5+
pull_request:
6+
merge_group:
7+
branches:
8+
- main
9+
types:
10+
- checks_requested
11+
push:
12+
branches:
13+
- main
14+
permissions:
15+
contents: read
16+
jobs:
17+
test_converting_readme:
18+
runs-on: ubuntu-latest
19+
permissions:
20+
contents: write
21+
steps:
22+
- name: Update pip, git
23+
run: |
24+
set -euxo pipefail
25+
sudo apt update
26+
sudo apt install -y git
27+
28+
- name: Check out code
29+
uses: actions/checkout@v3
30+
31+
- name: Convert README.md to HTML and save to the version directory
32+
uses: docker://pandoc/core:latest
33+
with:
34+
args: >-
35+
--from gfm --to html5 --toc --shift-heading-level-by=-1
36+
--template .pandoc_template.html5
37+
--output README.html README.md
38+
39+
- name: Upload README.html as an artifact
40+
uses: actions/upload-artifact@master
41+
with:
42+
name: README.html
43+
path: README.html

0 commit comments

Comments
 (0)