Skip to content

Commit dc2d71e

Browse files
authored
Added script to download release artifacts (#18)
* Added script to download release artifacts * Added script to stage the release artifacts
1 parent bdffcef commit dc2d71e

4 files changed

Lines changed: 148 additions & 2 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
21+
import sys, json, urllib.request, os, shutil, zipfile, tempfile
22+
from pathlib import Path
23+
24+
if len(sys.argv) != 3:
25+
print("Usage: ")
26+
print(" %s $WORKFLOW_RUN_ID $DEST_PATH" % sys.argv[0])
27+
sys.exit(-1)
28+
29+
if 'GITHUB_TOKEN' not in os.environ:
30+
print('You should have a GITHUB_TOKEN environment variable')
31+
sys.exit(-1)
32+
33+
GITHUB_TOKEN = os.environ['GITHUB_TOKEN']
34+
35+
ACCEPT_HEADER = 'application/vnd.github+json'
36+
LIST_URL = 'https://api.github.com/repos/apache/pulsar-client-cpp/actions/runs/%d/artifacts'
37+
38+
workflow_run_id = int(sys.argv[1])
39+
dest_path = sys.argv[2]
40+
41+
workflow_run_url = LIST_URL % workflow_run_id
42+
request = urllib.request.Request(workflow_run_url,
43+
headers={'Accept': ACCEPT_HEADER, 'Authorization': 'Bearer ' + GITHUB_TOKEN})
44+
with urllib.request.urlopen(request) as response:
45+
data = json.loads(response.read().decode("utf-8"))
46+
for artifact in data['artifacts']:
47+
name = artifact['name']
48+
url = artifact['archive_download_url']
49+
50+
print('Downloading %s from %s' % (name, url))
51+
artifact_request = urllib.request.Request(url,
52+
headers={'Authorization': 'Bearer ' + GITHUB_TOKEN})
53+
with urllib.request.urlopen(artifact_request) as response:
54+
tmp_zip = tempfile.NamedTemporaryFile(delete=False)
55+
try:
56+
#
57+
shutil.copyfileobj(response, tmp_zip)
58+
tmp_zip.close()
59+
60+
dest_dir = os.path.join(dest_path, name)
61+
Path(dest_dir).mkdir(parents=True, exist_ok=True)
62+
with zipfile.ZipFile(tmp_zip.name, 'r') as z:
63+
z.extractall(dest_dir)
64+
finally:
65+
os.unlink(tmp_zip.name)
66+
67+
68+

build-support/generate-source-archive.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919
#
20-
2120
ROOT_DIR=$(git rev-parse --show-toplevel)
2221

2322
VERSION=$(cat ${ROOT_DIR}/version.txt)
2423

2524
NAME=apache-pulsar-client-cpp-$VERSION
2625

27-
git archive --format=tar.gz --prefix ${NAME}/ -o ${NAME}.tar.gz HEAD
26+
OUT_DIR=${1:-.}
27+
28+
git archive --format=tar.gz --prefix ${NAME}/ -o ${OUT_DIR}/${NAME}.tar.gz HEAD

build-support/sign-files.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
21+
set -e
22+
23+
FILES=$*
24+
25+
for FILE in $FILES
26+
do
27+
echo "Signing $FILE"
28+
gpg --armor --output $FILE.asc --detach-sig $FILE
29+
30+
# SHA-512 signature
31+
shasum -a 512 $FILE > $FILE.sha512
32+
done

build-support/stage-release.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
21+
set -e -x
22+
23+
if [ $# -neq 2 ]; then
24+
echo "Usage: $0 \$DEST_PATH \$WORKFLOW_ID"
25+
exit 1
26+
fi
27+
28+
DEST_PATH=$1
29+
WORKFLOW_ID=$1
30+
31+
pushd $(dirname "$0")
32+
PULSAR_CPP_PATH=$(git rev-parse --show-toplevel)
33+
popd
34+
35+
mkdir -p $DEST_PATH
36+
37+
cd PULSAR_CPP_PATH
38+
VERSION=$(cat version.txt | xargs)
39+
40+
build-support/generate-source-archive.sh $DEST_PATH
41+
build-support/download-release-artifacts.py $WORKFLOW_ID $DEST_PATH
42+
43+
# Sign all files
44+
cd $DEST_PATH
45+
find . -type f | xargs $PULSAR_CPP_PATH/build-support/sign-files.sh

0 commit comments

Comments
 (0)