diff --git a/build-support/download-release-artifacts.py b/build-support/download-release-artifacts.py new file mode 100755 index 00000000..774ffdc8 --- /dev/null +++ b/build-support/download-release-artifacts.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import sys, json, urllib.request, os, shutil, zipfile, tempfile +from pathlib import Path + +if len(sys.argv) != 3: + print("Usage: ") + print(" %s $WORKFLOW_RUN_ID $DEST_PATH" % sys.argv[0]) + sys.exit(-1) + +if 'GITHUB_TOKEN' not in os.environ: + print('You should have a GITHUB_TOKEN environment variable') + sys.exit(-1) + +GITHUB_TOKEN = os.environ['GITHUB_TOKEN'] + +ACCEPT_HEADER = 'application/vnd.github+json' +LIST_URL = 'https://api.github.com/repos/apache/pulsar-client-cpp/actions/runs/%d/artifacts' + +workflow_run_id = int(sys.argv[1]) +dest_path = sys.argv[2] + +workflow_run_url = LIST_URL % workflow_run_id +request = urllib.request.Request(workflow_run_url, + headers={'Accept': ACCEPT_HEADER, 'Authorization': 'Bearer ' + GITHUB_TOKEN}) +with urllib.request.urlopen(request) as response: + data = json.loads(response.read().decode("utf-8")) + for artifact in data['artifacts']: + name = artifact['name'] + url = artifact['archive_download_url'] + + print('Downloading %s from %s' % (name, url)) + artifact_request = urllib.request.Request(url, + headers={'Authorization': 'Bearer ' + GITHUB_TOKEN}) + with urllib.request.urlopen(artifact_request) as response: + tmp_zip = tempfile.NamedTemporaryFile(delete=False) + try: + # + shutil.copyfileobj(response, tmp_zip) + tmp_zip.close() + + dest_dir = os.path.join(dest_path, name) + Path(dest_dir).mkdir(parents=True, exist_ok=True) + with zipfile.ZipFile(tmp_zip.name, 'r') as z: + z.extractall(dest_dir) + finally: + os.unlink(tmp_zip.name) + + + diff --git a/build-support/generate-source-archive.sh b/build-support/generate-source-archive.sh index d88f0818..bacddfb9 100755 --- a/build-support/generate-source-archive.sh +++ b/build-support/generate-source-archive.sh @@ -17,11 +17,12 @@ # specific language governing permissions and limitations # under the License. # - ROOT_DIR=$(git rev-parse --show-toplevel) VERSION=$(cat ${ROOT_DIR}/version.txt) NAME=apache-pulsar-client-cpp-$VERSION -git archive --format=tar.gz --prefix ${NAME}/ -o ${NAME}.tar.gz HEAD +OUT_DIR=${1:-.} + +git archive --format=tar.gz --prefix ${NAME}/ -o ${OUT_DIR}/${NAME}.tar.gz HEAD diff --git a/build-support/sign-files.sh b/build-support/sign-files.sh new file mode 100755 index 00000000..e827d0a9 --- /dev/null +++ b/build-support/sign-files.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +set -e + +FILES=$* + +for FILE in $FILES +do + echo "Signing $FILE" + gpg --armor --output $FILE.asc --detach-sig $FILE + + # SHA-512 signature + shasum -a 512 $FILE > $FILE.sha512 +done diff --git a/build-support/stage-release.sh b/build-support/stage-release.sh new file mode 100755 index 00000000..d435ca25 --- /dev/null +++ b/build-support/stage-release.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +set -e -x + +if [ $# -neq 2 ]; then + echo "Usage: $0 \$DEST_PATH \$WORKFLOW_ID" + exit 1 +fi + +DEST_PATH=$1 +WORKFLOW_ID=$1 + +pushd $(dirname "$0") +PULSAR_CPP_PATH=$(git rev-parse --show-toplevel) +popd + +mkdir -p $DEST_PATH + +cd PULSAR_CPP_PATH +VERSION=$(cat version.txt | xargs) + +build-support/generate-source-archive.sh $DEST_PATH +build-support/download-release-artifacts.py $WORKFLOW_ID $DEST_PATH + +# Sign all files +cd $DEST_PATH +find . -type f | xargs $PULSAR_CPP_PATH/build-support/sign-files.sh