|
| 1 | +--- |
| 2 | +name: Ansible collection docs build (PR) |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + collection-name: |
| 7 | + description: The collection name in the form namespace.collection. |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + default: ${{ github.event.repository.name }} |
| 11 | + collection-path: |
| 12 | + description: This is the relative path component of the collection in question, for example community/general. |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + python: |
| 16 | + description: The version of Python to install. |
| 17 | + required: false |
| 18 | + type: string |
| 19 | + default: '3.9' |
| 20 | + ansible-ref: |
| 21 | + description: The ref from which to install ansible, for example "stable-2.12" or "milestone". |
| 22 | + required: false |
| 23 | + type: string |
| 24 | + default: milestone |
| 25 | + init-dest-dir: |
| 26 | + description: A directory relative to the checkout where the init process has already been run. |
| 27 | + required: false |
| 28 | + type: string |
| 29 | + artifact-name: |
| 30 | + description: The name of the artifact to upload. |
| 31 | + required: false |
| 32 | + type: string |
| 33 | + default: ${{ github.event.repository.name }}_docs_${{ github.event.pull_request.head.sha }} |
| 34 | + diff-size-limit: |
| 35 | + description: The max size of the diff, past which it will be truncated. |
| 36 | + required: false |
| 37 | + type: number |
| 38 | + default: 60000 |
| 39 | + sort-files: |
| 40 | + description: If true, sort the trimmed and rendered list of files. |
| 41 | + required: false |
| 42 | + default: true |
| 43 | + type: boolean |
| 44 | + render-file-line: |
| 45 | + description: | |
| 46 | + A template used to render each line of the file list as markdown. This will be processed as a JavaScript regex replace string, |
| 47 | + and the following named capture groups can be referenced: |
| 48 | + - $<status> -- the single character "status" letter in the file list, like "A" or an added file or "M" for a modified file. |
| 49 | + - $<path_stub> -- the part of the path that will be discarded in the "trimmed" file list. |
| 50 | + - $<path_tail> -- the relative part of the path; this can be used to concatenate to a URL to create links to the published site. |
| 51 | +
|
| 52 | + Note that literal $ characters must be escaped as $$ and literal backslashes must be escaped as \\ |
| 53 | + required: false |
| 54 | + default: '> * `$<status>` $<path_tail>' |
| 55 | + type: string |
| 56 | + render-diff-truncate-text: |
| 57 | + description: Markdown text to be used if the diff text was truncated. It will be available in the render-diff template. |
| 58 | + required: false |
| 59 | + default: '**The diff output was truncated because it exceeded the maximum size.**' |
| 60 | + type: string |
| 61 | + render-diff: |
| 62 | + description: | |
| 63 | + A template used to render the diff output as markdown. It will be interpreted as a pseudo-JavaScript template literal and the following |
| 64 | + variables are available for ${var} interpolation: |
| 65 | + - ${diff} -- the diff text |
| 66 | + - ${truncated_msg} -- empty if the diff is not truncated, otherwise the value of render-diff-truncate-text |
| 67 | + required: false |
| 68 | + type: string |
| 69 | + default: | |
| 70 | + <details> |
| 71 | + <summary>Click to see the diff comparison.</summary> |
| 72 | +
|
| 73 | + **NOTE:** only file modifications are shown here. New and deleted files are excluded. |
| 74 | + See the file list and check the published docs to see those files. |
| 75 | +
|
| 76 | + ${truncated_msg} |
| 77 | +
|
| 78 | + ```diff |
| 79 | + ${diff} |
| 80 | + ``` |
| 81 | +
|
| 82 | + </details> |
| 83 | +
|
| 84 | + outputs: |
| 85 | + artifact-name: |
| 86 | + description: The same artifact name as passed in, available as an output. |
| 87 | + value: ${{ inputs.artifact-name }} |
| 88 | + artifact-url: |
| 89 | + description: The URL to the build artifacts. |
| 90 | + value: ${{ jobs.build-ansible-docs.outputs.artifact-url }} |
| 91 | + changed: |
| 92 | + description: If false, the PR does not change the documentation. |
| 93 | + value: ${{ jobs.build-ansible-docs.outputs.changed }} |
| 94 | + diff: |
| 95 | + description: The diff between the base and head of the PR. |
| 96 | + value: ${{ jobs.build-ansible-docs.outputs.diff }} |
| 97 | + diff-truncated: |
| 98 | + description: If true, the diff was truncated because it exceeded the max size. |
| 99 | + value: ${{ jobs.build-ansible-docs.outputs.diff-truncated }} |
| 100 | + diff-rendered: |
| 101 | + description: The markdownr rendered diff between the base and head of the PR. |
| 102 | + value: ${{ jobs.build-ansible-docs.outputs.diff-rendered }} |
| 103 | + diff-files: |
| 104 | + description: The raw file list from the diff output. |
| 105 | + value: ${{ jobs.build-ansible-docs.outputs.diff-files }} |
| 106 | + diff-files-trimmed: |
| 107 | + description: The file list from the diff with the paths trimmed. |
| 108 | + value: ${{ jobs.build-ansible-docs.outputs.diff-files-trimmed }} |
| 109 | + diff-files-rendered: |
| 110 | + description: The markdown rendered file list from the diff. |
| 111 | + value: ${{ jobs.build-ansible-docs.outputs.diff-files-rendered }} |
| 112 | + |
| 113 | +jobs: |
| 114 | + build-ansible-docs: |
| 115 | + name: Build Ansible Docs |
| 116 | + runs-on: ubuntu-latest |
| 117 | + permissions: |
| 118 | + contents: read |
| 119 | + outputs: |
| 120 | + artifact-url: ${{ steps.build-head.outputs.artifact-url }} |
| 121 | + changed: ${{ steps.build-base.outputs.hash != steps.build-head.outputs.hash }} |
| 122 | + diff: ${{ steps.diff.outputs.diff }} |
| 123 | + diff-truncated: ${{ steps.diff.outputs.truncated }} |
| 124 | + diff-rendered: ${{ steps.diff.outputs.diff-rendered }} |
| 125 | + diff-files: ${{ steps.diff.outputs.files-raw }} |
| 126 | + diff-files-trimmed: ${{ steps.diff.outputs.files-trimmed }} |
| 127 | + diff-files-rendered: ${{ steps.diff.outputs.files-rendered }} |
| 128 | + steps: |
| 129 | + - name: Variable setup |
| 130 | + id: vars |
| 131 | + uses: actions/github-script@v5 |
| 132 | + with: |
| 133 | + script: | |
| 134 | + const inputs = ${{ toJSON(inputs) }} |
| 135 | + var colpath = inputs['collection-path'] |
| 136 | + if (colpath == '') { |
| 137 | + colpath = inputs['collection-name'].replace('.', '/') |
| 138 | + } |
| 139 | +
|
| 140 | + core.exportVariable('ANSIBLE_COLLECTIONS_PATHS', process.env.GITHUB_WORKSPACE) |
| 141 | +
|
| 142 | + const checkoutPath = `ansible_collections/${colpath}` |
| 143 | +
|
| 144 | + core.setOutput('col-path', colpath) |
| 145 | + core.setOutput('checkout-path', checkoutPath) |
| 146 | +
|
| 147 | + var initPath = '${{ runner.temp }}/docsbuild' |
| 148 | + var skipInit = false |
| 149 | +
|
| 150 | + if (inputs['init-dest-dir'] != '') { |
| 151 | + initPath = `${checkoutPath}/${inputs['init-dest-dir']}` |
| 152 | + skipInit = true |
| 153 | + core.setOutput('init-dir-base', initPath) |
| 154 | + core.setOutput('init-dir-head', initPath) |
| 155 | + } else { |
| 156 | + core.setOutput('init-dir-base', `${initPath}/base`) |
| 157 | + core.setOutput('init-dir-head', `${initPath}/head`) |
| 158 | + } |
| 159 | +
|
| 160 | + core.setOutput('skip-init', skipInit) |
| 161 | +
|
| 162 | + - name: Set up Python |
| 163 | + uses: actions/setup-python@v2 |
| 164 | + with: |
| 165 | + python-version: ${{ inputs.python }} |
| 166 | + |
| 167 | + - name: Install Ansible |
| 168 | + run: pip install https://github.com/ansible/ansible/archive/${{ inputs.ansible-ref }}.tar.gz --disable-pip-version-check |
| 169 | + |
| 170 | + - name: Checkout BASE |
| 171 | + uses: actions/checkout@v2 |
| 172 | + with: |
| 173 | + ref: ${{ github.event.pull_request.base.sha }} |
| 174 | + path: ${{ steps.vars.outputs.checkout-path }} |
| 175 | + |
| 176 | + - name: Initialize the build environment (BASE) |
| 177 | + id: init-base |
| 178 | + uses: ansible-community/github-docs-build/actions/ansible-docs-build-init@main |
| 179 | + with: |
| 180 | + collections: ${{ inputs.collection-name }} |
| 181 | + dest-dir: ${{ steps.vars.outputs.init-dir-base }} |
| 182 | + skip-init: ${{ steps.vars.outputs.skip-init }} |
| 183 | + |
| 184 | + - name: Build BASE |
| 185 | + id: build-base |
| 186 | + uses: ansible-community/github-docs-build/actions/ansible-docs-build-html@main |
| 187 | + with: |
| 188 | + build-script: ${{ steps.init-base.outputs.build-script }} |
| 189 | + build-html: ${{ steps.init-base.outputs.build-html }} |
| 190 | + move-build: ${{ github.workspace }}/docsbuild/base |
| 191 | + artifact-upload: 'false' |
| 192 | + |
| 193 | + - name: Checkout HEAD |
| 194 | + uses: actions/checkout@v2 |
| 195 | + with: |
| 196 | + ref: ${{ github.event.pull_request.head.sha }} |
| 197 | + path: ${{ steps.vars.outputs.checkout-path }} |
| 198 | + |
| 199 | + - name: Initialize the build environment (HEAD) |
| 200 | + id: init-head |
| 201 | + uses: ansible-community/github-docs-build/actions/ansible-docs-build-init@main |
| 202 | + with: |
| 203 | + collections: ${{ inputs.collection-name }} |
| 204 | + dest-dir: ${{ steps.vars.outputs.init-dir-head }} |
| 205 | + skip-init: ${{ steps.vars.outputs.skip-init }} |
| 206 | + |
| 207 | + - name: Build HEAD |
| 208 | + id: build-head |
| 209 | + uses: ansible-community/github-docs-build/actions/ansible-docs-build-html@main |
| 210 | + with: |
| 211 | + build-script: ${{ steps.init-head.outputs.build-script }} |
| 212 | + build-html: ${{ steps.init-head.outputs.build-html }} |
| 213 | + move-build: ${{ github.workspace }}/docsbuild/head |
| 214 | + artifact-name: ${{ inputs.artifact-name }} |
| 215 | + |
| 216 | + - name: Get a diff of the changes |
| 217 | + if: steps.build-base.outputs.hash != steps.build-head.outputs.hash |
| 218 | + id: diff |
| 219 | + uses: ansible-community/github-docs-build/actions/ansible-docs-build-diff@main |
| 220 | + with: |
| 221 | + build-html-a: ${{ steps.build-base.outputs.build-html }} |
| 222 | + build-html-b: ${{ steps.build-head.outputs.build-html }} |
| 223 | + diff-size-limit: ${{ inputs.diff-size-limit }} |
| 224 | + render-file-line: ${{ inputs.render-file-line }} |
| 225 | + render-diff-truncate-text: ${{ inputs.render-diff-truncate-text }} |
| 226 | + render-diff: ${{ inputs.render-diff }} |
0 commit comments