|
| 1 | +#!/bin/bash -ex |
| 2 | +# |
| 3 | +# DO NOT RUN DIRECTLY. |
| 4 | +# Script must be sourced by deploy.sh or deploy-fips.sh |
| 5 | +# after setting or unsetting `SNOWPARK_FIPS` environment variable. |
| 6 | +# |
| 7 | + |
| 8 | +if [ -z "$GPG_KEY_ID" ]; then |
| 9 | + export GPG_KEY_ID="Snowflake Computing" |
| 10 | + echo "[WARN] GPG key ID not specified, using default: $GPG_KEY_ID." |
| 11 | +fi |
| 12 | + |
| 13 | +if [ -z "$GPG_KEY_PASSPHRASE" ]; then |
| 14 | + echo "[ERROR] GPG passphrase is not specified for $GPG_KEY_ID!" |
| 15 | + exit 1 |
| 16 | +fi |
| 17 | + |
| 18 | +if [ -z "$GPG_PRIVATE_KEY" ]; then |
| 19 | + echo "[ERROR] GPG private key file is not specified!" |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +if [ -z "$sonatype_user" ]; then |
| 24 | + echo "[ERROR] Jenkins sonatype user is not specified!" |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | + |
| 28 | +if [ -z "$sonatype_password" ]; then |
| 29 | + echo "[ERROR] Jenkins sonatype pwd is not specified!" |
| 30 | + exit 1 |
| 31 | +fi |
| 32 | + |
| 33 | +if [ -z "$PUBLISH" ]; then |
| 34 | + echo "[ERROR] 'PUBLISH' is not specified!" |
| 35 | + exit 1 |
| 36 | +fi |
| 37 | + |
| 38 | +if [ -z "$github_version_tag" ]; then |
| 39 | + echo "[ERROR] 'github_version_tag' is not specified!" |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +mkdir -p ~/.ivy2 |
| 44 | + |
| 45 | +STR=$'host=central.sonatype.com |
| 46 | +user='$sonatype_user' |
| 47 | +password='$sonatype_password'' |
| 48 | + |
| 49 | +echo "$STR" > ~/.ivy2/.credentials |
| 50 | + |
| 51 | +# import private key first |
| 52 | +echo "[INFO] Importing PGP key." |
| 53 | +if [ ! -z "$GPG_PRIVATE_KEY" ] && [ -f "$GPG_PRIVATE_KEY" ]; then |
| 54 | + # First check if already imported private key |
| 55 | + if ! gpg --list-secret-key | grep "$GPG_KEY_ID"; then |
| 56 | + gpg --allow-secret-key-import --import "$GPG_PRIVATE_KEY" |
| 57 | + fi |
| 58 | +fi |
| 59 | + |
| 60 | +which sbt |
| 61 | +if [ $? -ne 0 ] |
| 62 | +then |
| 63 | + pushd .. |
| 64 | + echo "[INFO] sbt is not installed, downloading latest sbt for test and build." |
| 65 | + curl -L -o sbt-1.11.4.zip https://github.com/sbt/sbt/releases/download/v1.11.4/sbt-1.11.4.zip |
| 66 | + unzip sbt-1.11.4.zip |
| 67 | + PATH=$PWD/sbt/bin:$PATH |
| 68 | + popd |
| 69 | +else |
| 70 | + echo "[INFO] Using system installed sbt." |
| 71 | +fi |
| 72 | +which sbt |
| 73 | +sbt version |
| 74 | + |
| 75 | +echo "[INFO] Checking out snowpark-java-scala @ tag: $github_version_tag." |
| 76 | +git checkout $github_version_tag |
| 77 | + |
| 78 | +if [ "$PUBLISH" = true ]; then |
| 79 | + if [ "$SNOWPARK_FIPS" = true ]; then |
| 80 | + echo "[INFO] Packaging snowpark-fips @ tag: $github_version_tag." |
| 81 | + else |
| 82 | + echo "[INFO] Packaging snowpark @ tag: $github_version_tag." |
| 83 | + fi |
| 84 | + sbt +publishSigned |
| 85 | + echo "[INFO] Staged packaged artifacts locally with PGP signing." |
| 86 | + sbt sonaUpload |
| 87 | + echo "[SUCCESS] Uploaded artifacts to central portal." |
| 88 | + echo "[ACTION-REQUIRED] Please log in to Central Portal to publish artifacts: https://central.sonatype.com/" |
| 89 | + # TODO: alternatively automate publishing fully |
| 90 | +# sbt sonaRelease |
| 91 | +# echo "[SUCCESS] Released Snowpark Java-Scala v$github_version_tag to Maven." |
| 92 | +else |
| 93 | + #release to s3 |
| 94 | + echo "[INFO] Staging signed artifacts to local ivy2 repository." |
| 95 | + rm -rf ~/.ivy2/local/ |
| 96 | + sbt +publishLocalSigned |
| 97 | + |
| 98 | + # SBT will build FIPS version of Snowpark automatically if the environment variable exists. |
| 99 | + if [ "$SNOWPARK_FIPS" = true ]; then |
| 100 | + S3_JENKINS_URL="s3://sfc-eng-jenkins/repository/snowparkclient-fips" |
| 101 | + S3_DATA_URL="s3://sfc-eng-data/client/snowparkclient-fips/releases" |
| 102 | + echo "[INFO] Uploading snowpark-fips artifacts to:" |
| 103 | + else |
| 104 | + S3_JENKINS_URL="s3://sfc-eng-jenkins/repository/snowparkclient" |
| 105 | + S3_DATA_URL="s3://sfc-eng-data/client/snowparkclient/releases" |
| 106 | + echo "[INFO] Uploading snowpark artifacts to:" |
| 107 | + fi |
| 108 | + echo "[INFO] - $S3_JENKINS_URL/$github_version_tag/" |
| 109 | + echo "[INFO] - $S3_DATA_URL/$github_version_tag/" |
| 110 | + |
| 111 | + # Rename all produced artifacts to include version number (sbt doesn't by default when publishing to local ivy2 repository). |
| 112 | + find ~/.ivy2/local -type f -name '*snowpark*' | while read file; do newfile=$(echo "$file" | sed "s/\(2\.1[23]\)\([-\.]\)/\1-${github_version_tag#v}\2/"); mv "$file" "$newfile"; done |
| 113 | + |
| 114 | + # Generate sha256 checksums for all artifacts produced except .md5, .sha1, and existing .sha256 checksum files. |
| 115 | + find ~/.ivy2/local -type f -name '*snowpark*' ! -name '*.md5' ! -name '*.sha1' ! -name '*.sha256' -exec sh -c 'for f; do sha256sum "$f" | awk '"'"'{printf "%s", $1}'"'"' > "$f.sha256"; done' _ {} + |
| 116 | + |
| 117 | + # Copy all files, flattening the nested structure of the ivy2 repository into the expected structure on s3. |
| 118 | + find ~/.ivy2/local -type f -name '*snowpark*' -exec aws s3 cp \{\} $S3_JENKINS_URL/$github_version_tag/ \; |
| 119 | + find ~/.ivy2/local -type f -name '*snowpark*' -exec aws s3 cp \{\} $S3_DATA_URL/$github_version_tag/ \; |
| 120 | + |
| 121 | + echo "[SUCCESS] Published Snowpark Java-Scala v$github_version_tag artifacts to S3." |
| 122 | +fi |
0 commit comments