Skip to content

Commit

Permalink
Docs/conditional publish (Azure#428)
Browse files Browse the repository at this point in the history
* Change extension publishing to be conditional on relative dates of last
update.

* Update .gitignore to properly ignore VSCode

* Lock wheel version and fix git info formatting

* Remove exposed port from Dockerfile
  • Loading branch information
sptramer authored and williexu committed Nov 27, 2018
1 parent a33df51 commit b877f25
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ env27/
/site

# VS Code
.vscode/settings.json
.vscode

# mypy
.mypy_cache/
Expand Down
13 changes: 11 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ jobs:
script: ./scripts/ci/test_index_ref_doc.sh
python: 3.6
- stage: publish
python: 3.6
script: docker run --rm -e TRAVIS_BUILD_ID=$TRAVIS_BUILD_ID -e TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG -e TRAVIS_COMMIT=$TRAVIS_COMMIT -e GH_TOKEN=$GH_TOKEN -e DOC_REPO_SLUG='Azure/azure-docs-cli-python' -e REPO_LOCATION=/repo -v $PWD:/repo sttramer/az-ext-list-publisher:0.2.0
script: |
docker run \
--rm \
-e TRAVIS_BUILD_ID=$TRAVIS_BUILD_ID \
-e TRAVIS_REPO_SLUG=$TRAVIS_REPO_SLUG \
-e TRAVIS_COMMIT=$TRAVIS_COMMIT \
-e GH_TOKEN=$GH_TOKEN \
-e DOC_REPO_SLUG='Azure/azure-docs-cli-python' \
-e REPO_LOCATION=/repo \
-v $PWD:/repo \
sttramer/az-ext-list-publisher:0.3.0
env: PURPOSE='SyncAvailableExtensionsDoc'
if: repo = Azure/azure-cli-extensions and branch = master and type = cron
fast_finish: true
Expand Down
31 changes: 17 additions & 14 deletions scripts/avail-ext-doc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
REPO_CLI_DOCS = 'https://{}@github.com/{}'.format(GH_TOKEN, DOC_REPO_SLUG)
CLONED_CLI_DOCS = os.path.join(os.path.sep, 'doc-repo')
AVAILABLE_EXTENSIONS_DOC = os.path.join(CLONED_CLI_DOCS, 'docs-ref-conceptual', 'azure-cli-extensions-list.md')
TEMPLATE_FILE = "list-template.md"
TEMPLATE_FILE = os.path.join(SCRIPTS_LOCATION, "avail-ext-doc", "list-template.md")

sys.path.insert(0, SCRIPTS_LOCATION)
from ci.util import get_index_data
from ci.util import get_index_data, INDEX_PATH

def get_extensions():
extensions = []
Expand All @@ -52,26 +52,26 @@ def get_extensions():
})
return extensions

def update_extensions_list(template_file, output_file):
def update_extensions_list(output_file):
template = None
with open(template_file, 'r') as doc_template:
with open(TEMPLATE_FILE, 'r') as doc_template:
template = Template(doc_template.read())
if template is None:
raise RuntimeError("Failed to read template file {}".format(template_file))
with open(output_file, 'w') as output:
output.write(template.render(extensions=get_extensions(), date=datetime.date.today().strftime("%m/%d/%Y")))

def date_only_diff(diff):
if not diff:
return True
stats = diff.split('\t')
return stats[0] == 1 and stats[1] == 1
def needs_update(doc_repo):
date_format="%Y-%m-%d %H:%M:%S %z"
ext_repo = Repo(REPO_LOCATION)
doc_updated = datetime.datetime.strptime(doc_repo.git.log(AVAILABLE_EXTENSIONS_DOC, pretty="format:%ai", n=1), date_format)
template_updated = datetime.datetime.strptime(ext_repo.git.log(TEMPLATE_FILE, pretty="format:%ai", n=1), date_format)
index_updated = datetime.datetime.strptime(ext_repo.git.log(INDEX_PATH, pretty="format:%ai", n=1), date_format)

return (doc_updated < index_updated) or (doc_updated < template_updated)

def commit_update(doc_repo):
doc_repo.git.add(doc_repo.working_tree_dir)
if date_only_diff(doc_repo.git.diff(staged=True, numstat=True)):
logger.warning('No changes. Exiting')
return
github_con = Github(GH_TOKEN)
user = github_con.get_user()
doc_repo.git.config('user.email', user.email or 'azpycli@microsoft.com')
Expand All @@ -94,8 +94,11 @@ def commit_update(doc_repo):

def main():
doc_repo = Repo.clone_from(REPO_CLI_DOCS, CLONED_CLI_DOCS)
update_extensions_list(TEMPLATE_FILE, AVAILABLE_EXTENSIONS_DOC)
commit_update(doc_repo)
if needs_update(doc_repo):
update_extensions_list(AVAILABLE_EXTENSIONS_DOC)
commit_update(doc_repo)
else:
logger.info("No update to docs index required, skipping publish")

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion scripts/avail-ext-doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Jinja2==2.10
GitPython==2.1.8
PyGithub>=1.36
wheel>=0.31.1
wheel==0.31.1

0 comments on commit b877f25

Please sign in to comment.