Skip to content

Commit ddadf19

Browse files
authored
docs(rustdocfx): gcb to upload reference docs to dev staging (#3283)
* docs(rustdocfx): gcb to upload reference docs to dev staging * docs(rustdocfx): gcb to upload reference docs to dev staging * fix missing newline * fix lint
1 parent 284d68b commit ddadf19

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

.gcb/builds/triggers/main.tf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ locals {
3434
# connection and just record it here.
3535
gcb_secret_name = "projects/${var.project}/secrets/github-github-oauthtoken-319d75/versions/latest"
3636

37-
# Add to this list of you want to have more triggers.
38-
builds = {
37+
# Add to these lists of you want to have more triggers.
38+
pr_builds = {
3939
integration = {}
4040
}
41+
42+
pm_builds = {
43+
integration = {}
44+
referenceupload = {}
45+
}
4146
}
4247

4348
# This is used to retrieve the project number. The project number is embedded in
@@ -67,7 +72,7 @@ resource "google_cloudbuildv2_repository" "main" {
6772
}
6873

6974
resource "google_cloudbuild_trigger" "pull-request" {
70-
for_each = tomap(local.builds)
75+
for_each = tomap(local.pr_builds)
7176
location = var.region
7277
name = "gcb-pr-${each.key}"
7378
filename = ".gcb/${each.key}.yaml"
@@ -87,7 +92,7 @@ resource "google_cloudbuild_trigger" "pull-request" {
8792
}
8893

8994
resource "google_cloudbuild_trigger" "post-merge" {
90-
for_each = tomap(local.builds)
95+
for_each = tomap(local.pm_builds)
9196
location = var.region
9297
name = "gcb-pm-${each.key}"
9398
filename = ".gcb/${each.key}.yaml"

.gcb/referenceupload.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
options:
16+
dynamic_substitutions: true
17+
substitutionOption: 'ALLOW_LOOSE'
18+
logging: CLOUD_LOGGING_ONLY
19+
env:
20+
- STAGING_BUCKET=docs-staging-v2-dev
21+
- SCCACHE_GCS_BUCKET=${PROJECT_ID}-build-cache
22+
- SCCACHE_GCS_RW_MODE=READ_WRITE
23+
- SCCACHE_GCS_KEY_PREFIX=sccache/referenceupload
24+
- RUSTC_WRAPPER=/workspace/.bin/sccache
25+
serviceAccount: 'projects/${PROJECT_ID}/serviceAccounts/integration-test-runner@${PROJECT_ID}.iam.gserviceaccount.com'
26+
steps:
27+
- name: 'gcr.io/cloud-builders/curl'
28+
script: |
29+
#!/usr/bin/env bash
30+
set -e
31+
mkdir -p .bin
32+
curl -fsSL https://github.com/mozilla/sccache/releases/download/v0.9.1/sccache-v0.9.1-x86_64-unknown-linux-musl.tar.gz |
33+
tar -C /workspace/.bin -zxf - --strip-components=1
34+
chmod 755 /workspace/.bin/sccache
35+
- name: 'rust:1.85-bookworm'
36+
script: |
37+
#!/usr/bin/env bash
38+
set -e
39+
apt-get update
40+
yes Y | apt-get install python3-pip
41+
yes Y | apt-get install virtualenv python3-venv
42+
python3 -m venv .venv
43+
source .venv/bin/activate
44+
pip install gcp-docuploader
45+
wget https://go.dev/dl/go1.25.1.linux-amd64.tar.gz
46+
tar -C /usr/local -xzf ./go1.25.1.linux-amd64.tar.gz
47+
export PATH=$PATH:/usr/local/go/bin
48+
cargo install --locked cargo-workspaces
49+
go build ./doc/rustdocfx/
50+
./rustdocfx -project-root ./ -staging-bucket ${STAGING_BUCKET}

doc/rustdocfx/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var crateDenyList = []string{"gcp-sdk", "google-cloud-base", "google-cloud-gax-i
4747
func main() {
4848
out := flag.String("out", "docfx", "Output directory within project-root (default docfx)")
4949
projectRoot := flag.String("project-root", "", "Top level directory of googleapis/google-cloud-rust")
50-
upload := flag.Bool("upload", false, "Upload generated docfx using docuploader")
50+
upload := flag.String("staging-bucket", "", "Upload the generated docfx to the gcs bucket using docuploader")
5151
flag.Parse()
5252

5353
crates := flag.Args()
@@ -108,10 +108,9 @@ func main() {
108108
}
109109
fmt.Printf("Generated docfx for crate: %s\n", crate.Name)
110110

111-
if *upload {
111+
if *upload != "" {
112112
fmt.Printf("Uploading crate: %s\n", crate.Name)
113-
// TODO: Add a flag to specify bucket location.
114-
if err := runCmd(nil, "", "docuploader", "upload", "--staging-bucket=docs-staging-v2-dev", fmt.Sprintf("--metadata-file=%s/docs.metadata", crateOutDir), crateOutDir); err != nil {
113+
if err := runCmd(nil, "", "docuploader", "upload", fmt.Sprintf("--staging-bucket=%s", *upload), "--destination-prefix=docfx", fmt.Sprintf("--metadata-file=%s/docs.metadata", crateOutDir), crateOutDir); err != nil {
115114
fmt.Printf("error uploading files: %v\n", err)
116115
}
117116
}

doc/rustdocfx/preflight.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ import (
2121
)
2222

2323
// preFlightTests() verifies all the required commands are available.
24-
func preFlightTests(upload bool) error {
25-
26-
// TODO: Preflight checks for:
27-
// cargo workspaces
28-
// cargo rustdoc
29-
// docuploader
30-
// Failfast if not installed.
24+
func preFlightTests(upload string) error {
3125
if err := testExternalCommand("cargo", "--version"); err != nil {
3226
return fmt.Errorf("got an error trying to run `cargo --version`, the instructions on https://www.rust-lang.org/learn/get-started may solve this problem: %w", err)
3327
}
@@ -40,7 +34,7 @@ func preFlightTests(upload bool) error {
4034
if err := testExternalCommand("cargo", "workspaces", "--version"); err != nil {
4135
return fmt.Errorf("got an error trying to run `cargo workspaces --version`, run `cargo install --locked cargo-workspaces` to solve this problem: %w", err)
4236
}
43-
if !upload {
37+
if upload == "" {
4438
return nil
4539
}
4640
if err := testExternalCommand("docuploader", "--version"); err != nil {

0 commit comments

Comments
 (0)