-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,105 additions
and
109 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
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,35 +1,43 @@ | ||
name: testcontainers requirements | ||
on: | ||
push: | ||
branches: [master] | ||
branches: [main] | ||
pull_request: | ||
branches: [master] | ||
branches: [main] | ||
|
||
jobs: | ||
requirements: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: | ||
- "3.7" | ||
- "3.8" | ||
- "3.9" | ||
- "3.10" | ||
- "3.11" | ||
runs-on: ubuntu-latest | ||
runtime: | ||
- machine: ubuntu-latest | ||
python-version: "3.7" | ||
- machine: ubuntu-latest | ||
python-version: "3.8" | ||
- machine: ubuntu-latest | ||
python-version: "3.9" | ||
- machine: ubuntu-latest | ||
python-version: "3.10" | ||
- machine: ubuntu-latest | ||
python-version: "3.11" | ||
- machine: windows-latest | ||
python-version: "3.10" | ||
- machine: macos-latest | ||
python-version: "3.10" | ||
runs-on: ${{ matrix.runtime.machine }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup python ${{ matrix.python-version }} | ||
- name: Setup python ${{ matrix.runtime.python-version }} | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
python-version: ${{ matrix.runtime.python-version }} | ||
- name: Update pip and install pip-tools | ||
run: pip install --upgrade pip pip-tools | ||
- name: Build requirements | ||
run: | | ||
rm requirements/${{ matrix.python-version }}.txt | ||
pip-compile --resolver=backtracking -v --upgrade -o requirements/${{ matrix.python-version }}.txt | ||
run: pip-compile --resolver=backtracking -v --upgrade -o requirements.txt | ||
- name: Store requirements as artifact | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: requirements-${{ matrix.python-version }}.txt | ||
path: requirements/${{ matrix.python-version }}.txt | ||
name: requirements-${{ matrix.runtime.machine }}-${{ matrix.runtime.python-version }}.txt | ||
path: requirements.txt |
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 |
---|---|---|
|
@@ -72,3 +72,4 @@ venv | |
.DS_Store | ||
.python-version | ||
.env | ||
.github-token |
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
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import argparse | ||
import io | ||
import pathlib | ||
import requests | ||
import shutil | ||
import tempfile | ||
import zipfile | ||
|
||
|
||
def __main__() -> None: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("--owner", default="testcontainers") | ||
parser.add_argument("--repo", default="testcontainers-python") | ||
parser.add_argument("--run", help="GitHub Action run id") | ||
parser.add_argument("--pr", help="GitHub PR number") | ||
parser.add_argument("--branch", default="main") | ||
parser.add_argument("--token", help="GitHub autentication token") | ||
args = parser.parse_args() | ||
|
||
# Get an access token. | ||
if args.token: | ||
token = args.token | ||
elif (path := pathlib.Path(".github-token")).is_file(): | ||
token = path.read_text().strip() | ||
else: | ||
token = input("we need a GitHub access token to fetch the requirements; please visit " | ||
"https://github.com/settings/tokens/new, create a token with `public_repo` " | ||
"scope, and paste it here: ").strip() | ||
cache = input("do you want to cache the token in a `.github-token` file [Ny]? ") | ||
if cache.lower().startswith("y"): | ||
path.write_text(token) | ||
|
||
headers = { | ||
"Authorization": f"Bearer {token}", | ||
} | ||
base_url = f"https://api.github.com/repos/{args.owner}/{args.repo}" | ||
|
||
if args.run: # Run id was specified. | ||
run = args.run | ||
elif args.pr: # PR was specified, let's get the most recent run id. | ||
print(f"fetching most recent commit for PR #{args.pr}") | ||
response = requests.get(f"{base_url}/pulls/{args.pr}", headers=headers) | ||
response.raise_for_status() | ||
response = response.json() | ||
head_sha = response["head"]["sha"] | ||
else: # Nothing was specified, let's get the most recent run id on the main branch. | ||
print(f"fetching most recent commit for branch `{args.branch}`") | ||
response = requests.get(f"{base_url}/branches/{args.branch}", headers=headers) | ||
response.raise_for_status() | ||
response = response.json() | ||
head_sha = response["commit"]["sha"] | ||
|
||
# List all completed runs and find the one that generated the requirements. | ||
response = requests.get(f"{base_url}/actions/runs", headers=headers, params={ | ||
"head_sha": head_sha, | ||
"status": "success", | ||
}) | ||
response.raise_for_status() | ||
response = response.json() | ||
|
||
# Get the requirements run. | ||
runs = [run for run in response["workflow_runs"] if | ||
run["path"].endswith("requirements.yml")] | ||
if len(runs) != 1: | ||
raise RuntimeError(f"could not identify unique workflow run: {runs}") | ||
run = runs[0]["id"] | ||
|
||
# Get all the artifacts. | ||
print(f"fetching artifacts for run {run} ...") | ||
url = f"{base_url}/actions/runs/{run}/artifacts" | ||
response = requests.get(url, headers=headers) | ||
response.raise_for_status() | ||
response = response.json() | ||
artifacts = response["artifacts"] | ||
print(f"discovered {len(artifacts)} artifacts") | ||
|
||
# Get the content for each artifact and save it. | ||
for artifact in artifacts: | ||
name: str = artifact["name"] | ||
name = name.removeprefix("requirements-") | ||
print(f"fetching artifact {name} ...") | ||
response = requests.get(artifact["archive_download_url"], headers=headers) | ||
response.raise_for_status() | ||
with zipfile.ZipFile(io.BytesIO(response.content)) as zip, \ | ||
tempfile.TemporaryDirectory() as tempdir: | ||
zip.extract("requirements.txt", tempdir) | ||
shutil.move(pathlib.Path(tempdir) / "requirements.txt", | ||
pathlib.Path("requirements") / name) | ||
|
||
print("done") | ||
|
||
|
||
if __name__ == "__main__": | ||
__main__() |
Oops, something went wrong.