Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: new dir arch #13

Merged
merged 1 commit into from
Nov 10, 2020
Merged

fix: new dir arch #13

merged 1 commit into from
Nov 10, 2020

Conversation

jericdeleon
Copy link
Contributor

This PR fixes a directory change in esy's npm release that first occured in 0.6.7.

Since 0.6.7, asdf install esy 0.6.7 failed with the ff:

Downloading esy, version 0.6.7
Extracting esy
Installing esy
cp: cannot stat '/tmp/asdf_esy_Yl0dPG/esy-0.6.7/package/platform-linux/_build/default/bin/esyInstallRelease.js': No such file or directory

This was the directory structure in (and prior to) 0.6.6:
esy02

This is how 0.6.7 (and assuming future versions) looks:
esy01

I just used a naive semver comparison function. If you'd prefer a different approach (I liberally used ternaries), please suggest and I will happily adjust. No issues if you'd like to edit the change yourselves as well.

If I missed something, please let me know.

Here's a unit test to play around with:

#!/usr/bin/env bash
set -e

new_dir_arch() {
  local version="$1"
	local major_cutoff=0
	local minor_cutoff=6
	local patch_cutoff=6

	if [[ "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
		local major="${BASH_REMATCH[1]}"
		local minor="${BASH_REMATCH[2]}"
		local patch="${BASH_REMATCH[3]}"

		local major_gt="$([[ $major -gt $major_cutoff ]] && echo 0 || echo 1)"
		local minor_gt="$([[ $minor -gt $minor_cutoff ]] && echo 0 || echo 1)"
		local patch_gt="$([[ $patch -gt $patch_cutoff ]] && echo 0 || echo 1)"

		local major_eq="$([[ $major -eq $major_cutoff ]] && echo 0 || echo 1)"
		local minor_eq="$([[ $minor -eq $minor_cutoff ]] && echo 0 || echo 1)"
		local patch_eq="$([[ $patch -eq $patch_cutoff ]] && echo 0 || echo 1)"

		local major_match="$([[ $major_gt -eq 0 ]] && echo 0 || echo 1)"
		local minor_match="$(([[ $major_eq -eq 0 ]] && [[ $minor_gt -eq 0 ]]) && echo 0 || echo 1)"
		local patch_match="$(([[ $major_eq -eq 0 ]] && [[ $minor_eq -eq 0 ]] && [[ $patch_gt -eq 0 ]]) && echo 0 || echo 1)"

		local new_dir_arch="$(([[ $major_match -eq 0 ]] || [[ $minor_match -eq 0 ]] || [[ $patch_match -eq 0 ]]) && echo 0 || echo 1)"

    echo "$new_dir_arch"
  else
    fail "Cannot parse version: $version"
	fi
}

platform() {
  local version="$1"
  local new_dir_arch=$(new_dir_arch "$version")

  if [[ "$OSTYPE" == "linux"* ]]; then
    if [[ $new_dir_arch -eq 0 ]]; then echo "Linux"; else echo "platform-linux"; fi
  elif [[ "$OSTYPE" == "darwin"* ]]; then
    if [[ $new_dir_arch -eq 0 ]]; then echo "macOS"; else echo "platform-darwin"; fi
  else
    fail "Unknown platform: $OSTYPE"
  fi
}

esy_install() {
  local version="$1"
  local platform=$(platform "$version")

  echo "$version platform: $platform"
}

esy_install "0.5.5"
esy_install "0.5.10"
esy_install "0.6.5"
esy_install "0.6.6"
esy_install "0.6.7"
esy_install "0.6.8"
esy_install "0.7.4"
esy_install "1.0.0"
esy_install "1.1.1"
esy_install "1.6.7"
esy_install "1.6.6"

@ivanoats
Copy link

ivanoats commented Nov 9, 2020

I can confirm the error and thus the need for the fix. Also that this fix works. Let's get this merged :-)

@smorimoto
Copy link
Member

Oh, sorry, I forgot to review this.

@smorimoto
Copy link
Member

​The code looks a bit redundant to me, but looks good.

@smorimoto smorimoto merged commit df1dd25 into asdf-community:master Nov 10, 2020
@smorimoto
Copy link
Member

​Thanks for this PR @jericdeleon! ​and thanks for pinging me @ivanoats!

@jericdeleon
Copy link
Contributor Author

Thanks for taking the time to review @smorimoto!

@jericdeleon jericdeleon deleted the fix/new-dir-arch branch November 10, 2020 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants