Repository navigation
222 lines (196 loc) · 9.9 KB
/
Copy pathupdate-java-api-docs.yaml
File metadata and controls
222 lines (196 loc) · 9.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Regenerates docs/api-reference/java/ for a released adk-java version and
# opens the pull request for it. The Java counterpart of
# update-typescript-api-docs.yaml, and deliberately the same shape.
#
# Why this runs in CI rather than on a maintainer's machine:
# tools/java-api-docs/README.md. The short version is that the build compiles
# adk-java from source and resolves its full Maven dependency set, so the
# output depends on the toolchain it was built with. One pinned, disposable
# environment makes it reproducible.
#
# Two triggers, doing different jobs:
# workflow_dispatch - the real thing. Builds and opens a pull request.
# pull_request - a smoke test, only when the generator or this file
# changes. Builds and checks the output, opens nothing.
name: Update ADK Java API Reference
on:
workflow_dispatch:
inputs:
version:
description: 'adk-java version, e.g. 1.13.0. Empty means the latest release.'
required: false
type: string
pull_request:
paths:
- 'tools/java-api-docs/**'
- '.github/workflows/update-java-api-docs.yaml'
permissions: {}
jobs:
generate:
runs-on: ubuntu-latest
# A cold Maven build of adk-java plus aggregate Javadoc is the long pole
# here. This is a ceiling to catch a hang, not a target.
timeout-minutes: 45
steps:
- name: Checkout adk-docs repo
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
# The adk-java GitHub release is the authority for Java, not Maven
# Central -- Central can lag the release and is only a cross-check. That
# is the opposite of the TypeScript reference, where npm is the source,
# so the two workflows resolve their versions differently on purpose.
- name: Resolve the version
id: resolve
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
if [[ -n "${INPUT_VERSION}" ]]; then
version="${INPUT_VERSION}"
echo "Using the version given to the workflow: ${version}"
else
tag="$(curl -fsSL https://api.github.com/repos/google/adk-java/releases/latest \
| jq -r '.tag_name')"
version="${tag#v}"
echo "Using the latest google/adk-java release: ${tag}"
fi
if [[ ! "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Version must be X.Y.Z, got '${version}'"
exit 1
fi
echo "version=${version}" >> "$GITHUB_OUTPUT"
- name: Check the release tag exists
env:
VERSION: ${{ steps.resolve.outputs.version }}
run: |
set -euo pipefail
if ! git ls-remote --exit-code --tags \
https://github.com/google/adk-java "refs/tags/v${VERSION}" >/dev/null; then
echo "::error::google/adk-java has no tag v${VERSION}"
exit 1
fi
echo "Found v${VERSION}."
# generate.sh asks for a JDK 17+ and `jar`, both of which this provides.
# It builds with adk-java's own Maven wrapper, so no Maven here.
- name: Set up Java
uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
with:
distribution: 'temurin'
# 26, not the 17 adk-java compiles against: those are different
# questions. The pom sets maven.compiler.release=17 and that still
# governs the bytecode, but the Javadoc tool that renders these
# pages is whichever one the JDK ships, and its version is stamped
# into every file it writes -- the published reference said
# "Generated by javadoc (17)".
#
# Pinned, and deliberately not floating. A moving JDK would rewrite
# the whole reference the first time the runner image changed, and
# the diff would be a thousand files of nothing. Changing this pin
# is a real change and should look like one.
java-version: '26'
- name: Record what we are building against
env:
VERSION: ${{ steps.resolve.outputs.version }}
run: |
{
echo "### Java API reference"
echo
echo "| | |"
echo "|---|---|"
echo "| Target version | \`${VERSION}\` |"
echo "| java | \`$(java -version 2>&1 | head -1)\` |"
echo "| Trigger | \`${{ github.event_name }}\` |"
} >> "$GITHUB_STEP_SUMMARY"
- name: Generate the Java API reference
env:
VERSION: ${{ steps.resolve.outputs.version }}
run: bash tools/java-api-docs/generate.sh "${VERSION}"
# generate.sh already asserts that index.html renders the version it was
# asked for, which is the check that matters most and the one the
# TypeScript script lacked. What it does not check is whether anything
# else came out of the jar, or whether the analytics tag survived the
# extract-then-inject dance, so do that here.
- name: Check the output is real
env:
VERSION: ${{ steps.resolve.outputs.version }}
TARGET: docs/api-reference/java
run: |
set -euo pipefail
fail() { echo "::error::$1"; exit 1; }
[[ -f "${TARGET}/index.html" ]] || fail "no ${TARGET}/index.html was produced"
pages="$(find "${TARGET}" -name '*.html' | wc -l)"
echo "Generated ${pages} HTML pages."
[[ "${pages}" -ge 100 ]] || fail "only ${pages} HTML pages generated, expected hundreds"
# The jar carries build metadata that must not be published; the
# script removes it, and this is here so a change upstream that
# renames it does not quietly ship it.
[[ ! -d "${TARGET}/META-INF" ]] || fail "META-INF was extracted into the published docs"
missing_ga="$(find "${TARGET}" -name '*.html' -exec grep -L 'googletagmanager.com/gtag/js' {} + | wc -l)"
[[ "${missing_ga}" -eq 0 ]] || fail "${missing_ga} HTML files have no analytics tag"
# Both of these were wrong in the published reference until now, and
# both are the kind of wrong a build happily reports success for.
jdk_major="$(java -version 2>&1 | grep -oE '"[0-9]+' | tr -d '"' | head -1)"
grep -q "Generated by javadoc (${jdk_major})" "${TARGET}/index.html" \
|| fail "pages were not rendered by the javadoc this JDK ships (${jdk_major})"
# The `|| true` is load-bearing. grep exits 1 when it matches nothing,
# `find -exec +` passes that on, and pipefail then kills the step --
# so without it this check fails precisely when it has nothing to
# report. (The -L check above is safe: -L exits 0 when every file
# matches.) Caught by this check failing on its own first green run.
stale="$(grep -rl 'Copyright © 1980' "${TARGET}" --include='*.html' | wc -l || true)"
[[ "${stale}" -eq 0 ]] || fail "${stale} files still carry the 1980 copyright footer"
grep -qE 'Copyright © 20[0-9]{2} Google LLC\.' "${TARGET}/index.html" \
|| fail "the footer is not the dated Google LLC one generate.sh sets"
echo "Output looks right: ${pages} pages, no META-INF, analytics tag," \
"javadoc ${jdk_major}, dated copyright footer."
- name: Upload the generated reference
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: java-api-reference-${{ steps.resolve.outputs.version }}
path: docs/api-reference/java
retention-days: 7
- name: Check whether anything changed
id: diff
run: |
set -euo pipefail
if git diff --quiet -- docs/api-reference/java; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "The reference already matches this version; nothing to open." \
>> "$GITHUB_STEP_SUMMARY"
else
echo "changed=true" >> "$GITHUB_OUTPUT"
git diff --stat -- docs/api-reference/java | tail -1 >> "$GITHUB_STEP_SUMMARY"
fi
- name: Create Pull Request
if: github.event_name == 'workflow_dispatch' && steps.diff.outputs.changed == 'true'
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
token: ${{ secrets.ADK_BOT_GITHUB_TOKEN }}
commit-message: "docs: update API reference for ADK Java ${{ steps.resolve.outputs.version }}"
title: "Update API reference docs for ADK Java ${{ steps.resolve.outputs.version }}"
body: |
Regenerated `docs/api-reference/java/` with
`tools/java-api-docs/generate.sh ${{ steps.resolve.outputs.version }}`,
run by [this workflow](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}).
Upstream release:
https://github.com/google/adk-java/releases/tag/v${{ steps.resolve.outputs.version }}
Generated output only. This does not bump the `com.google.adk`
coordinates quoted in prose or in `examples/java/**/pom.xml`; those
are a separate change.
branch: "update-java-api-reference-${{ steps.resolve.outputs.version }}"
delete-branch: true
add-paths: docs/api-reference/java