Skip to content

Commit

Permalink
Support building a particular commit of Nim rather than devel
Browse files Browse the repository at this point in the history
  • Loading branch information
iffy committed Nov 3, 2020
1 parent 9e4f831 commit 72877d2
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 3 deletions.
159 changes: 159 additions & 0 deletions .github/setup_from_release_url.sh
@@ -0,0 +1,159 @@
#!/usr/bin/env bash
#
# Simple tool to setup a Nim environment
# Copyright (C) 2020 Leorize
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

#----------------------------------------------------------
# This has been modified from github.com/alaviss/setup-nim
# to build from a particular commit instead of the latest
# devel branch. Once alaviss/setup-nim supports building a
# particular commit, this can be removed in favor of using
# that.
#----------------------------------------------------------
set -eu
set -o pipefail

_releases_url=https://github.com/nim-lang/nightlies/releases
_download_url=$_releases_url/download

print-help() {
cat <<EOF
Usage: $0 [option] archive-prefix release-url
Downloads and install the latest Nim nightly from a release URL.
The compiler can then be found in the 'bin' folder relative to the output
directory.
This script is tailored for CI use, as such it's very barebones and make
assumptions about the system such as having a working C compiler.
Options:
-o dir Set the output directory to 'dir'. The compiler will be
extracted to this directory. Defaults to \$PWD/nim.
-h Print this help message.
EOF
}

get-archive-name() {
local ext=.tar.xz
local os; os=$(uname)
os=$(tr '[:upper:]' '[:lower:]' <<< "$os")
case "$os" in
'darwin')
os=macosx
;;
'windows_nt'|mingw*)
os=windows
ext=.zip
;;
esac

local arch; arch=$(uname -m)
case "$arch" in
aarch64)
arch=arm64
;;
armv7l)
arch=arm
;;
i*86)
arch=x32
;;
x86_64)
arch=x64
;;
esac

echo "${os}_$arch$ext"
}

has-release() {
local url=$1
curl -f -I "$_releases_url/$url" >/dev/null 2>&1
}

msg() {
echo $'\e[1m\e[36m--\e[0m' "$@"
}

ok() {
echo $'\e[1m\e[32m--\e[0m' "$@"
}

err() {
echo $'\e[1m\e[31mError:\e[0m' "$@"
}

out=$PWD/nim
tag=
while getopts 'o:h' opt; do
case "$opt" in
'o')
out=$OPTARG
;;
'h')
print-help
exit 0
;;
*)
print-help
exit 1
;;
esac
done
unset opt

shift $((OPTIND - 1))
[[ $# -gt 0 ]] && prefix=$1 && tag=$2
if [[ -z "$prefix" ]] || [[ -z "$tag" ]]; then
print-help
exit 1
fi

mkdir -p "$out"
cd "$out"

if has-release "$tag"; then
archive="$prefix-$(get-archive-name)"
url="$_download_url/$tag/$archive"
msg "Downloading prebuilt archive '$archive' for tag '$tag' from '$url'"
if ! curl -f -LO "$url"; then
err "Archive '$archive' could not be found and/or downloaded. Maybe your OS/architecture does not have any prebuilt available?"
exit 1
fi
msg "Extracing '$archive'"
if [[ $archive == *.zip ]]; then
# Create a temporary directory
tmpdir=$(mktemp -d)
# extract archive to temporary dir
7z x "$archive" "-o$tmpdir"
# collect the extracted file names
extracted=( "$tmpdir"/* )
# use the first name collected, which should be the nim-<version> folder.
# This allows us to strip the first component of the path.
mv "${extracted[0]}/"* .
# remove the temporary dir afterwards
rm -rf "$tmpdir"
unset tmpdir
else
tar -xf "$archive" --strip-components 1
fi
else
err "Could not find any release at '$tag'."
exit 1
fi

ok "Installation to '$PWD' completed! The compiler and associated tools can be found at '$PWD/bin'"
49 changes: 46 additions & 3 deletions .github/workflows/ci.yml
Expand Up @@ -8,8 +8,13 @@ jobs:
test:
strategy:
matrix:
os: ['windows-latest', 'macos-latest', 'ubuntu-latest']
nim: ['devel', 'version-1-4', 'version-1-0']
os:
- windows-latest
- macos-latest
- ubuntu-latest
nim:
- version-1-4
- version-1-0

name: Nim ${{ matrix.nim }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand All @@ -24,4 +29,42 @@ jobs:
cd tests
nim c -r tester
- run: ./src/nimble install -y


# The following is copied largely from alaviss/setup-nim to support
# building a particular commit rather than the latest devel version.
# Once alaviss/setup-nim supports building a particular commit, it's
# recommended that the following be removed.
devel:
strategy:
matrix:
os:
- windows-latest
- macos-latest
- ubuntu-latest
tag:
- 2020-11-03-devel-fde17b159fdc96eda5609fd98e1fe3c7a34ef40b
name: Nim ${{ matrix.tag }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: 'Download the Nim compiler'
shell: bash
run: |
bash '.github/setup_from_release_url.sh' -o 'nim' 'nim-1.5.1' '${{ matrix.tag }}'
- name: 'Add the Nim compiler to PATH'
shell: bash
run: |
add-path() {
echo "$1" >> "$GITHUB_PATH"
echo "Directory '$1' has been added to PATH."
}
path='nim'
path=$(python -c "import os; import sys; print(os.path.realpath(sys.argv[1]))" "$path")
path=$path/bin
add-path "$path"
add-path "$HOME/.nimble/bin"
- run: nim --version
- run: |
cd tests
nim c -r tester
- run: ./src/nimble install -y

0 comments on commit 72877d2

Please sign in to comment.