Skip to content

Commit

Permalink
refactor: use modules instead of embeded scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcer committed Nov 2, 2023
1 parent 751b7b5 commit 90886b1
Showing 1 changed file with 1 addition and 56 deletions.
57 changes: 1 addition & 56 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,61 +31,6 @@ runs:
- name: Setup MoonBit
shell: nu {0}
run: |
const CLI_HOST = 'https://cli.moonbitlang.com'
const CLI_DOWNLOAD_PATH = {
Windows: 'windows',
Ubuntu: 'ubuntu_x86',
Darwin: 'macos_intel',
}
export-env {
$env.config.color_config.leading_trailing_space_bg = { attr: n }
}
# If current host is Windows
export def windows? [] {
# Windows / Darwin / Linux
(sys).host.name == 'Windows'
}
# Create a line by repeating the unit with specified times
def build-line [
times: int,
unit: string = '-',
] {
0..<$times | reduce -f '' { |i, acc| $unit + $acc }
}
export def hr-line [
width?: int = 90,
--color(-c): string = 'g',
--blank-line(-b),
--with-arrow(-a),
] {
echo $'(ansi $color)(build-line $width)(if $with_arrow {'>'})(ansi reset)'
if $blank_line { char nl }
}
# Download moonbit binary files to local
export def 'setup moonbit' [] {
let MOONBIT_BIN_DIR = [$nu.home-path '.moon'] | path join
const DEFAULT_BINS = ['moon', 'moonc', 'moonfmt', 'moonrun', 'mooninfo']
const WINDOWS_BINS = ['moon.exe', 'moonc.exe', 'moonfmt.exe', 'moonrun.exe']
mkdir $MOONBIT_BIN_DIR; cd $MOONBIT_BIN_DIR
let DOWNLOAD_PATH = $CLI_DOWNLOAD_PATH | get -i (sys).host.name
if (windows?) {
$WINDOWS_BINS | each {|it| aria2c $'($CLI_HOST)/($DOWNLOAD_PATH)/($it)' }
} else {
$DEFAULT_BINS | each {|it| aria2c $'($CLI_HOST)/($DOWNLOAD_PATH)/($it)'; chmod +x $it }
}
echo (char nl)
echo $'Contents of ($MOONBIT_BIN_DIR):'; hr-line -b
echo (ls -l $MOONBIT_BIN_DIR)
echo $MOONBIT_BIN_DIR | save -a $env.GITHUB_PATH
}
use ${{ github.action_path }}/nu/moonbit.nu *
setup moonbit

0 comments on commit 90886b1

Please sign in to comment.