Skip to content

Commit 4a447ce

Browse files
jamietannaClaude Sonnet 4.5
andauthored
ci: bundle Mkdocs site into Releases (#41355)
As we now perform the Mkdocs build as part of the main repo, we can now attach the docs site build into the GitHub Release artifacts as part of our release pipeline. For folks who are running versions behind the "bleeding edge" of Renovate, this is very useful, as they can now grab a copy of the built documentation for their given Renovate version. This allows folks to take the `mkdocs-site.tgz` and upload it to static hosting, without restoring to workarounds[0] that can make it more difficult. Because we're now building the docs site as part of the release, we need to upload the built artifact to then be used by our deploy step. As the deploy step no longer needs to build the docs site, we can simplify this. However, if the release hasn't occurred (because there are no commit(s) that need a release right now) we still need to rebuild the docs site, in case there are docs-only changes. [0]: https://www.jvt.me/posts/2024/11/19/renovate-private-docs/ Co-authored-by: Claude Sonnet 4.5 <jamie.tanna+github-copilot@mend.io>
1 parent 579ff4c commit 4a447ce

File tree

3 files changed

+96
-34
lines changed

3 files changed

+96
-34
lines changed

.github/workflows/build.yml

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,16 @@ jobs:
845845
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
846846
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin
847847
848+
- name: Setup PDM
849+
uses: pdm-project/setup-pdm@94a823180e06fcde4ad29308721954a521c96ed0 # v4.4
850+
with:
851+
python-version-file: .python-version
852+
version: ${{ env.PDM_VERSION }}
853+
cache: true
854+
855+
- name: Install pdm dependencies
856+
run: pdm install
857+
848858
- name: Check dry run
849859
run: |
850860
if [[ "${{github.event_name}}" == "workflow_dispatch" && "${{ github.event.inputs.dryRun }}" != "true" ]]; then
@@ -860,9 +870,30 @@ jobs:
860870
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
861871
LOG_LEVEL: debug
862872

873+
- name: Build mkdocs site for deployment (when no release)
874+
if: github.ref_name == 'main'
875+
run: |
876+
# If there wasn't a release, we won't have executed `tools/prepare-release.ts`, and the mkdocs site won't be built, but we do want it built regardless, so we can update the docs site
877+
if [[ ! -f tmp/mkdocs-site.tgz ]]; then
878+
latest_tag=$(gh release view --json tagName -q .tagName)
879+
pnpm mkdocs build --version "$latest_tag"
880+
mkdir -p tmp
881+
tar -czf tmp/mkdocs-site.tgz -C tools/mkdocs/site .
882+
fi
883+
env:
884+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
885+
886+
- name: Upload docs artifact for deployment
887+
if: github.ref_name == 'main'
888+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
889+
with:
890+
name: mkdocs-site
891+
path: tmp/mkdocs-site.tgz
892+
retention-days: 1
893+
863894
- run: df -h
864895

865-
build-deploy-docs-site:
896+
deploy-docs-site:
866897
if: ${{ github.repository == 'renovatebot/renovate' && github.ref_name == 'main' && github.event_name == 'push' }}
867898
needs:
868899
- setup-build
@@ -878,40 +909,16 @@ jobs:
878909

879910
runs-on: ubuntu-latest
880911
steps:
881-
- name: Checkout code
882-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
883-
with:
884-
show-progress: false
885-
886-
- name: Setup Node.js
887-
uses: ./.github/actions/setup-node
888-
with:
889-
node-version: ${{ needs.setup-build.outputs.node-version }}
890-
os: ${{ runner.os }}
891-
892-
- name: Setup PDM
893-
uses: pdm-project/setup-pdm@94a823180e06fcde4ad29308721954a521c96ed0 # v4.4
912+
- name: Download mkdocs site from release
913+
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
894914
with:
895-
python-version-file: .python-version
896-
version: ${{ env.PDM_VERSION }}
897-
cache: true
898-
899-
- name: Install pdm dependencies
900-
run: pdm install
915+
name: mkdocs-site
916+
path: tmp
901917

902-
- name: Determine latest release tag (whether we've released as part of this build or not)
903-
id: latest_release
918+
- name: Extract docs site
904919
run: |
905-
latest_release=$(gh release view --json tagName -q .tagName)
906-
echo "release_tag=$latest_release" >> "$GITHUB_OUTPUT"
907-
env:
908-
GH_TOKEN: ${{ github.token }}
909-
910-
# Rebuild the docs site to make sure that we have the version specified in the JSON Schema and page footer
911-
- name: Build mkdocs for Renovate ${{ steps.latest_release.outputs.release_tag }}
912-
run: pnpm mkdocs build --version ${{ steps.latest_release.outputs.release_tag }}
913-
env:
914-
GITHUB_TOKEN: ${{ github.token }}
920+
mkdir -p tools/mkdocs/site
921+
tar -xzf tmp/mkdocs-site.tgz -C tools/mkdocs/site
915922
916923
# Per https://github.com/renovatebot/helm-charts/issues/3752, when we migrated the docs site from renovatebot/renovatebot.github.io to renovatebot/renovate, the `/helm-charts/` repository would no longer work as a subdomain, due to a known GitHub Pages limitation
917924
- name: Mirror helm-charts/index.yaml from helm-charts' GitHub Pages site
@@ -950,9 +957,9 @@ jobs:
950957
951958
notify-docs-failure:
952959
runs-on: ubuntu-latest
953-
if: ${{ always() && (github.repository == 'renovatebot/renovate' && github.ref_name == 'main' && github.event_name == 'push') && (needs.build-deploy-docs-site.result == 'failure' || needs.build-deploy-docs-site.result == 'timed_out') }}
960+
if: ${{ always() && (github.repository == 'renovatebot/renovate' && github.ref_name == 'main' && github.event_name == 'push') && (needs.deploy-docs-site.result == 'failure' || needs.deploy-docs-site.result == 'timed_out') }}
954961
needs:
955-
- build-deploy-docs-site
962+
- deploy-docs-site
956963
steps:
957964
- name: Post to Slack
958965
id: slack

.releaserc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
{
1212
"path": "tmp/docs.tgz",
1313
"label": "docs.tgz"
14+
},
15+
{
16+
"path": "tmp/mkdocs-site.tgz",
17+
"label": "mkdocs-site.tgz"
1418
}
1519
]
1620
}

