-
-
Notifications
You must be signed in to change notification settings - Fork 10
Implement CDN uploading #34
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| name: Publish Apps | ||
|
|
||
| inputs: | ||
| sdk_version: | ||
| description: The SDK version that determines the path on the CDN | ||
| required: true | ||
|
|
||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - name: 'Download cdn-files' | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: 'cdn-files' | ||
| path: cdn_files | ||
| - name: 'Install boto3' | ||
| shell: bash | ||
| run: pip install boto3 | ||
| - name: 'Upload files' | ||
| shell: bash | ||
| run: python Buildscripts/CDN/upload-app-files.py cdn_files ${{ inputs.sdk_version }} ${{ env.CDN_ID }} ${{ env.CDN_TOKEN_NAME }} ${{ env.CDN_TOKEN_VALUE }} | ||
|
KenVanHoeylandt marked this conversation as resolved.
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import os | ||
| import sys | ||
| import boto3 | ||
|
|
||
| SHELL_COLOR_RED = "\033[91m" | ||
| SHELL_COLOR_ORANGE = "\033[93m" | ||
| SHELL_COLOR_RESET = "\033[m" | ||
|
|
||
| def print_warning(message): | ||
| print(f"{SHELL_COLOR_ORANGE}WARNING: {message}{SHELL_COLOR_RESET}") | ||
|
|
||
| def print_error(message): | ||
| print(f"{SHELL_COLOR_RED}ERROR: {message}{SHELL_COLOR_RESET}") | ||
|
|
||
| def print_help(): | ||
| print("Usage: python upload-app-files.py [path] [sdkVersion] [cloudflareAccountId] [cloudflareTokenName] [cloudflareTokenValue]") | ||
| print("") | ||
| print("Options:") | ||
| print(" --index-only Upload only apps.json") | ||
|
|
||
| def exit_with_error(message): | ||
| print_error(message) | ||
| sys.exit(1) | ||
|
|
||
| def main(path: str, sdk_version: str, cloudflare_account_id, cloudflare_token_name: str, cloudflare_token_value: str, index_only: bool): | ||
| if not os.path.exists(path): | ||
| exit_with_error(f"Path not found: {path}") | ||
| s3 = boto3.client( | ||
| service_name="s3", | ||
| endpoint_url=f"https://{cloudflare_account_id}.r2.cloudflarestorage.com", | ||
| aws_access_key_id=cloudflare_token_name, | ||
| aws_secret_access_key=cloudflare_token_value, | ||
| region_name="auto" | ||
| ) | ||
|
KenVanHoeylandt marked this conversation as resolved.
|
||
| files_to_upload = os.listdir(path) | ||
| if index_only: | ||
| files_to_upload = [f for f in files_to_upload if f == 'apps.json'] | ||
| else: | ||
| # Ensure apps.json is uploaded last so it never references files that | ||
| # haven't finished uploading yet. | ||
| files_to_upload.sort(key=lambda f: f == 'apps.json') | ||
| counter = 1 | ||
| total = len(files_to_upload) | ||
| for file_name in files_to_upload: | ||
| object_path = f"apps/{sdk_version}/{file_name}" | ||
| print(f"[{counter}/{total}] Uploading {file_name} to {object_path}") | ||
| file_path = os.path.join(path, file_name) | ||
| try: | ||
| s3.upload_file(file_path, "tactility", object_path) | ||
| except Exception as e: | ||
| exit_with_error(f"Failed to upload {file_name}: {str(e)}") | ||
| counter += 1 | ||
|
|
||
| if __name__ == "__main__": | ||
| print("Tactility CDN Apps Uploader") | ||
| if "--help" in sys.argv: | ||
| print_help() | ||
| sys.exit() | ||
| # Argument validation | ||
| if len(sys.argv) < 6: | ||
| print_help() | ||
| sys.exit(1) | ||
| main( | ||
| path=sys.argv[1], | ||
| sdk_version=sys.argv[2], | ||
| cloudflare_account_id=sys.argv[3], | ||
| cloudflare_token_name=sys.argv[4], | ||
| cloudflare_token_value=sys.argv[5], | ||
| index_only="--index-only" in sys.argv | ||
| ) | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.