Skip to content

Commit e367fdd

Browse files
committed
Initial commit
0 parents  commit e367fdd

File tree

6 files changed

+359
-0
lines changed

6 files changed

+359
-0
lines changed

Diff for: .editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
max_line_length = 80
8+
indent_size = 4
9+
10+
[*.yml]
11+
indent_size = 2

Diff for: .github/workflows/build.yml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build tools cache
2+
on:
3+
schedule:
4+
- cron: '*/30 * * * *'
5+
6+
jobs:
7+
build:
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
max-parallel: 3
12+
matrix:
13+
os:
14+
- windows-2019
15+
- ubuntu-18.04
16+
- macos-10.15
17+
crate:
18+
- cargo-audit
19+
- cargo-udeps
20+
- cargo-nono
21+
- cross
22+
- sccache
23+
steps:
24+
- uses: actions/checkout@v2
25+
- uses: actions/setup-python@v1
26+
with:
27+
python-version: 3.8
28+
- name: Build and upload binary crate
29+
- name: Install dependencies
30+
run: python -m pip install -r requirements.txt
31+
- name: Build ${{ matrix.crate }}
32+
run: python build.py
33+
env:
34+
CRATE: ${{ matrix.crate }}
35+
RUNNER: ${{ matrix.os }}
36+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
37+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

Diff for: .gitignore

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
cover/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
db.sqlite3-journal
64+
65+
# Flask stuff:
66+
instance/
67+
.webassets-cache
68+
69+
# Scrapy stuff:
70+
.scrapy
71+
72+
# Sphinx documentation
73+
docs/_build/
74+
75+
# PyBuilder
76+
.pybuilder/
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# IPython
83+
profile_default/
84+
ipython_config.py
85+
86+
# pyenv
87+
# For a library or package, you might want to ignore these files since the code is
88+
# intended to run in multiple environments; otherwise, check them in:
89+
# .python-version
90+
91+
# pipenv
92+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
94+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
95+
# install all needed dependencies.
96+
#Pipfile.lock
97+
98+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
99+
__pypackages__/
100+
101+
# Celery stuff
102+
celerybeat-schedule
103+
celerybeat.pid
104+
105+
# SageMath parsed files
106+
*.sage.py
107+
108+
# Environments
109+
.env
110+
.venv
111+
env/
112+
venv/
113+
ENV/
114+
env.bak/
115+
venv.bak/
116+
117+
# Spyder project settings
118+
.spyderproject
119+
.spyproject
120+
121+
# Rope project settings
122+
.ropeproject
123+
124+
# mkdocs documentation
125+
/site
126+
127+
# mypy
128+
.mypy_cache/
129+
.dmypy.json
130+
dmypy.json
131+
132+
# Pyre type checker
133+
.pyre/
134+
135+
# pytype static type analyzer
136+
.pytype/
137+
138+
# Cython debug symbols
139+
cython_debug/
140+
141+
# static files generated from Django application using `collectstatic`
142+
media
143+
static

Diff for: README.md

Whitespace-only changes.

