Skip to content

Commit 0a0c686

Browse files
authored
Merge pull request #5 from LeetCode-OpenSource/upload-to-ali-oss
Upload to ali oss
2 parents d4cd332 + fa6f3b5 commit 0a0c686

File tree

6 files changed

+63
-4
lines changed

6 files changed

+63
-4
lines changed

.circleci/config.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ build: &build
3232

3333
deploy: &deploy
3434
docker:
35-
- image: tsub/ghr:latest
35+
- image: broooooklyn/rust-python:latest
3636
working_directory: /mnt/crate
3737
steps:
3838
- attach_workspace:
@@ -43,7 +43,8 @@ deploy: &deploy
4343
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";
4444
then
4545
export GIT_TAG="$(git describe --tags $(git rev-list --tags --max-count=1))"; \
46-
ghr -u "${CIRCLE_PROJECT_USERNAME}" -r "${CIRCLE_PROJECT_REPONAME}" "${GIT_TAG}" build/lib/py_sourcemap/*.so
46+
ghr -u "${CIRCLE_PROJECT_USERNAME}" -r "${CIRCLE_PROJECT_REPONAME}" "${GIT_TAG}" build/lib/py_sourcemap/*.so && \
47+
python upload-ali-oss.py
4748
else
4849
echo "Not a release, skipping publish"
4950
fi

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,9 @@ deploy:
3636
skip_cleanup: true
3737
on:
3838
tags: true
39+
40+
deploy:
41+
provider: script
42+
script: python upload-ali-oss.py
43+
on:
44+
tags: true

Dockerfile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ FROM ubuntu:18.04
22

33
ARG PYTHON_VERSION=3.6
44

5+
ENV GHR_VERSION="0.9.0"
6+
57
ENV RUSTUP_HOME=/usr/local/rustup \
68
CARGO_HOME=/usr/local/cargo \
79
PATH=/usr/local/cargo/bin:$PATH \
@@ -18,11 +20,19 @@ RUN apt-get update && \
1820
if [ $PYTHON_VERSION = '3.6' ]; \
1921
then \
2022
apt-get install python3-pip -y --no-install-recommends && \
21-
ln -sf /usr/bin/pip3 /usr/bin/pip; \
23+
ln -sf /usr/bin/pip3 /usr/bin/pip && \
24+
pip install setuptools; \
2225
else \
2326
curl https://bootstrap.pypa.io/get-pip.py | python${PYTHON_VERSION}; \
2427
fi && \
25-
pip install --upgrade pip
28+
pip install --upgrade pip && \
29+
curl -fSL -o ghr.tar.gz "https://github.com/tcnksm/ghr/releases/download/v${GHR_VERSION}/ghr_v${GHR_VERSION}_linux_amd64.tar.gz" && \
30+
tar -xvzf ghr.tar.gz && \
31+
mv ghr_v${GHR_VERSION}_linux_amd64/ghr /usr/local/bin && \
32+
chown root:root /usr/local/bin/ghr && \
33+
rm -r \
34+
ghr.tar.gz \
35+
ghr_v${GHR_VERSION}_linux_amd64
2636

2737
RUN set -eux; \
2838
dpkgArch="$(dpkg --print-architecture)"; \

appveyor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ artifacts:
7474
- path: build\lib\py_sourcemap\*.pyd
7575
name: Binary
7676

77+
before_deploy:
78+
- "%PYTHON%\\python.exe upload-ali-oss.py"
79+
7780
deploy:
7881
provider: GitHub
7982
description: $(APPVEYOR_REPO_TAG_NAME)

requirement-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ yapf==0.23.0
22
twine==1.11.0
33
bumpversion==0.5.3
44
pytest==3.7.4
5+
oss2==2.5.0
6+
pycryptodome==3.6.6

upload-ali-oss.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import sys
3+
import ntpath
4+
import glob
5+
import configparser
6+
7+
import oss2
8+
9+
endpoint = 'http://{region}.aliyuncs.com'.format(region='oss-cn-shanghai')
10+
11+
bucket_name = 'lc-frontend'
12+
13+
if __name__ == '__main__':
14+
if len(sys.argv) >= 2:
15+
files = sys.argv[1:]
16+
else:
17+
files = glob.glob('build/lib/py_sourcemap/*.so')
18+
19+
config = configparser.ConfigParser()
20+
config.read('.bumpversion.cfg')
21+
package_version = config['bumpversion']['current_version']
22+
23+
access_key = os.environ.get('ALIYUN_ACCESS_KEY')
24+
access_token = os.environ.get('ALIYUN_ACCESS_TOKEN')
25+
26+
auth = oss2.Auth(access_key, access_token)
27+
bucket = oss2.Bucket(auth, endpoint, bucket_name)
28+
29+
for file_path in files:
30+
basename = ntpath.basename(file_path)
31+
fp = open(file_path, 'rb')
32+
target_key = 'packages/py_sourcemap/{version}/{name}'.format(
33+
version=package_version, name=basename)
34+
print('Uploading {}...'.format(target_key))
35+
bucket.put_object(target_key, fp.read())
36+
fp.close()
37+
print('Uploaded all.')

0 commit comments

Comments
 (0)