Skip to content
This repository was archived by the owner on May 27, 2024. It is now read-only.

Commit f0b847c

Browse files
committed
support release to qiniu
1 parent 34fdfd1 commit f0b847c

File tree

3 files changed

+90
-4
lines changed

3 files changed

+90
-4
lines changed

.travis.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
---
2+
os: linux
3+
dist: xenial # Python3.7 virtualenv is available only on Travis Xenial VMs.
24
language: go
3-
sudo: false
5+
sudo: true
46
go:
57
- "1.13"
68
env:
79
- GO111MODULE=on
8-
9-
install: true
10-
10+
before_install:
11+
- sudo apt-get update -q
12+
- sudo apt-get install -y python3 python3-dev python3-pip python3-setuptools
13+
- sudo pip3 install -r scripts/requirements.txt
14+
install:
15+
- true # just skip
1116
script:
1217
- go test -v
1318
after_success:
1419
- test -n "$TRAVIS_TAG" && curl -sL https://git.io/goreleaser | bash
20+
- test -n "$TRAVIS_TAG" && python3 -u scripts/upload2qiniu.py

scripts/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
qiniu~=7.2
2+
retry~=0.9.2

scripts/upload2qiniu.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# coding: utf-8
2+
3+
import argparse
4+
import glob
5+
import re
6+
import logging
7+
import os
8+
9+
import qiniu.config
10+
from qiniu import Auth, etag, put_file
11+
from qiniu import Zone, set_default
12+
from retry import retry
13+
14+
class Qiniu:
15+
def __init__(self, access_key, secret_key, bucket_name: str):
16+
self._access_key = access_key
17+
self._secret_key = secret_key
18+
self._auth = Auth(access_key, secret_key)
19+
self._bucket = bucket_name
20+
21+
@retry(tries=5, delay=0.5, jitter=0.1, logger=logging)
22+
def upload_file(self, key, localfile):
23+
token = self._auth.upload_token(self._bucket, key)
24+
ret, info = put_file(token, key, localfile)
25+
if ret: # ret possibly is None
26+
assert ret['key'] == key
27+
assert ret['hash'] == etag(localfile)
28+
return info
29+
30+
31+
access_key = 'caBese-UQYXwQeigGqtdgwybP2Qh2AlDPdcEd42C'
32+
secret_key = 'SIG4DGyO45aseWSvOc9Be-ZkGrxoc-IpWlM5xts8'
33+
34+
zone = Zone(up_host='https://up.qiniup.com',
35+
up_host_backup='https://upload.qiniup.com',
36+
io_host='http://iovip.qbox.me',
37+
scheme='https')
38+
set_default(default_zone=zone)
39+
40+
41+
def main():
42+
parser = argparse.ArgumentParser()
43+
parser.add_argument("-A",
44+
'--access-key',
45+
help='access key, env-var QINIU_ACCESS_KEY',
46+
default=os.environ.get("QINIU_ACCESS_KEY", access_key))
47+
parser.add_argument("-S",
48+
"--secret-key",
49+
help='secret key, env-var QINIU_SECRET_KEY',
50+
default=os.environ.get("QINIU_SECRET_KEY", secret_key))
51+
parser.add_argument("-B",
52+
"--bucket",
53+
help='bucket name',
54+
default=os.environ.get("QINIU_BUCKET", "atxupload"))
55+
args = parser.parse_args()
56+
57+
assert args.access_key
58+
assert args.secret_key
59+
assert args.bucket
60+
61+
qn = Qiniu(args.access_key, args.secret_key, args.bucket)
62+
checksum_path = glob.glob("*/atx-agent_*_checksums.txt")[0]
63+
distdir = os.path.dirname(checksum_path)
64+
65+
version = re.search(r"([\d.]+)", checksum_path).group(0)
66+
print(checksum_path, version)
67+
key_prefix = "openatx/atx-agent/releases/download/" + version + "/"
68+
qn.upload_file(key_prefix + os.path.basename(checksum_path), checksum_path)
69+
with open(checksum_path, 'r', encoding='utf-8') as f:
70+
for line in f:
71+
_, filename = line.split()
72+
key = key_prefix + filename
73+
print("-", filename, "->", key)
74+
qn.upload_file(key, os.path.join(distdir, filename))
75+
76+
77+
if __name__ == "__main__":
78+
main()

0 commit comments

Comments
 (0)