Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgomez committed Nov 27, 2024
1 parent 3a60cf0 commit 809ab9a
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 50 deletions.
2 changes: 0 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ updates:
directory: "/"
schedule:
interval: "daily"
assignees:
- "jiro4989"
6 changes: 3 additions & 3 deletions .github/workflows/test_versioning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.nimble
key: ${{ runner.os }}-nimble-v2
key: ${{ runner.os }}-nimble-v1
restore-keys: |
${{ runner.os }}-nimble-v2
${{ runner.os }}-nimble-v1
- uses: jiro4989/setup-nim-action@v2
- uses: nim-lang/setup-nimble-action@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

Expand Down
70 changes: 25 additions & 45 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,87 +1,67 @@
---
name: 'Setup Nim environment'
description: 'Setup a Nim environment and add it to the PATH'
author: 'jiro4989'
name: 'Setup Nimble environment'
description: 'Setup a Nimble environment and add it to the PATH'
author: 'jmgomez'

inputs:
nim-version:
nimble-version:
description: >-
The Nim version to download (if necessary)
and use. Example 1.0.2
The Nimble version to download (if necessary)
and use. Examples: '0.16.3', 'stable'
default: 'stable'
nim-install-directory:
required: false
nimble-install-directory:
description: >-
The Nim compiler installation directory.
default: '.nim_runtime'
parent-nim-install-directory:
The Nimble installation directory.
default: '.nimble_runtime'
required: false
parent-nimble-install-directory:
description: >-
The Nim compiler installation parent directory.
The Nimble installation parent directory.
It will be placed in the current directory if this parameter is empty.
default: ''
use-nightlies:
description: >-
Using nightlies build (https://github.com/nim-lang/nightlies/releases) if `nim-version` is `devel`.
The installation will be fast if this parameter is `true`.
If `nim-version` is not `devel`, then this parameter has no effect.
default: false
required: false
repo-token:
description: 'The GITHUB_TOKEN secret'
required: false

# NOTE: Unused parameters. These parameters were used in setup-nim-action@v1.
# setup-nim-action@v2 does not require these. These are left for backward compatibility.
no-color:
description: '[Deprecated] unused parameter'
default: false
"yes":
description: '[Deprecated] unused parameter'
default: false

runs:
using: 'composite'
steps:
- name: Install nim
- name: Install nimble
shell: bash
run: |
"${{ github.action_path }}/install_nim.sh" \
--nim-version "${{ inputs.nim-version }}" \
--parent-nim-install-directory "${{ inputs.parent-nim-install-directory }}" \
--nim-install-directory "${{ inputs.nim-install-directory }}" \
"${{ github.action_path }}/install_nimble.sh" \
--nimble-version "${{ inputs.nimble-version }}" \
--parent-nimble-install-directory "${{ inputs.parent-nimble-install-directory }}" \
--nimble-install-directory "${{ inputs.nimble-install-directory }}" \
--os "${{ runner.os }}" \
--use-nightlies "${{ inputs.use-nightlies }}" \
--repo-token "${{ inputs.repo-token }}"
- name: Set PATH for Unix
shell: bash
run: |
parent="${{ inputs.parent-nim-install-directory }}"
parent="${{ inputs.parent-nimble-install-directory }}"
if [[ "${parent}" = "" ]]; then
parent="$PWD"
fi
echo "$parent/${{ inputs.nim-install-directory }}/bin" >> "$GITHUB_PATH"
echo "$HOME/.nimble/bin" >> "$GITHUB_PATH"
echo "$parent/${{ inputs.nimble-install-directory }}/bin" >> "$GITHUB_PATH"
if: runner.os != 'Windows'

- name: Set PATH for Windows
shell: pwsh
run: |
$parent = "${{ inputs.parent-nim-install-directory }}"
$parent = "${{ inputs.parent-nimble-install-directory }}"
if ($parent -eq "") {
$parent = "$Pwd"
}
echo "$parent\${{ inputs.nim-install-directory }}\bin" >> $Env:GITHUB_PATH
mkdir -Force ~\.nimble\bin
(Resolve-Path ~\.nimble\bin).Path >> $Env:GITHUB_PATH
echo "$parent\${{ inputs.nimble-install-directory }}\bin" >> $Env:GITHUB_PATH
if: runner.os == 'Windows'

- name: Print nim directory
- name: Print nimble directory
shell: bash
run: |
echo "installed nim fullpath: $(which nim)"
- name: Print nim version
shell: bash
run: nim -v
echo "installed nimble fullpath: $(which nimble)"
- name: Print nimble version
shell: bash
Expand Down
115 changes: 115 additions & 0 deletions install_nimble.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/bash

set -eu

DATE_FORMAT="%Y-%m-%d %H:%M:%S"

info() {
echo "$(date +"$DATE_FORMAT") [INFO] $*"
}

err() {
echo "$(date +"$DATE_FORMAT") [ERR] $*"
}

fetch_tags() {
# https://docs.github.com/ja/rest/git/refs?apiVersion=2022-11-28
curl \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${repo_token}" \
-H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/nim-lang/nimble/git/refs/tags |
jq -r '.[].ref' |
sed -E 's:^refs/tags/v::'
}

tag_regexp() {
version=$1
echo "$version" |
sed -E \
-e 's/\./\\./g' \
-e 's/^/^/' \
-e 's/x$//'
}

latest_version() {
sort -V | tail -n 1
}

# parse commandline args
nimble_version="stable"
nimble_install_dir=".nimble_runtime"
os="Linux"
repo_token=""
parent_nimble_install_dir=""

while ((0 < $#)); do
opt=$1
shift
case $opt in
--nimble-version)
nimble_version=$1
shift
;;
--nimble-install-directory)
nimble_install_dir=$1
shift
;;
--parent-nimble-install-directory)
parent_nimble_install_dir=$1
shift
;;
--os)
os=$1
shift
;;
--repo-token)
repo_token=$1
shift
;;
esac
done

