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

Upload Index html as text/html #30

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions .github/scripts/s3-deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def get_tag(ci):
BUILD38_S3_KEY = os.getenv("BUILD38_S3_KEY", None)
BUILD38_S3_SECRET = os.getenv("BUILD38_S3_SECRET", None)

BINARIES_CONTENT_TYPE = "binary/octet-stream"
INDEX_CONTENT_TYPE = "text/html"

omvll_keys_set = True
build38_keys_set = True

Expand Down Expand Up @@ -150,7 +153,7 @@ def get_tag(ci):
aws_secret_access_key=BUILD38_S3_SECRET
)

def push(file: str, dir_name: str, s3_bucket_name: str, s3_resource, use_timestamp=True):
def push(file: str, dir_name: str, s3_bucket_name: str, s3_resource, s3_content_type: str, use_timestamp=True):
zipfile = pathlib.Path(file)
if use_timestamp:
now = datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
Expand All @@ -160,7 +163,7 @@ def push(file: str, dir_name: str, s3_bucket_name: str, s3_resource, use_timesta
logger.info("Uploading %s to %s", file, dst)
try:
obj = s3_resource.Object(s3_bucket_name, dst)
obj.put(Body=zipfile.read_bytes())
obj.put(Body=zipfile.read_bytes(), ContentType=s3_content_type)
return 0
except ClientError as e:
logger.error("S3 push failed: %s", e)
Expand Down Expand Up @@ -193,34 +196,34 @@ def generate_index(dir_name: str, s3_bucket_name: str, s3_resource):
logger.info("[ZIP ] Uploading '%s'", file.as_posix())
# Nightly deployment
if omvll_keys_set:
push(file.as_posix(), dir_name, OMVLL_S3_BUCKET, omvll_s3)
push(file.as_posix(), dir_name, OMVLL_S3_BUCKET, omvll_s3, BINARIES_CONTENT_TYPE)
# Experimental deployment
if build38_keys_set:
push(file.as_posix(), dir_name, BUILD38_S3_BUCKET, build38_s3)
push(file.as_posix(), dir_name, BUILD38_S3_BUCKET, build38_s3, BINARIES_CONTENT_TYPE)

for file in DIST_DIR.glob("*.tar.gz"):
logger.info("[TAR.GZ] Uploading '%s'", file.as_posix())
# Nightly deployment
if omvll_keys_set:
push(file.as_posix(), dir_name, OMVLL_S3_BUCKET, omvll_s3)
push(file.as_posix(), dir_name, OMVLL_S3_BUCKET, omvll_s3, BINARIES_CONTENT_TYPE)
# Experimental deployment
if build38_keys_set:
push(file.as_posix(), dir_name, BUILD38_S3_BUCKET, build38_s3)
push(file.as_posix(), dir_name, BUILD38_S3_BUCKET, build38_s3, BINARIES_CONTENT_TYPE)

if omvll_keys_set:
nightly_index = generate_index(dir_name, OMVLL_S3_BUCKET, omvll_s3)
with tempfile.TemporaryDirectory() as tmp:
tmp = pathlib.Path(tmp)
index = (tmp / "index.html")
index.write_text(nightly_index)
push(index.as_posix(), dir_name, OMVLL_S3_BUCKET, omvll_s3, False)
push(index.as_posix(), dir_name, OMVLL_S3_BUCKET, omvll_s3, INDEX_CONTENT_TYPE, False)

if build38_keys_set:
experimental_index = generate_index(dir_name, BUILD38_S3_BUCKET, build38_s3)
with tempfile.TemporaryDirectory() as tmp:
tmp = pathlib.Path(tmp)
index = (tmp / "index.html")
index.write_text(experimental_index)
push(index.as_posix(), dir_name, BUILD38_S3_BUCKET, build38_s3, False)
push(index.as_posix(), dir_name, BUILD38_S3_BUCKET, build38_s3, INDEX_CONTENT_TYPE, False)

logger.info("Done!")
Loading