tools/prepare-release.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command } from 'commander';
2+
import fs from 'fs-extra';
23
import { logger } from '../lib/logger/index.ts';
34
import { generateDocs } from './docs/index.ts';
45
import { bake } from './utils/docker.ts';
@@ -33,6 +34,7 @@ void (async () => {
3334
logger.info(`Preparing v${opts.version?.toString()} ...`);
3435
build();
3536
await generateDocs(undefined, undefined, opts.version?.toString());
37+
await buildMkdocs(opts.version?.toString());
3638
await bake('build', opts);
3739
})();
3840

@@ -50,3 +52,52 @@ function build(): void {
5052
logger.debug(`Build succeeded:\n${res.stdout || res.stderr}`);
5153
}
5254
}
55+
56+
async function buildMkdocs(version: string | undefined): Promise<void> {
57+
logger.info('Building Mkdocs site ...');
58+
59+
const mkdocsArgs = ['mkdocs', 'build'];
60+
if (version) {
61+
mkdocsArgs.push('--version', version);
62+
}
63+
64+
const mkdocsRes = exec('pnpm', mkdocsArgs);
65+
66+
if (mkdocsRes.signal) {
67+
logger.error(`Signal received: ${mkdocsRes.signal}`);
68+
process.exit(-1);
69+
} else if (mkdocsRes.exitCode) {
70+
logger.error(
71+
`Error occurred building mkdocs:\n${mkdocsRes.stderr || mkdocsRes.stdout}`,
72+
);
73+
process.exit(mkdocsRes.exitCode);
74+
} else {
75+
logger.debug(
76+
`Mkdocs build succeeded:\n${mkdocsRes.stdout || mkdocsRes.stderr}`,
77+
);
78+
}
79+
80+
// Package the mkdocs site to attach to the release
81+
logger.info('Packaging Mkdocs site ...');
82+
await fs.ensureDir('tmp');
83+
84+
const tarRes = exec('tar', [
85+
'-czf',
86+
'tmp/mkdocs-site.tgz',
87+
'-C',
88+
'tools/mkdocs/site',
89+
'.',
90+
]);
91+
92+
if (tarRes.signal) {
93+
logger.error(`Signal received: ${tarRes.signal}`);
94+
process.exit(-1);
95+
} else if (tarRes.exitCode) {
96+
logger.error(
97+
`Error occurred creating mkdocs-site.tgz:\n${tarRes.stderr || tarRes.stdout}`,
98+
);
99+
process.exit(tarRes.exitCode);
100+
} else {
101+
logger.info('Mkdocs site packaged successfully to tmp/mkdocs-site.tgz');
102+
}
103+
}

0 commit comments

Comments
 (0)