You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2022/10/07 17:27:22 UTC
[pulsar-client-cpp] branch main updated: Added script to download release artifacts (#18)
This is an automated email from the ASF dual-hosted git repository.
mmerli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new dc2d71e Added script to download release artifacts (#18)
dc2d71e is described below
commit dc2d71e7da8316491ce9cff77eb5b24e0fa71f06
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Fri Oct 7 10:27:18 2022 -0700
Added script to download release artifacts (#18)
* Added script to download release artifacts
* Added script to stage the release artifacts
---
build-support/download-release-artifacts.py | 68 ++++++++++++++++++++++
build-support/generate-source-archive.sh | 5 +-
.../{generate-source-archive.sh => sign-files.sh} | 13 +++--
...generate-source-archive.sh => stage-release.sh} | 26 +++++++--
4 files changed, 102 insertions(+), 10 deletions(-)
diff --git a/build-support/download-release-artifacts.py b/build-support/download-release-artifacts.py
new file mode 100755
index 0000000..774ffdc
--- /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 d88f081..bacddfb 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/generate-source-archive.sh b/build-support/sign-files.sh
similarity index 81%
copy from build-support/generate-source-archive.sh
copy to build-support/sign-files.sh
index d88f081..e827d0a 100755
--- a/build-support/generate-source-archive.sh
+++ b/build-support/sign-files.sh
@@ -18,10 +18,15 @@
# under the License.
#
-ROOT_DIR=$(git rev-parse --show-toplevel)
+set -e
-VERSION=$(cat ${ROOT_DIR}/version.txt)
+FILES=$*
-NAME=apache-pulsar-client-cpp-$VERSION
+for FILE in $FILES
+do
+ echo "Signing $FILE"
+ gpg --armor --output $FILE.asc --detach-sig $FILE
-git archive --format=tar.gz --prefix ${NAME}/ -o ${NAME}.tar.gz HEAD
+ # SHA-512 signature
+ shasum -a 512 $FILE > $FILE.sha512
+done
diff --git a/build-support/generate-source-archive.sh b/build-support/stage-release.sh
similarity index 62%
copy from build-support/generate-source-archive.sh
copy to build-support/stage-release.sh
index d88f081..d435ca2 100755
--- a/build-support/generate-source-archive.sh
+++ b/build-support/stage-release.sh
@@ -18,10 +18,28 @@
# under the License.
#
-ROOT_DIR=$(git rev-parse --show-toplevel)
+set -e -x
-VERSION=$(cat ${ROOT_DIR}/version.txt)
+if [ $# -neq 2 ]; then
+ echo "Usage: $0 \$DEST_PATH \$WORKFLOW_ID"
+ exit 1
+fi
-NAME=apache-pulsar-client-cpp-$VERSION
+DEST_PATH=$1
+WORKFLOW_ID=$1
-git archive --format=tar.gz --prefix ${NAME}/ -o ${NAME}.tar.gz HEAD
+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