Skip to content

Commit

Permalink
run sync-release-assets on PR for testing purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Oct 23, 2023
1 parent 7e5991c commit c4112aa
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 8 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/on_pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,12 @@ jobs:
CONCURRENCY: pr-${{ github.event.pull_request.number }}
PR_NUMBER: ${{ github.event.pull_request.number }}
secrets: inherit

sync-release-assets:
name: "TEST: Sync pre-release assets with build.rerun.io"
if: github.event.pull_request.head.repo.owner.login == 'rerun-io'
uses: ./.github/workflows/reusable_sync_release_assets.yml
with:
CONCURRENCY: pr-${{ github.event.pull_request.number }}
RELEASE_VERSION: prerelease
secrets: inherit
35 changes: 28 additions & 7 deletions .github/workflows/reusable_sync_release_assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ on:
type: string
default: ""

permissions:
contents: "write"
id-token: write

concurrency:
group: ${{ inputs.CONCURRENCY }}-sync-assets
cancel-in-progress: true
Expand All @@ -20,16 +24,34 @@ jobs:
name: Upload assets from build.rerun.io

permissions:
contents: "read"
contents: "write"
id-token: "write"

runs-on: ubuntu-latest
# container:
# image: rerunio/ci_docker:0.10.0

steps:
# - name: Update CA Certificates
# run: sudo apt-get install --reinstall ca-certificates

- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || '' }}

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.x
python-version: "3.11"
# cache: "pip"
# cache-dependency-path: "scripts/ci/requirements.txt"

- name: Install Python dependencies
run: pip install google-cloud-storage "PyGithub==1.59.0" "requests>=2.31,<3"
# run: |
# pip install --upgrade pip
# pip install -r scripts/ci/requirements.txt

- id: "auth"
uses: google-github-actions/auth@v1
Expand All @@ -42,12 +64,11 @@ jobs:
with:
version: ">= 363.0.0"

- name: Install deps
run: pip install google-cloud-storage PyGithub

- name: Sync assets
run: |
python scripts/ci/sync_release_assets.py \
# sed -i 's/DEFAULT@SECLEVEL=2/DEFAULT@SECLEVEL=1/' /etc/ssl/openssl.cnf
# grep SECLEVEL /etc/ssl/openssl.cnf
python ./scripts/ci/sync_release_assets.py \
--github-release ${{ inputs.RELEASE_VERSION }} \
--github-token ${{ secrets.GITHUB_TOKEN }} \
--remove --update
31 changes: 30 additions & 1 deletion scripts/ci/sync_release_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from __future__ import annotations

import argparse
import github
import requests
from typing import Dict

from github import Github
Expand Down Expand Up @@ -91,10 +93,36 @@ def update_release_assets(release: GitRelease, assets: Assets):

for name, blob in assets.items():
with blob.open("rb") as f:
print("MANUAL THROTTLING TEST, DON'T MOVE")
import time

time.sleep(30)
print(f" Uploading {name}…")
release.upload_asset_from_memory(f, blob.size, name, content_type="application/octet-stream")


# TODO: explain
def create_custom_tls_adapter() -> requests.Session:
import requests
import ssl
from urllib3 import poolmanager

class TLSAdapter(requests.adapters.HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False):
"""Create and initialize the urllib3 PoolManager."""
ctx = ssl.create_default_context()
ctx.set_ciphers("DEFAULT@SECLEVEL=1")
self.poolmanager = poolmanager.PoolManager(
num_pools=connections, maxsize=maxsize, block=block, ssl_version=ssl.PROTOCOL_TLS, ssl_context=ctx
)

session = requests.session()
session.mount("https://", TLSAdapter())

print("created custom requester")
return session


def main() -> None:
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--github-token", required=True, help="GitHub token")
Expand All @@ -106,7 +134,8 @@ def main() -> None:
parser.add_argument("--update", action="store_true", help="Update new assets to the specified release")
args = parser.parse_args()

gh = Github(args.github_token)
gh = Github(args.github_token, timeout=99999999)
# gh._Github__requester._Requester__httpsConnectionClass.session = create_custom_tls_adapter()
repo = gh.get_repo(args.github_repository)
release = repo.get_release(args.github_release)
commit = dict([(tag.name, tag.commit) for tag in repo.get_tags()])[args.github_release]
Expand Down

0 comments on commit c4112aa

Please sign in to comment.