Skip to content

Commit f29b12a

Browse files
committed
ci: Report changed pages
1 parent 8a5c956 commit f29b12a

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

.github/workflows/deploy.yaml

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ jobs:
4848
if: github.ref != 'refs/heads/master'
4949
container: quay.io/hypernode/deploy:3-php8.1-node18
5050
steps:
51-
- uses: actions/checkout@v2
51+
- uses: actions/checkout@v3
52+
with:
53+
fetch-depth: 0
5254
- name: download build artifact
5355
uses: actions/download-artifact@v3
5456
with:
@@ -65,11 +67,31 @@ jobs:
6567
- name: Get brancher hostname
6668
id: get_brancher_hostname
6769
run: echo "BRANCHER_URL=https://$(jq .hostnames[0] deployment-report.json -r)" >> $GITHUB_OUTPUT
70+
- name: Get changed pages
71+
id: changed_pages
72+
run: |
73+
git config --global --add safe.directory $(pwd)
74+
commits=${{ github.event.pull_request.commits }}
75+
if [[ -n "$commits" ]]; then
76+
# Prepare enough depth for diffs with target branch
77+
git fetch --depth="$(( commits + 1 ))"
78+
fi
79+
result="$(python3 ci/bin/get_changed_urls.py \
80+
${{ github.event.pull_request.base.sha }} \
81+
${{github.event.pull_request.head.sha}} \
82+
--base-url=${{ steps.get_brancher_hostname.outputs.BRANCHER_URL }}
83+
)"
84+
echo "$result"
85+
echo "CHANGED_PAGES<<EOF" >> $GITHUB_OUTPUT
86+
echo "$result" >> $GITHUB_OUTPUT
87+
echo "EOF" >> $GITHUB_OUTPUT
88+
shell: bash
6889
- name: Comment hostname on PR
6990
uses: thollander/actions-comment-pull-request@v1
7091
with:
7192
message: |
72-
Acceptance server is available at ${{ steps.get_brancher_hostname.outputs.BRANCHER_URL }}
93+
Acceptance server is available at ${{ steps.get_brancher_hostname.outputs.BRANCHER_URL }}.
94+
${{ steps.changed_pages.outputs.CHANGED_PAGES }}
7395
7496
deploy_production:
7597
needs: build
@@ -81,7 +103,7 @@ jobs:
81103
if: github.ref == 'refs/heads/master'
82104
container: quay.io/hypernode/deploy:3-php8.1-node18
83105
steps:
84-
- uses: actions/checkout@v2
106+
- uses: actions/checkout@v3
85107
- name: download build artifact
86108
uses: actions/download-artifact@v3
87109
with:

ci/bin/get_changed_urls.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import argparse
2+
import re
3+
import subprocess
4+
from typing import Tuple
5+
6+
CHANGED_PATTERN = re.compile(r"^[AM]")
7+
8+
9+
def parse_args() -> Tuple[str, str, str]:
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument("start_commit")
12+
parser.add_argument("end_commit")
13+
parser.add_argument("--base-url", default="")
14+
15+
args = parser.parse_args()
16+
17+
return args.start_commit, args.end_commit, args.base_url.rstrip("/")
18+
19+
20+
def main():
21+
start_commit, end_commit, base_url = parse_args()
22+
diff_command = [
23+
"git",
24+
"diff",
25+
"--name-status",
26+
"-M",
27+
"--stat",
28+
start_commit,
29+
end_commit,
30+
]
31+
output = subprocess.check_output(diff_command, encoding="utf-8")
32+
changed_files = filter(CHANGED_PATTERN.match, output.splitlines())
33+
changed_files = map(lambda x: x.split("\t")[1], changed_files)
34+
changed_markdown_files = filter(lambda x: x.endswith(".md"), changed_files)
35+
changed_markdown_files = list(changed_markdown_files)
36+
37+
if changed_markdown_files:
38+
print("Changed pages:")
39+
for file in changed_markdown_files:
40+
file = re.sub("^docs/", "", file)
41+
file = re.sub(".md$", ".html", file)
42+
print("- " + base_url + "/" + file)
43+
44+
45+
if __name__ == "__main__":
46+
main()

0 commit comments

Comments
 (0)