Skip to content

Commit e49aca4

Browse files
Allow to provide extra labels (#43)
* Allow to provide extra labels. * Change to use newlines instead of commas to separate entries. * Use input.provide-link-targets safely. * Add tests. * Update .github/workflows/test-action-build-init.yml * Fix more copy'n'paste errors. * Try to improve tests. * Show as bool. Co-authored-by: Brian Scholer <1260690+briantist@users.noreply.github.com>
1 parent 04c308e commit e49aca4

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ on:
100100
description: A space separated list of additional collections to install prior to building the documentation.
101101
required: false
102102
type: string
103+
provide-link-targets:
104+
description: A newline separated list of link targets that should not cause reference errors. A small RST file will be created during the build which contains these labels.
105+
required: false
106+
type: string
103107

104108
outputs:
105109
artifact-name:
@@ -225,6 +229,7 @@ jobs:
225229
antsibull-docs-version: '${{ inputs.init-antsibull-docs-version }}'
226230
lenient: ${{ inputs.init-lenient }}
227231
fail-on-error: ${{ inputs.init-fail-on-error }}
232+
provide-link-targets: ${{ inputs.provide-link-targets }}
228233

229234
- name: Build BASE
230235
id: build-base
@@ -257,6 +262,7 @@ jobs:
257262
antsibull-docs-version: '${{ inputs.init-antsibull-docs-version }}'
258263
lenient: ${{ inputs.init-lenient }}
259264
fail-on-error: ${{ inputs.init-fail-on-error }}
265+
provide-link-targets: ${{ inputs.provide-link-targets }}
260266

261267
- name: Build HEAD
262268
id: build-head

.github/workflows/test-action-build-init.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
jobs:
1616
tests:
17-
name: Init [ver=${{ matrix.antsibull-docs-version }}, skip=${{ matrix.skip-init }}, lenient=${{ matrix.lenient }}, fail-on-error=${{ matrix.fail-on-error }}, dest=${{ matrix.dest }}, collections=${{ matrix.collections }}]
17+
name: Init [ver=${{ matrix.antsibull-docs-version }}, skip=${{ matrix.skip-init }}, lenient=${{ matrix.lenient }}, fail-on-error=${{ matrix.fail-on-error }}, dest=${{ matrix.dest }}, collections=${{ matrix.collections }}, link-targets=${{ matrix.provide-link-targets != '' }}]
1818
runs-on: ubuntu-latest
1919
strategy:
2020
fail-fast: false
@@ -35,11 +35,17 @@ jobs:
3535
fail-on-error:
3636
- true
3737
- false
38+
provide-link-targets:
39+
- ''
40+
- |
41+
outside_reference_1
42+
outside_reference_2
3843
include:
3944
- skip-init: true
4045
dest: .test/simple-build
4146
lenient: false # unused but needs a value
4247
fail-on-error: false # unused but needs a value
48+
provide-link-targets: ''
4349

4450
steps:
4551
- name: Checkout
@@ -66,6 +72,7 @@ jobs:
6672
skip-init: ${{ matrix.skip-init }}
6773
antsibull-docs-version: ${{ matrix.antsibull-docs-version }}
6874
lenient: ${{ matrix.lenient }}
75+
provide-link-targets: ${{ matrix.provide-link-targets }}
6976

7077
- name: assert
7178
env:
@@ -102,3 +109,14 @@ jobs:
102109
# if fail-on-error == 'false', the grep should succeed (!fail) and never run the false command
103110
# short circuit if skip-init is 'true'
104111
${{ matrix.skip-init }} || ! grep -- '--fail-on-error' conf.py || ${{ matrix.fail-on-error }} || exit 1
112+
113+
# check if provide-link-targets was used (being no empty)
114+
# :orphan: and the labels mentioned in provide-link-targets should end up in rst/_targets.rst
115+
# short circuit if skip-init is 'true' or matrix.provide-link-targets is empty
116+
${{ matrix.skip-init }} || ${{ matrix.provide-link-targets == '' }} || grep -- '^:orphan:$' rst/_targets.rst || exit 1
117+
${{ matrix.skip-init }} || ${{ matrix.provide-link-targets == '' }} || grep -- '^.. _outside_reference_1:$' rst/_targets.rst || exit 1
118+
${{ matrix.skip-init }} || ${{ matrix.provide-link-targets == '' }} || grep -- '^.. _outside_reference_2:$' rst/_targets.rst || exit 1
119+
120+
# check if provide-link-targets was not used when being empty
121+
# short circuit if skip-init is 'true' or matrix.provide-link-targets is not empty
122+
${{ matrix.skip-init }} || ${{ matrix.provide-link-targets != '' }} || ! test -e rst/_targets.rst || exit 1

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ inputs:
3636
The version of antsibull-docs to install. When set, it refers to a git ref from which to install.
3737
If not set, the latest version from PyPI is installed.
3838
required: false
39+
provide-link-targets:
40+
description: A newline separated list of link targets that should not cause reference errors. A small RST file will be created during the build which contains these labels.
41+
required: false
42+
type: string
3943
outputs:
4044
build-script:
4145
description: The path of the build script to execute.
@@ -51,6 +55,7 @@ runs:
5155
id: init
5256
env:
5357
PIP_DISABLE_PIP_VERSION_CHECK: '1'
58+
_INPUT_PROVIDE_LINK_TARGETS: ${{ inputs.provide-link-targets }}
5459
shell: bash
5560
run: |
5661
echo "::group::Installing antsibull-docs"
@@ -72,6 +77,17 @@ runs:
7277
echo "::endgroup::"
7378
fi
7479
80+
if [[ "${_INPUT_PROVIDE_LINK_TARGETS}" != "" ]]; then
81+
echo "::group::Create small RST file for link"
82+
mkdir -p "${{ inputs.dest-dir }}/rst"
83+
echo ":orphan:" > "${{ inputs.dest-dir }}/rst/_targets.rst"
84+
while read -r line; do
85+
echo ".. _${line}:" >> "${{ inputs.dest-dir }}/rst/_targets.rst"
86+
done <<< "${_INPUT_PROVIDE_LINK_TARGETS}"
87+
echo "This file just exists to provide link targets. Please ignore it." >> "${{ inputs.dest-dir }}/rst/_targets.rst"
88+
echo "::endgroup::"
89+
fi
90+
7591
echo "::group::Install additional requirements"
7692
pip install -r "${{ inputs.dest-dir }}/requirements.txt"
7793
echo "::endgroup::"

0 commit comments

Comments
 (0)