Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding single language build support #44

Merged
merged 6 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
dandhlee marked this conversation as resolved.
Show resolved Hide resolved
)

# 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):
dandhlee marked this conversation as resolved.
Show resolved Hide resolved
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