Diff for: build.py

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
import os
2+
import os.path
3+
import sys
4+
import logging
5+
import logging.config
6+
import subprocess
7+
8+
import boto3
9+
import requests
10+
11+
S3_REGION = 'us-east-2'
12+
S3_BUCKET = 'actions-rs.install.binary-cache'
13+
S3_OBJECT_URL = 'https://s3.{region}.amazonaws.com/{bucket}/{{object_name}}'.format(
14+
region=S3_REGION,
15+
bucket=S3_BUCKET,
16+
)
17+
S3_OBJECT_NAME = '{crate}/{runner}/{crate}-{version}{ext}'
18+
19+
MAX_VERSIONS_TO_BUILD = 1
20+
21+
22+
def crate_info(crate):
23+
url = 'https://crates.io/api/v1/crates/{}'.format(crate)
24+
logging.info('Requesting crates.io URL: {}'.format(url))
25+
26+
resp = requests.get(url)
27+
resp.raise_for_status()
28+
29+
versions = filter(lambda v: not v['yanked'], resp.json()['versions'])
30+
for version in list(versions)[:MAX_VERSIONS_TO_BUILD]:
31+
yield version['num']
32+
33+
34+
def exists(runner, crate, version):
35+
"""Check if `crate` with version `version` for `runner` environment
36+
already exists in the S3 bucket."""
37+
38+
ext = '.exe' if runner.lower().startswith('windows') else ''
39+
object_name = S3_OBJECT_NAME.format(
40+
crate=crate,
41+
runner=runner,
42+
version=version,
43+
ext=ext,
44+
)
45+
url = S3_OBJECT_URL.format(object_name=object_name)
46+
logging.info(
47+
'Check if {crate} == {version} for {runner} exists in S3 bucket at {url}'.format(
48+
crate=crate,
49+
version=version,
50+
runner=runner,
51+
url=url,
52+
))
53+
resp = requests.head(url, allow_redirects=True)
54+
55+
if resp.ok:
56+
logging.debug(
57+
'{crate} == {version} for {runner} already exists in S3 bucket'.format(
58+
crate=crate,
59+
version=version,
60+
runner=runner,
61+
))
62+
return True
63+
64+
else:
65+
logging.warning(
66+
'{crate} == {version} for {runner} does not exists in S3 bucket'.format(
67+
crate=crate,
68+
version=version,
69+
runner=runner,
70+
))
71+
return False
72+
73+
74+
def build(runner, crate, version):
75+
root = os.path.join(
76+
os.getcwd(),
77+
'build',
78+
'{}-{}-{}'.format(runner, crate, version)
79+
)
80+
81+
logging.info('Preparing build root at {}'.format(root))
82+
os.makedirs(root, exist_ok=True)
83+
84+
args = 'cargo install --version {version} --root {root} --no-track {crate}'.format(
85+
version=version,
86+
root=root,
87+
crate=crate,
88+
)
89+
subprocess.check_call(args, shell=True)
90+
91+
return os.path.join(root, 'bin', os.listdir(os.path.join(root, 'bin'))[0])
92+
93+
94+
def upload(client, runner, crate, version, path):
95+
"""Upload prebuilt `crate` with `version` for `runner` environment
96+
located at `path` to the S3 bucket."""
97+
98+
ext = '.exe' if runner.lower().startswith('windows') else ''
99+
object_name = S3_OBJECT_NAME.format(
100+
crate=crate,
101+
runner=runner,
102+
version=version,
103+
ext=ext,
104+
)
105+
106+
logging.info('Uploading {path} to {bucket}/{name}'.format(
107+
path=path,
108+
bucket=S3_BUCKET,
109+
name=object_name,
110+
))
111+
client.upload_file(path, S3_BUCKET, object_name)
112+
113+
114+
class LogFormatter(logging.Formatter):
115+
def format(self, record):
116+
msg = record.getMessage()
117+
if record.levelno == logging.DEBUG:
118+
return '::debug::{}'.format(msg)
119+
elif record.levelno == logging.INFO:
120+
return msg
121+
elif record.levelno in (logging.WARN, logging.WARNING):
122+
return '::warning::{}'.format(msg)
123+
else:
124+
return '::error::{}'.format(msg)
125+
126+
127+
if __name__ == '__main__':
128+
logging.config.dictConfig({
129+
'version': 1,
130+
'disable_existing_loggers': True,
131+
'formatters': {
132+
'gha': {
133+
'()': LogFormatter,
134+
},
135+
},
136+
'handlers': {
137+
'stdout': {
138+
'class': 'logging.StreamHandler',
139+
'formatter': 'gha',
140+
},
141+
},
142+
'loggers': {
143+
'': {
144+
'handlers': ['stdout'],
145+
'level': 'DEBUG',
146+
}
147+
}
148+
})
149+
150+
crate = os.environ['CRATE']
151+
runner = os.environ['RUNNER']
152+
153+
s3_client = boto3.client(
154+
's3',
155+
region_name=S3_REGION,
156+
aws_access_key_id=os.environ['AWS_ACCESS_KEY_ID'],
157+
aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY']
158+
)
159+
160+
logging.info('Building {} crate for {} environment'.format(crate, runner))
161+
for version in crate_info(crate):
162+
if not exists(runner, crate, version):
163+
path = build(runner, crate, version)
164+
logging.info('Built {} at {}'.format(crate, path))
165+
166+
upload(s3_client, runner, crate, version, path)

Diff for: requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
requests
2+
boto3

0 commit comments

Comments
 (0)