-
Notifications
You must be signed in to change notification settings - Fork 289
165 lines (161 loc) · 6.27 KB
/
preview.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: "Preview build"
permissions:
issues: write
pull-requests: write
contents: write
on:
pull_request:
jobs:
check:
name: "Content check"
runs-on: ubuntu-20.04
steps:
- name: "Checkout repo"
uses: actions/checkout@v3
with:
submodules: recursive
- name: "Check for obsolete wiki headers"
run: |
if grep -rEi "^wiki_[^ ]+: " source/; then
echo '/!\ Wiki headers are obsolete (see previous log entries)'
exit 2
fi
- name: "Check for obsolete feature headers"
run: |
if grep -rEi "^feature_[^ ]+: " source/; then
echo '/!\ Feature headers are obsolete (see previous log entries)'
exit 2
fi
- name: "Check for non-breaking space in markdowns"
run: |
if grep -P '\xa0' `find source/ -name "*.md"` ; then
echo '/!\ nonbreaking spaces have been found within the markdown (see previous log entries)'
exit 2
fi
# bundler just bump versions to the locally available ones
# which means developers would always require bleeding edge versions not available on stable servers
# this is too simplistic and breaks deployment
# instead all changes are tested via CI on the same target OS and version than the production builder
- name: "Check for simplistic bundler requirement bump"
run: |
if grep -E "^(RUBY VERSION|BUNDLED WITH)" Gemfile.lock; then
echo '/!\ please remove "RUBY VERSION" and "BUNDLED WITH" requirements in Gemfile.lock'
exit 2
fi
build:
name: "Build preview"
runs-on: ubuntu-20.04
outputs:
PR_ID: ${{steps.details.outputs.PR_ID}}
PREVIEW_PATH: ${{steps.details.outputs.PREVIEW_PATH}}
PREVIEW_LINK: ${{steps.details.outputs.PREVIEW_LINK}}
PREVIEW_LINK_PATH: ${{steps.details.outputs.PREVIEW_LINK_PATH}}
PREVIEW_LINK_BASE: ${{steps.details.outputs.PREVIEW_LINK_BASE}}
steps:
- name: "Checkout repo"
uses: actions/checkout@v3
with:
submodules: recursive
- name: Extract PR details
id: details
run: |
PR_ID=${{ github.event.pull_request.number }}
PREVIEW_PATH=previews/${PR_ID}
PREVIEW_LINK=https://$(echo "${{github.repository}}" | sed -e 's#/#.github.io/#')/${PREVIEW_PATH}
PREVIEW_LINK_PATH="$(echo $PREVIEW_LINK | sed -e 's#.*\.io/#/#')"
PREVIEW_LINK_BASE="$(echo $PREVIEW_LINK | sed -e 's#\.io.*#.io#')"
echo "PR_ID=${PR_ID}" >> $GITHUB_OUTPUT
echo "PREVIEW_PATH=${PREVIEW_PATH}" >> $GITHUB_OUTPUT
echo "PREVIEW_LINK=${PREVIEW_LINK}" >> $GITHUB_OUTPUT
echo "PREVIEW_LINK_PATH=${PREVIEW_LINK_PATH}" >> $GITHUB_OUTPUT
echo "PREVIEW_LINK_BASE=${PREVIEW_LINK_BASE}" >> $GITHUB_OUTPUT
- name: Comment on PR
continue-on-error: true
run: |
set -euo pipefail
echo "Hey there, thanks for the new content! 🙏 We'll create a preview build and post the link here in a few minutes." >/tmp/comment
gh pr comment ${{steps.details.outputs.PR_ID}} -F /tmp/comment
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build container image
uses: docker/build-push-action@v3
with:
context: .
push: false
load: true
tags: ovirt-site:latest
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Set up Jekyll cache
uses: actions/cache@v3
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
- name: "Change config"
run: |
set -exuo pipefail
sed -i -e "s#@PREVIEW_LINK_PATH@#${{steps.details.outputs.PREVIEW_LINK_PATH}}#" htmlproofer_test.rb
cat htmlproofer_test.rb
sed -i -e "s#^baseurl: .*#baseurl: ${{steps.details.outputs.PREVIEW_LINK_PATH}}#" _config.yml
sed -i -e "s#^url: .*#url: ${{steps.details.outputs.PREVIEW_LINK_BASE}}#" _config.yml
sed -i -e "s#site-baseurl: /#site-baseurl: ${{steps.details.outputs.PREVIEW_LINK_PATH}}#" _config.yml
cat _config.yml
- name: "Build website"
run: docker run --rm --mount type=bind,source=$(pwd),target=/srv/site ovirt-site build
- name: "Upload generated content"
uses: actions/upload-artifact@v4
with:
name: ovirt-site
if-no-files-found: error
path: |
_site
- name: "Run htmlproofer"
run: docker run --rm --mount type=bind,source=$(pwd),target=/srv/site --entrypoint "/bin/bash" ovirt-site -c "bundle exec ruby htmlproofer_test.rb"
publish:
name: "Publish preview"
runs-on: ubuntu-20.04
needs:
- check
- build
concurrency:
group: ovirt-site-preview-build
cancel-in-progress: false
steps:
- name: "Checkout repo"
uses: actions/checkout@v3
with:
ref: gh-pages
token: "${{ secrets.GITHUB_TOKEN }}"
- name: "Remove preview build directory"
run: rm -rf "${{needs.build.outputs.PREVIEW_PATH}}"
- name: "Create preview build directory"
run: mkdir -p "${{needs.build.outputs.PREVIEW_PATH}}"
- name: "Download generated content"
uses: actions/download-artifact@v4
with:
name: ovirt-site
path: "${{needs.build.outputs.PREVIEW_PATH}}"
- name: "Commit changes"
run: |
set -euo pipefail
git config user.name "GitHub Actions"
git config user.email [email protected]
git add .
if ! git diff-index --quiet HEAD --; then
git commit -m "Adding or updating preview build for PR ${{needs.build.outputs.PR_ID}}"
git push --set-upstream origin gh-pages
else
echo -e "No changes found."
fi
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: "Send comment to PR"
continue-on-error: true
run: |
set -euo pipefail
echo "Your preview build is ready! ✨ Check the following link in 1-2 minutes: ${{needs.build.outputs.PREVIEW_LINK}} ." >/tmp/comment
gh pr comment ${{needs.build.outputs.PR_ID}} -F /tmp/comment
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"