-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(workflow): add cache buster and exit on no updates
- Loading branch information
1 parent
a0b2538
commit 48e2ed8
Showing
4 changed files
with
25 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
node_modules | ||
*.vsix | ||
.mypy_cache | ||
.python-version | ||
|
||
# Ignore everything in the test folder | ||
/test/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,36 @@ | ||
import hashlib | ||
from datetime import datetime, timezone | ||
|
||
import requests | ||
|
||
|
||
def get_resource_spec(): | ||
# Add a cache buster using a timezone-aware datetime object | ||
cfn_resource_spec_url = "https://d1uauaxba7bl26.cloudfront.net/latest/gzip/CloudFormationResourceSpecification.json" | ||
# Load the source data and hash it | ||
response = requests.get(cfn_resource_spec_url) | ||
|
||
current_time = datetime.now(timezone.utc).timestamp() | ||
response = requests.get(cfn_resource_spec_url, params={"nocache": current_time}) | ||
response.raise_for_status() | ||
return response | ||
|
||
|
||
def calculate_hash(content): | ||
return hashlib.sha256(content).hexdigest() | ||
|
||
|
||
# Load the current hash | ||
with open("src/current-cfn-spec-hash", "r+") as file: | ||
current_hash = file.read() | ||
# Load the source data and hash it | ||
new_hash = hashlib.md5(get_resource_spec().content).hexdigest() | ||
current_hash = file.read().strip() | ||
new_hash = calculate_hash(get_resource_spec().content) | ||
|
||
if new_hash == current_hash: | ||
print(f"The new hash: {new_hash} matches with our current hash: {current_hash}.") | ||
print("The snippets are up-to-date, stopping the pipeline.") | ||
exit(1) | ||
else: | ||
print( | ||
f"Found an update in the cfn-resource-specification, let's update the hash to: {new_hash}" | ||
" and continue with updating the cfn resource snippets!" | ||
f"Found an update in the cfn-resource-specification, let's update the hash to: {new_hash} " | ||
"and continue with updating the cfn resource snippets!" | ||
) | ||
file.seek(0) | ||
file.write(new_hash) | ||
file.truncate() |