Skip to content

Commit

Permalink
support forc-wallet (#195)
Browse files Browse the repository at this point in the history
* support forc-wallet

* update CI

* support forc-wallet

* fix forc-wallet repository_url -> repository_name

* deprecate usage of consts

* re-add FORC const

* deprecate consts for target_triple.rs

* missing 'v' from tag

* remove usage of const static components in tests

* fix order of discovery for DownloadCfg::new

* handle creating fuelup component
  • Loading branch information
eightfilms authored Sep 30, 2022
1 parent 37477c4 commit 9b87111
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
98 changes: 98 additions & 0 deletions .github/workflows/scripts/append_package_to_channel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash
set -e

add_url_and_hash() {
_url="https://github.com/FuelLabs/$1/releases/download/$2/$3"
_err=$(curl -sSf "${_url}" -L -o "${3}" 2>&1)
if echo "$_err" | grep -q 404; then
printf "Could not download from %s - the release binary might not be ready yet. You can check if a binary is available here: https://github.com/FuelLabs/%s/releases/%s\n" "${_url}" "${1}" "${2}"
exit 1
fi
# shasum generates extra output so we take the first 64 bytes.
_hash=$(shasum -a 256 "$3" | head -c 64)
RETVAL="url = \"${_url}\"\nhash = \"${_hash}\"\n\n"
}

create_new_pkg() {
_header=$(printf "[pkg.%s]\nversion = \"%s\"\n" "${1}" "${2}")
RETVAL="$_header"
}

create_pkg_in_channel() {
CHANNEL_TOML_NAME=$3
version=$2
date="$(date +'%Y%m%d')"
tag="v${2}"
case "${1}" in
"forc")
_targets=("darwin_amd64" "darwin_arm64" "linux_amd64" "linux_arm64")
_repo="sway"
_tarball_prefix="forc-binaries"
;;
"forc-client")
_targets=("aarch64-apple-darwin" "aarch64-unknown-linux-gnu" "x86_64-apple-darwin" "x86_64-unknown-linux-gnu")
_repo="forc-client"
_tarball_prefix="forc-client"

if [ "${2}" != "nightly" ]; then
_tarball_prefix+="-${version}"
fi
;;
"forc-wallet")
_targets=("aarch64-apple-darwin" "aarch64-unknown-linux-gnu" "x86_64-apple-darwin" "x86_64-unknown-linux-gnu")
_repo="forc-wallet"
_tarball_prefix="forc-wallet"

if [ "${2}" != "nightly" ]; then
_tarball_prefix+="-${version}"
fi
;;
"fuel-core")
_targets=("aarch64-apple-darwin" "aarch64-unknown-linux-gnu" "x86_64-apple-darwin" "x86_64-unknown-linux-gnu")
_repo="fuel-core"
_tarball_prefix="fuel-core"

if [ "${2}" != "nightly" ]; then
_tarball_prefix+="-${version}"
fi

;;
esac

if [ "${2}" = "nightly" ]; then
_repo="sway-nightly-binaries"
version="$(curl -s https://api.github.com/repos/FuelLabs/${_repo}/releases | grep "tag_name" | grep "nightly.${date}" | grep "${_tarball_prefix}" | head -n 1 | cut -d "-" -f3- | cut -d "\"" -f1)"
_tarball_prefix+="-${version}"
# Replace '+' within string with '%2B' to be URL friendly
tag=$(echo "${_tarball_prefix}" | sed -r "s/\+/\%2B/g")
fi

# We need to recreate channel-fuel-latest.toml, generating new URLs and sha256 hashes for the download links.
printf "%s: Generating new package\n" "${1}"
create_new_pkg "$1" "${version}"
_header="$RETVAL"
_content=""
for target in "${_targets[@]}"; do
_content+="[pkg.${1}.target.${target}]\n"
# TAG is either: v0.22.1 or forc-binaries-nightly-2022-08-25
add_url_and_hash $_repo "${tag}" "${_tarball_prefix}-${target}.tar.gz"
_content+="$RETVAL"
done

# Only write to file if there's no problem downloading and hashing all the above releases.
_package=$(printf "%s\n%s" "${_header}" "${_content}")
echo -ne "$_package" >>"$CHANNEL_TOML_NAME"
}

main() {
COMPONENT=$1
VERSION=$2
CHANNEL_TOML_NAME=$3
trap 'rm *.tar.gz' ERR EXIT

create_pkg_in_channel "${COMPONENT}" "${VERSION}" "${CHANNEL_TOML_NAME}"

exit 0
}

main "$@" || exit 1
9 changes: 9 additions & 0 deletions components.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ executables = ["fuel-core"]
repository_name = "fuel-core"
targets = [ "aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "x86_64-apple-darwin" ]
publish = true

[component.forc-wallet]
name = "forc-wallet"
tarball_prefix = "forc-wallet"
is_plugin = true
executables = ["forc-wallet"]
repository_name = "forc-wallet"
targets = [ "aarch64-unknown-linux-gnu", "x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "x86_64-apple-darwin" ]
publish = true
1 change: 1 addition & 0 deletions tests/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ my_toolchain (default)
- forc-explore - not found
- forc-fmt - not found
- forc-lsp - not found
- forc-wallet - not found
fuel-core - not found
"#;
assert!(stdout.contains(expected_stdout));
Expand Down

0 comments on commit 9b87111

Please sign in to comment.