|
1 | 1 | ---
|
2 |
| - |
3 |
| -name: Ansible package docs build |
| 2 | +name: Build and deploy docs |
4 | 3 | on:
|
5 | 4 | schedule:
|
6 |
| - - cron: '17 5 * * *' # Run at 05:17 am |
| 5 | + # Run at 05:17 on Tuesday and Thursday |
| 6 | + - cron: '17 5 * * 2,4' |
7 | 7 | workflow_dispatch:
|
8 | 8 | inputs:
|
9 | 9 | repository-owner:
|
10 | 10 | description: GitHub account or org that owns the repository
|
| 11 | + type: string |
11 | 12 | required: true
|
12 | 13 | default: ansible
|
13 | 14 | repository-name:
|
14 | 15 | description: Name of the GitHub repository
|
| 16 | + type: string |
15 | 17 | required: true
|
16 | 18 | default: ansible-documentation
|
17 | 19 | repository-branch:
|
18 | 20 | description: Branch, tag, or commit SHA
|
| 21 | + type: string |
19 | 22 | required: true
|
20 | 23 | default: devel
|
21 | 24 | ansible-package-version:
|
22 |
| - type: choice |
23 | 25 | description: Ansible community package version
|
| 26 | + type: choice |
24 | 27 | required: true
|
25 | 28 | default: devel
|
26 | 29 | options:
|
|
29 | 32 | - '10'
|
30 | 33 | - '9'
|
31 | 34 | deploy:
|
32 |
| - type: boolean |
33 | 35 | description: Deploy the build
|
| 36 | + type: boolean |
34 | 37 | required: true
|
35 | 38 | deployment-environment:
|
36 |
| - type: choice |
37 | 39 | description: Deployment environment
|
| 40 | + type: choice |
38 | 41 | required: true
|
39 | 42 | default: test
|
40 | 43 | options:
|
41 | 44 | - production
|
42 | 45 | - test
|
43 | 46 |
|
44 |
| -env: |
45 |
| - PACKAGE_VERSION: ${{ github.event.inputs.ansible-package-version || 'devel' }} |
46 |
| - |
47 | 47 | jobs:
|
48 | 48 | build-package-docs:
|
49 |
| - runs-on: ubuntu-latest |
50 |
| - steps: |
51 |
| - - name: Checkout Ansible documentation |
52 |
| - uses: actions/checkout@v4 |
53 |
| - with: |
54 |
| - repository: >- |
55 |
| - ${{ |
56 |
| - github.event.inputs.repository-owner || 'ansible' |
57 |
| - }}/${{ |
58 |
| - github.event.inputs.repository-name || 'ansible-documentation' |
59 |
| - }} |
60 |
| - ref: ${{ github.event.inputs.repository-branch || 'devel' }} |
61 |
| - path: build-directory |
62 |
| - |
63 |
| - - name: Setup nox |
64 |
| - |
65 |
| - |
66 |
| - - name: Output Python info |
67 |
| - run: python --version --version && which python |
68 |
| - |
69 |
| - - name: Graft ansible-core |
70 |
| - run: nox -s clone-core |
71 |
| - working-directory: build-directory |
72 |
| - |
73 |
| - - name: Install project requirements |
74 |
| - run: >- |
75 |
| - python -m pip install |
76 |
| - -r tests/requirements.in |
77 |
| - -c tests/requirements.txt |
78 |
| - working-directory: build-directory |
79 |
| - |
80 |
| - - name: Set the COLLECTION_LIST variable |
81 |
| - if: env.PACKAGE_VERSION != 'devel' |
82 |
| - run: >- |
83 |
| - echo COLLECTION_LIST="${PACKAGE_VERSION}" |
84 |
| - >> "${GITHUB_ENV}" |
85 |
| -
|
86 |
| - - name: Set the VERSION variable |
87 |
| - run: echo VERSION="${PACKAGE_VERSION}" >> "${GITHUB_ENV}" |
88 |
| - |
89 |
| - - name: Build the Ansible community package docs |
90 |
| - run: make webdocs ANSIBLE_VERSION="${COLLECTION_LIST}" |
91 |
| - working-directory: build-directory/docs/docsite |
92 |
| - |
93 |
| - - name: Create a tarball with the build contents |
94 |
| - run: >- |
95 |
| - tar -czvf |
96 |
| - ansible-package-docs-html-"${PACKAGE_VERSION}"-"$(date '+%Y-%m-%d')"-${{ |
97 |
| - github.run_id |
98 |
| - }}-${{ |
99 |
| - github.run_number |
100 |
| - }}-${{ |
101 |
| - github.run_attempt |
102 |
| - }}.tar.gz |
103 |
| - --directory=_build/html/ . |
104 |
| - working-directory: build-directory/docs/docsite |
105 |
| - |
106 |
| - - name: Create a downloadable archive that contains the tarball |
107 |
| - uses: actions/upload-artifact@v4 |
108 |
| - with: |
109 |
| - name: package-docs-build |
110 |
| - path: build-directory/docs/docsite/ansible-package-docs-html-*.tar.gz |
111 |
| - retention-days: 7 |
| 49 | + name: 📝 Build |
| 50 | + uses: ./.github/workflows/reusable-build-docs.yaml |
| 51 | + with: |
| 52 | + repository-owner: ${{ github.event.inputs.repository-owner }} |
| 53 | + repository-name: ${{ github.event.inputs.repository-name }} |
| 54 | + repository-branch: ${{ github.event.inputs.repository-branch }} |
| 55 | + ansible-package-version: ${{ github.event.inputs.ansible-package-version }} |
| 56 | + secrets: |
| 57 | + DOCS_BOT_TOKEN: ${{ secrets.DOCS_BOT_TOKEN }} |
112 | 58 |
|
113 |
| - check-deploy: |
| 59 | + deploy-package-docs: |
| 60 | + name: 🚀 Deploy |
114 | 61 | if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy == 'true'
|
115 | 62 | needs: build-package-docs
|
116 |
| - runs-on: ubuntu-latest |
117 |
| - steps: |
118 |
| - - name: Log the workflow inputs if deployed |
119 |
| - run: | |
120 |
| - { |
121 |
| - echo "## Deployment details :shipit:"; |
122 |
| - echo "Publish to: ${{ github.event.inputs.deployment-environment }}"; |
123 |
| - echo "Package version: ${{ github.event.inputs.ansible-package-version }}"; |
124 |
| - echo "Owner: ${{ github.event.inputs.repository-owner }}"; |
125 |
| - echo "Branch: ${{ github.event.inputs.repository-branch }}"; |
126 |
| - } >> "${GITHUB_STEP_SUMMARY}" |
127 |
| -
|
128 |
| - notify-build-failures: |
129 |
| - if: failure() |
130 |
| - needs: build-package-docs |
131 |
| - runs-on: ubuntu-latest |
132 |
| - env: |
133 |
| - ROOM_URL: https://ansible-accounts.ems.host/_matrix/client/v3/rooms/!HJtetIFWYEIDBOXxFE:libera.chat/send/m.room.message |
134 |
| - FAIL_MESSAGE: >- |
135 |
| - Oh no! A community package docs build has failed. |
136 |
| - Check this workflow run to see what went wrong: |
137 |
| - https://github.com/ansible/ansible-documentation/actions/runs/${{ github.run_id }} |
138 |
| - @orandon @samccann |
139 |
| - steps: |
140 |
| - - name: Set a transaction ID |
141 |
| - run: echo "TX_ID=$(date +%s)" >> "${GITHUB_ENV}" |
142 |
| - |
143 |
| - - name: Notify the DaWGs in Matrix |
144 |
| - run: | |
145 |
| - curl -X PUT "${{ env.ROOM_URL }}/${TX_ID}" \ |
146 |
| - -H "Authorization: Bearer ${{ secrets.DOCS_BOT_TOKEN }}" \ |
147 |
| - -H "Content-Type: application/json" \ |
148 |
| - -d '{"msgtype": "m.text", "body": "${{ env.FAIL_MESSAGE }}"}' |
149 |
| -
|
150 |
| - deploy-package-docs: |
151 |
| - needs: |
152 |
| - - check-deploy |
153 |
| - runs-on: ubuntu-latest |
154 |
| - environment: |
155 |
| - name: deploy-package-docs |
156 |
| - url: ${{ env.ENV_URL }} |
157 |
| - env: |
158 |
| - TARGET: ${{ github.event.inputs.deployment-environment }} |
159 |
| - DEST_REPO: ansible-community/package-doc-builds |
160 |
| - USER_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com" |
161 |
| - USER_NAME: "github-actions[bot]" |
162 |
| - steps: |
163 |
| - - name: Download the build archive |
164 |
| - uses: actions/download-artifact@v4 |
165 |
| - with: |
166 |
| - name: package-docs-build |
167 |
| - |
168 |
| - - name: Extract the tarball |
169 |
| - run: >- |
170 |
| - tar -xvzf |
171 |
| - ansible-package-docs-html-*.tar.gz |
172 |
| - --one-top-level |
173 |
| -
|
174 |
| - - name: Set the production branch and url |
175 |
| - if: env.TARGET == 'production' |
176 |
| - env: |
177 |
| - BRANCH_NAME: ${{ github.event.inputs.ansible-package-version }} |
178 |
| - PROD_URL: https://ansible.readthedocs.io/projects/ansible |
179 |
| - run: | |
180 |
| - echo "BRANCH=${BRANCH_NAME}" >> "${GITHUB_ENV}" |
181 |
| - echo "ENV_URL=${PROD_URL}/${BRANCH_NAME}" >> "${GITHUB_ENV}" |
182 |
| -
|
183 |
| - - name: Set the test branch and url |
184 |
| - if: env.TARGET == 'test' |
185 |
| - env: |
186 |
| - TEST_URL: https://ansible-community.github.io/package-doc-builds |
187 |
| - run: | |
188 |
| - echo "BRANCH=gh-pages" >> "${GITHUB_ENV}" |
189 |
| - echo "ENV_URL=${TEST_URL}" >> "${GITHUB_ENV}" |
190 |
| -
|
191 |
| - - name: Checkout the deploy directory |
192 |
| - uses: actions/checkout@v4 |
193 |
| - with: |
194 |
| - repository: ${{ env.DEST_REPO }} |
195 |
| - ref: ${{ env.BRANCH }} |
196 |
| - path: deploy-directory |
197 |
| - fetch-depth: 0 |
198 |
| - ssh-key: ${{ secrets.DEPLOY_DOC_BUILD }} |
199 |
| - persist-credentials: true |
200 |
| - |
201 |
| - - name: Copy the generated HTML and assets for production |
202 |
| - run: >- |
203 |
| - rsync -av --delete --mkpath |
204 |
| - ansible-package-docs-html-*/ |
205 |
| - deploy-directory/docs |
206 |
| -
|
207 |
| - - name: Create a norobots.txt file for the test site |
208 |
| - if: env.TARGET == 'test' |
209 |
| - run: | |
210 |
| - touch norobots.txt |
211 |
| - echo "User-agent: *" > norobots.txt |
212 |
| - echo "Disallow: /" >> norobots.txt |
213 |
| - working-directory: deploy-directory/docs |
214 |
| - |
215 |
| - - name: Configure the git user |
216 |
| - run: | |
217 |
| - git config --local user.email "${USER_EMAIL}" |
218 |
| - git config --local user.name "${USER_NAME}" |
219 |
| - working-directory: deploy-directory |
220 |
| - |
221 |
| - - name: Git add the generated HTML and assets |
222 |
| - run: git add ./docs --all --force |
223 |
| - working-directory: deploy-directory |
224 |
| - |
225 |
| - - name: Commit generated HTML and assets |
226 |
| - run: >- |
227 |
| - git diff-index --quiet HEAD || |
228 |
| - git commit -m "Push docs build $(date '+%Y-%m-%d')-${{ |
229 |
| - github.run_id |
230 |
| - }}-${{ |
231 |
| - github.run_number |
232 |
| - }}-${{ |
233 |
| - github.run_attempt |
234 |
| - }}" |
235 |
| - working-directory: deploy-directory |
236 |
| - |
237 |
| - - name: Push build to deploy repository |
238 |
| - run: git push origin |
239 |
| - working-directory: deploy-directory |
| 63 | + uses: ./.github/workflows/reusable-deploy-docs.yaml |
| 64 | + with: |
| 65 | + ansible-package-version: ${{ github.event.inputs.ansible-package-version }} |
| 66 | + deployment-environment: ${{ github.event.inputs.deployment-environment }} |
| 67 | + repository-owner: ${{ github.event.inputs.repository-owner }} |
| 68 | + repository-branch: ${{ github.event.inputs.repository-branch }} |
| 69 | + secrets: |
| 70 | + DEPLOY_DOC_BUILD: ${{ secrets.DEPLOY_DOC_BUILD }} |
0 commit comments