Skip to content

Commit

Permalink
feat: adding single language build support (#44)
Browse files Browse the repository at this point in the history
By specifying "LANGUAGE=", users can build only that individual language.
  • Loading branch information
dandhlee committed Dec 9, 2020
1 parent 652ecf3 commit 95977aa
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions .trampolinerc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pass_down_envvars+=(
"SOURCE_BLOB" # Set to force regeneration of a single source blob.
"FORCE_GENERATE_ALL" # Set to force regeneration of all blobs.
"TEST_BUCKET" # Must set when running tests.
"LANGUAGE" # For specifying specific language builds.
)

# Prevent unintentional override on the default image.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ See `.trampolinerc` for the canonical list of relevant environment variables.
* `SOURCE_BUCKET`: The bucket to use for regeneration. See Running locally.
* `SOURCE_BLOB`: A single blob to regenerate. Only the blob name - do not
include `gs://` or the bucket.
* `LANGUAGE`: Regenerates all docs under specified language. For example: `LANGUAGE:dotnet`
* `FORCE_GENERATE_ALL`: Set to `true` to regenerate all docs.

### Formatting and style
Expand Down
18 changes: 18 additions & 0 deletions docpipeline/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,23 @@ def build_one_doc(bucket_name, object_name, credentials):
sys.exit(1)


@main.command()
@click.argument("bucket_name")
@click.argument("language")
@click.option(
"--credentials",
default=credentials.find(),
help="Path to the credentials file to use for Google Cloud Storage.",
)
def build_language_docs(bucket_name, language, credentials):
verify(credentials)

try:
generate.build_language_docs(bucket_name, language, credentials)
except Exception as e:
log.error(e)
sys.exit(1)


if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions docpipeline/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,10 @@ def build_new_docs(bucket_name, credentials):
if new_name not in other_names:
new_blobs.append(blob)
build_blobs(new_blobs, credentials)


def build_language_docs(bucket_name, language, credentials):
all_blobs = storage_client(credentials).list_blobs(bucket_name)
language_prefix = DOCFX_PREFIX + language + "-"
docfx_blobs = [blob for blob in all_blobs if blob.name.startswith(language_prefix)]
build_blobs(docfx_blobs, credentials)
2 changes: 2 additions & 0 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ python3 -m pip install .

if [ "$FORCE_GENERATE_ALL" == "true" ]; then
python3 docpipeline/__main__.py build-all-docs $SOURCE_BUCKET
elif [ -n "$LANGUAGE" ]; then
python3 docpipeline/__main__.py build-language-docs $SOURCE_BUCKET $LANGUAGE
elif [ -n "$SOURCE_BLOB" ]; then
python3 docpipeline/__main__.py build-one-doc $SOURCE_BUCKET $SOURCE_BLOB
else
Expand Down
14 changes: 14 additions & 0 deletions tests/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,17 @@ def test_generate(yaml_dir, tmpdir):
html_blob = bucket.get_blob(html_blob_name)
t3 = html_blob.updated
assert t2 != t3

# Force generation of Python docs and verify timestamp
language = "python"
generate.build_language_docs(test_bucket, language, credentials)
html_blob = bucket.get_blob(html_blob_name)
t4 = html_blob.updated
assert t3 != t4

# Force generation of Go docs, verify timestamp does not change
language = "go"
generate.build_language_docs(test_bucket, language, credentials)
html_blob = bucket.get_blob(html_blob_name)
t5 = html_blob.updated
assert t4 == t5

0 comments on commit 95977aa

Please sign in to comment.