Skip to content

Commit 67c74a4

Browse files
authored
ci: Fix multi-version docs (#100)
Fixes #88 Signed-off-by: Eric Deandrea <eric.deandrea@ibm.com>
1 parent b673b11 commit 67c74a4

3 files changed

Lines changed: 48 additions & 33 deletions

File tree

.github/scripts/get-current-gh-pages.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
echo "Fetching latest pages deployment..."
44

5+
REPO="${REPO:=docling-project/docling-java}"
6+
57
# Get the latest successful pages deployment
68
ARTIFACT_ID=$(gh api "/repos/${REPO}/actions/artifacts?name=github-pages" --jq '.artifacts[0].id')
79

.github/workflows/release.yml

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,6 @@ on:
1111
- main
1212
paths:
1313
- .github/project.yml
14-
workflow_dispatch:
15-
inputs:
16-
version:
17-
description: The version to release (e.g. 1.0.0)
18-
required: true
19-
type: string
20-
dryrun:
21-
description: Perform a dry-run release
22-
required: true
23-
type: boolean
24-
default: false
2514

2615
concurrency:
2716
group: ${{ github.workflow }}-${{ github.ref }}
@@ -31,6 +20,8 @@ permissions:
3120
attestations: write
3221
id-token: write
3322
contents: write
23+
pages: write
24+
discussions: write
3425

3526
defaults:
3627
run:
@@ -39,40 +30,28 @@ defaults:
3930
jobs:
4031
release:
4132
runs-on: ubuntu-latest
42-
if: (github.repository == 'docling-project/docling-java') && ((github.event_name == 'workflow_dispatch') || ((github.event_name == 'pull_request_target') && (github.event.pull_request.merged == true)))
33+
if: (github.repository == 'docling-project/docling-java') && ((github.event_name == 'pull_request_target') && (github.event.pull_request.merged == true))
34+
environment:
35+
name: github-pages
36+
url: ${{ steps.deployment.outputs.page_url }}
4337
steps:
4438
- uses: actions/create-github-app-token@7e473efe3cb98aa54f8d4bac15400b15fad77d94 # v2.2.0
4539
id: app-token
4640
with:
4741
app-id: ${{ vars.DOCLING_JAVA_CI_APP_ID }}
4842
private-key: ${{ secrets.DOCLING_JAVA_CI_PRIVATE_KEY }}
4943

50-
- name: Checkout before PR
51-
if: github.event_name == 'pull_request_target'
44+
- name: Checkout before
5245
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
5346
with:
5447
ref: ${{ github.event.pull_request.base.sha }}
5548
path: before
5649
token: ${{ steps.app-token.outputs.token }}
5750
fetch-depth: 0
5851

59-
- name: Checkout current ref
60-
if: github.event_name == 'workflow_dispatch'
61-
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
62-
with:
63-
ref: ${{ github.ref }}
64-
path: before
65-
token: ${{ steps.app-token.outputs.token }}
66-
fetch-depth: 0
67-
6852
- name: Capture version before PR
69-
if: github.event_name == 'pull_request_target'
7053
run: echo "PREVIOUS_VERSION=$(yq '.release.current-version' before/.github/project.yml)" >> $GITHUB_ENV
7154

72-
- name: Set version to release
73-
if: github.event_name == 'workflow_dispatch'
74-
run: echo "PREVIOUS_VERSION=${{ inputs.version }}" >> $GITHUB_ENV
75-
7655
- name: Checkout current ref
7756
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
7857
with:
@@ -83,6 +62,11 @@ jobs:
8362
- name: Capture current version
8463
run: echo "CURRENT_VERSION=$(yq '.release.current-version' after/.github/project.yml)" >> $GITHUB_ENV
8564

65+
- name: Setup Python
66+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
67+
with:
68+
python-version: '3.x'
69+
8670
- name: Setup Java
8771
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
8872
with:
@@ -111,12 +95,38 @@ jobs:
11195
echo "Releasing version ${{ env.PREVIOUS_VERSION }} -> ${{ env.CURRENT_VERSION }}"
11296
./gradlew --no-daemon :jreleaserFullRelease
11397
98+
- name: Build current version docs
99+
working-directory: after
100+
run: ./gradlew --no-daemon :docs:build
101+
102+
- name: Build previous version docs
103+
working-directory: before
104+
run: ./gradlew --no-daemon :docs:build -Pdocs.alias=release -Pdocs.versionsFile=$(realpath ../after/build/mkdocs/versions.json)
105+
106+
- name: Merge docs together
107+
run: |
108+
mkdir -p docs
109+
cp -vRf after/docs/build/mkdocs docs/
110+
cp -vRf before/docs/build/mkdocs docs/
111+
112+
- name: Setup pages
113+
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b # v5.0.0
114+
115+
- name: Upload pages artifact
116+
uses: actions/upload-pages-artifact@7b1f4a764d45c48632c6b24a0339c27f5614fb0b # v4.0.0
117+
with:
118+
path: docs
119+
120+
- name: Deploy to GH Pages
121+
id: deployment
122+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
123+
114124
# Persist logs
115125
- name: JReleaser release output
116126
if: always()
117127
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
118128
with:
119129
name: jreleaser-release
120130
path: |
121-
build/jreleaser/trace.log
122-
build/jreleaser/output.properties
131+
before/build/jreleaser/trace.log
132+
before/build/jreleaser/output.properties

docs/build.gradle.kts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ mkdocs {
2929
)
3030

3131
publish {
32+
val alias = findProperty("docs.alias")?.toString() ?: "dev"
33+
val versionsFile = findProperty("docs.versionsFile")?.toString() ?: layout.buildDirectory.dir("mkdocs").get().file("versions.json").asFile.absolutePath
34+
3235
// This is a hack because versionAliases is created final as an array without a setter
3336
// So it isn't friendly to the Gradle Kotlin DSL
37+
org.codehaus.groovy.runtime.InvokerHelper.setProperty(this, "versionAliases", arrayOf(alias))
3438
docPath = "${project.version}"
35-
org.codehaus.groovy.runtime.InvokerHelper.setProperty(this, "versionAliases", arrayOf("dev"))
36-
rootRedirectTo = "dev"
39+
rootRedirectTo = alias
3740
generateVersionsFile = true
38-
existingVersionsFile = layout.buildDirectory.dir("mkdocs").get().file("versions.json").asFile.absolutePath
41+
existingVersionsFile = versionsFile
3942
}
4043
}
4144

0 commit comments

Comments
 (0)