|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Usage: |
| 4 | +# |
| 5 | +# $ ELIXIR_PEM=/path/to/elixir.pem \ |
| 6 | +# HEX_FASTLY_KEY=... \ |
| 7 | +# HEX_FASTLY_BUILDS_SERVICE_ID=... \ |
| 8 | +# release_hex.sh HEX_VERSION |
| 9 | +# |
| 10 | +# Unless ELIXIR_PEM is set, nothing is uploaded. After running, can be locally tested: |
| 11 | +# |
| 12 | +# $ (cd tmp && erl -S httpd) |
| 13 | +# $ HEX_BUILDS_URL=http://localhost:8000 mix local.hex --force |
| 14 | + |
| 15 | +set -e -u -o pipefail |
| 16 | + |
| 17 | +function main { |
| 18 | + hex_version=$1 |
| 19 | + installs_dir="$PWD/tmp/installs" |
| 20 | + hex_csv="${installs_dir}/hex.csv" |
| 21 | + |
| 22 | + rm -rf "${installs_dir}" |
| 23 | + mkdir "${installs_dir}" |
| 24 | + |
| 25 | + s3down hex.csv "${hex_csv}" |
| 26 | + touch "${hex_csv}" |
| 27 | + sed -i.bak "/^${hex_version},/d" "${hex_csv}" |
| 28 | + |
| 29 | + # UPDATE THIS FOR EVERY RELEASE |
| 30 | + build ${hex_version} 25.3.2.20 1.18.3 1.18.0 noble-20250404 |
| 31 | + build ${hex_version} 26.2.5.11 1.18.3 1.18.0 noble-20250404 |
| 32 | + build ${hex_version} 27.3.3 1.18.3 1.18.0 noble-20250404 |
| 33 | + |
| 34 | + build ${hex_version} 25.3.2.20 1.17.3 1.17.0 noble-20250404 |
| 35 | + build ${hex_version} 26.2.5.11 1.17.3 1.17.0 noble-20250404 |
| 36 | + build ${hex_version} 27.3.3 1.17.3 1.17.0 noble-20250404 |
| 37 | + |
| 38 | + rm -rf _build |
| 39 | + rm "${hex_csv}.bak" |
| 40 | + |
| 41 | + if [ -n "${ELIXIR_PEM}" ]; then |
| 42 | + openssl dgst -sha512 -sign "${ELIXIR_PEM}" "${hex_csv}" | openssl base64 > "${hex_csv}.signed" |
| 43 | + |
| 44 | + cd $installs_dir |
| 45 | + for path in $(find . -type f | sort); do |
| 46 | + path="${path#./}" |
| 47 | + echo "uploading ${path}..." |
| 48 | + s3up "${path}" "${path}" |
| 49 | + done |
| 50 | + |
| 51 | + purge_key "${HEX_FASTLY_BUILDS_SERVICE_ID}" "installs" |
| 52 | + else |
| 53 | + echo "ELIXIR_PEM is empty, skipping" |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | +} |
| 57 | + |
| 58 | +# $1 = hex version |
| 59 | +# $2 = erlang version |
| 60 | +# $3 = elixir version |
| 61 | +# $4 = saved elixir version |
| 62 | +# $5 = ubuntu version |
| 63 | +function build { |
| 64 | + hex_version=$1 |
| 65 | + otp_version=$2 |
| 66 | + otp_release=${otp_version%%.*} |
| 67 | + elixir_version=$3 |
| 68 | + saved_elixir_version=$4 |
| 69 | + ubuntu_version=$5 |
| 70 | + |
| 71 | + echo "Building ${elixir_version} ${otp_version} ${ubuntu_version}" |
| 72 | + rm -rf _build src/mix_safe_erl_term.erl |
| 73 | + hex_ez=hex-${hex_version}-otp-${otp_release}.ez |
| 74 | + |
| 75 | + mkdir -p "$installs_dir/${saved_elixir_version}" |
| 76 | + docker run -v $(pwd):/hex hexpm/elixir:${elixir_version}-erlang-${otp_version}-ubuntu-${ubuntu_version} sh -c " \ |
| 77 | + cd /hex && \ |
| 78 | + MIX_ENV=prod mix archive.build -o ${hex_ez}" |
| 79 | + |
| 80 | + mv "${hex_ez}" "${installs_dir}/${saved_elixir_version}/${hex_ez}" |
| 81 | + sha=$(shasum -a 512 "${installs_dir}/${saved_elixir_version}/${hex_ez}") |
| 82 | + sha=($sha) |
| 83 | + echo "${hex_version},${sha},${saved_elixir_version},${otp_release}" >> "${hex_csv}" |
| 84 | +} |
| 85 | + |
| 86 | +# $1 = source |
| 87 | +# $2 = target |
| 88 | +function s3up { |
| 89 | + aws s3 cp "${1}" "s3://s3.hex.pm/installs/${2}" --acl public-read --cache-control "public, max-age=604800" --metadata "surrogate-key=installs" |
| 90 | +} |
| 91 | + |
| 92 | +# $1 = source |
| 93 | +# $2 = target |
| 94 | +function s3down { |
| 95 | + aws s3 cp "s3://s3.hex.pm/installs/${1}" "${2}" |
| 96 | +} |
| 97 | + |
| 98 | +# $1 = service |
| 99 | +# $2 = key |
| 100 | +function purge_key() { |
| 101 | + curl \ |
| 102 | + --fail \ |
| 103 | + -X POST \ |
| 104 | + -H "Fastly-Key: ${HEX_FASTLY_KEY}" \ |
| 105 | + -H "Accept: application/json" \ |
| 106 | + -H "Content-Length: 0" \ |
| 107 | + "https://api.fastly.com/service/$1/purge/$2" |
| 108 | +} |
| 109 | + |
| 110 | +main $* |
0 commit comments