if [[ "$parent_nimble_install_dir" = "" ]]; then
parent_nimble_install_dir="$PWD"
fi

cd "$parent_nimble_install_dir"

# get exact version if stable
if [[ "$nimble_version" = "stable" ]]; then
nimble_version=$(fetch_tags | latest_version)
elif [[ "$nimble_version" =~ ^[0-9]+\.[0-9]+\.x$ ]] || [[ "$nimble_version" =~ ^[0-9]+\.x$ ]]; then
nimble_version="$(fetch_tags | grep -E "$(tag_regexp "$nimble_version")" | latest_version)"
fi

info "Installing nimble $nimble_version"

info "Current directory: $(pwd)"
info "Installing to: ${nimble_install_dir}/bin"

# Create installation directory
mkdir -p "${nimble_install_dir}/bin"

# Set architecture
arch="x64"

if [[ "$os" = "Windows" ]]; then
download_url="https://github.com/nim-lang/nimble/releases/download/v${nimble_version}/nimble-windows_${arch}.zip"
info "Downloading from: ${download_url}"
curl -sSL "${download_url}" > nimble.zip
unzip -j nimble.zip "nimble.exe" -d "${nimble_install_dir}/bin"
rm -f nimble.zip
elif [[ "$os" = "macOS" || "$os" = "Darwin" ]]; then
download_url="https://github.com/nim-lang/nimble/releases/download/v${nimble_version}/nimble-macosx_${arch}.tar.gz"
info "Downloading from: ${download_url}"
curl -sSL "${download_url}" | tar xvz -C "${nimble_install_dir}/bin"
else
download_url="https://github.com/nim-lang/nimble/releases/download/v${nimble_version}/nimble-linux_${arch}.tar.gz"
info "Downloading from: ${download_url}"
curl -sSL "${download_url}" | tar xvz -C "${nimble_install_dir}/bin"
fi

info "Contents of ${nimble_install_dir}/bin:"
ls -la "${nimble_install_dir}/bin"

info "Nimble installation complete"

0 comments on commit 809ab9a

Please sign in to comment.