Skip to content

Commit 5375959

Browse files
authored
ansible-docs-build-html - first tests, rename move-build to copy-build (#18)
* first pass at action testing * typo * executable bit * fixups * shoe me your moves * rename move-build to copy-build * add artifact tests * naming * also trigget on .test changes * add build component to path * update build path references
1 parent 2066248 commit 5375959

File tree

6 files changed

+182
-10
lines changed

6 files changed

+182
-10
lines changed

.github/workflows/_shared-docs-build-pr.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ jobs:
200200
with:
201201
build-script: ${{ steps.init-base.outputs.build-script }}
202202
build-html: ${{ steps.init-base.outputs.build-html }}
203-
move-build: ${{ github.workspace }}/docsbuild/base
203+
copy-build: ${{ github.workspace }}/docsbuild/base
204204
artifact-upload: 'false'
205205

206206
- name: Checkout HEAD
@@ -229,7 +229,7 @@ jobs:
229229
with:
230230
build-script: ${{ steps.init-head.outputs.build-script }}
231231
build-html: ${{ steps.init-head.outputs.build-html }}
232-
move-build: ${{ github.workspace }}/docsbuild/head
232+
copy-build: ${{ github.workspace }}/docsbuild/head
233233
artifact-name: ${{ inputs.artifact-name }}
234234

235235
- name: Get a diff of the changes
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
---
2+
name: test - action/build-html
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- .test/**
8+
- .github/workflows/test-action-build-html.yml
9+
- actions/ansibe-docs-build-html/**
10+
pull_request:
11+
paths:
12+
- .test/**
13+
- .github/workflows/test-action-build-html.yml
14+
- actions/ansibe-docs-build-html/**
15+
16+
jobs:
17+
tests:
18+
name: Simple tests
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v2
23+
24+
- name: Simple 1 invoke - no copy, no artifact
25+
id: simple1
26+
uses: ./actions/ansible-docs-build-html
27+
with:
28+
build-script: .test/simple-build/build.sh
29+
build-html: .test/simple-build/build/html
30+
artifact-upload: false
31+
32+
- name: Simple 1 - Download artifacts
33+
uses: actions/download-artifact@v2
34+
id: simple1-artifact
35+
with:
36+
path: .artifacts/simple1
37+
38+
- name: Simple 1 - assert
39+
shell: python
40+
run: |
41+
expected_hash = r'${{ hashFiles('.test/simple-build/src') }}'
42+
output_hash = r'${{ steps.simple1.outputs.hash }}'
43+
output_build_html = r'${{ steps.simple1.outputs.build-html }}'
44+
artifact_hash = r'${{ hashFiles(steps.simple1-artifact.outputs.download-path) }}'
45+
46+
assert output_build_html == '.test/simple-build/build/html'
47+
assert output_hash == expected_hash
48+
assert artifact_hash != output_hash
49+
50+
- name: Simple 2 invoke - with copy, no artifact
51+
id: simple2
52+
uses: ./actions/ansible-docs-build-html
53+
with:
54+
build-script: .test/simple-build/build.sh
55+
build-html: .test/simple-build/build/html
56+
copy-build: .copies/simple2/html
57+
artifact-upload: false
58+
59+
- name: Simple 2 - Download artifacts
60+
uses: actions/download-artifact@v2
61+
id: simple2-artifact
62+
with:
63+
path: .artifacts/simple2
64+
65+
- name: Simple 2 - assert
66+
shell: python
67+
run: |
68+
expected_hash = r'${{ hashFiles('.test/simple-build/src') }}'
69+
output_hash = r'${{ steps.simple2.outputs.hash }}'
70+
output_build_html = r'${{ steps.simple2.outputs.build-html }}'
71+
artifact_hash = r'${{ hashFiles(steps.simple2-artifact.outputs.download-path) }}'
72+
original_build_hash = r'${{ hashFiles('.test/simple-build/build/html') }}'
73+
74+
assert output_build_html == '.copies/simple2/html'
75+
assert output_hash == expected_hash
76+
assert output_hash == original_build_hash
77+
assert artifact_hash != output_hash
78+
79+
- name: Simple 3 invoke - no copy, with artifact
80+
id: simple3
81+
uses: ./actions/ansible-docs-build-html
82+
with:
83+
build-script: .test/simple-build/build.sh
84+
build-html: .test/simple-build/build/html
85+
artifact-retention-days: 1
86+
artifact-name: tests-simple3
87+
88+
- name: Simple 3 - Download artifacts
89+
uses: actions/download-artifact@v2
90+
id: simple3-artifact
91+
with:
92+
name: ${{ steps.simple3.outputs.artifact-name }}
93+
path: .artifacts/simple3
94+
95+
- name: Simple 3 - assert
96+
shell: python
97+
run: |
98+
expected_hash = r'${{ hashFiles('.test/simple-build/src') }}'
99+
output_hash = r'${{ steps.simple3.outputs.hash }}'
100+
output_build_html = r'${{ steps.simple3.outputs.build-html }}'
101+
artifact_hash = r'${{ hashFiles(steps.simple3-artifact.outputs.download-path) }}'
102+
103+
assert output_build_html == '.test/simple-build/build/html'
104+
assert output_hash == expected_hash
105+
assert artifact_hash == output_hash
106+
107+
- name: Simple 3 - assert artifact url
108+
# this URL only goes to the run page, not to an individual artifact
109+
# so all we're really checking here is that it's a valid URL that's accessible
110+
run: wget '${{ steps.simple3.outputs.artifact-url }}'
111+
112+
- name: Simple 4 invoke - with copy, with artifact
113+
id: simple4
114+
uses: ./actions/ansible-docs-build-html
115+
with:
116+
build-script: .test/simple-build/build.sh
117+
build-html: .test/simple-build/build/html
118+
copy-build: .copies/simple4/html
119+
artifact-retention-days: 1
120+
artifact-name: tests-simple4
121+
122+
- name: Simple 4 - Download artifacts
123+
uses: actions/download-artifact@v2
124+
id: simple4-artifact
125+
with:
126+
name: ${{ steps.simple4.outputs.artifact-name }}
127+
path: .artifacts/simple4
128+
129+
- name: Simple 4 - assert
130+
shell: python
131+
run: |
132+
expected_hash = r'${{ hashFiles('.test/simple-build/src') }}'
133+
output_hash = r'${{ steps.simple4.outputs.hash }}'
134+
output_build_html = r'${{ steps.simple4.outputs.build-html }}'
135+
artifact_hash = r'${{ hashFiles(steps.simple4-artifact.outputs.download-path) }}'
136+
original_build_hash = r'${{ hashFiles('.test/simple-build/build/html') }}'
137+
138+
assert output_build_html == '.copies/simple4/html'
139+
assert output_hash == expected_hash
140+
assert output_hash == original_build_hash
141+
assert artifact_hash == output_hash
142+
143+
- name: Simple 4 - assert artifact url
144+
# this URL only goes to the run page, not to an individual artifact
145+
# so all we're really checking here is that it's a valid URL that's accessible
146+
run: wget '${{ steps.simple4.outputs.artifact-url }}'

.test/simple-build/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
pushd "${BASH_SOURCE%/*}"
4+
5+
rm -rf build/html
6+
mkdir -p build/html
7+
cp -R src/* build/html/
8+
9+
popd

.test/simple-build/src/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Test Index</title>
4+
</head>
5+
<body>
6+
<h1>Test Index</h1>
7+
</body>
8+
</html>

.test/simple-build/src/other.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
<title>Other HTML</title>
4+
</head>
5+
<body>
6+
<h1>Other HTML</h1>
7+
</body>
8+
</html>

actions/ansible-docs-build-html/action.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ inputs:
1010
description: The path where the build script will output the HTML.
1111
required: false
1212
default: ${{ runner.temp }}/docsbuild/build/html
13-
move-build:
13+
copy-build:
1414
description: |
15-
If set, move the built HTML to this path after building, and set the build-html output to this path instead.
15+
If set, copy the built HTML files to this path after building, and set the build-html output to this path instead.
1616
This is useful if you need to do multiple builds from the same environment, or otherwise need the files to be elsewhere.
17+
Note: files in the destination that do not exist in the source will be deleted!
1718
required: false
1819
artifact-upload:
1920
description: If true then upload the rendered docs as a build artifact.
@@ -52,13 +53,13 @@ runs:
5253
echo "::endgroup::"
5354
5455
HTML="${{ inputs.build-html }}"
55-
MOVE_BUILD="${{ inputs.move-build }}"
56+
COPY_BUILD="${{ inputs.copy-build }}"
5657
57-
if [[ "$MOVE_BUILD" != "" ]] ; then
58-
echo "::group::Move the build files"
59-
mkdir -p "$MOVE_BUILD"
60-
rsync -avc --delete-after "$HTML" "$MOVE_BUILD"
61-
echo "::set-output name=build-html::$MOVE_BUILD"
58+
if [[ "$COPY_BUILD" != "" ]] ; then
59+
echo "::group::Copy the build files"
60+
mkdir -p "$COPY_BUILD"
61+
rsync -avc --delete-after "$HTML" "$COPY_BUILD"
62+
echo "::set-output name=build-html::$COPY_BUILD"
6263
echo "::endgroup::"
6364
else
6465
echo "::set-output name=build-html::$HTML"

0 commit comments

Comments
 (0)