Skip to content

Commit

Permalink
feat: Add Github cache support
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcer committed Jun 10, 2024
1 parent 6c5ea23 commit 24d1532
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 7 deletions.
19 changes: 18 additions & 1 deletion action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,26 @@ runs:
with:
version: '0.94.2'

- name: Get Cache Suffix
id: cache-suffix
shell: nu {0}
run: |
use ${{ github.action_path }}/nu/bend.nu *
gen-cache-key
- uses: actions/cache@v4
id: cache
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.cargo/bin/hvm*
~/.cargo/bin/bend*
key: ${{ runner.os }}-check-${{ steps.cache-suffix.outputs.suffix }}

- name: Setup Bend
shell: nu {0}
run: |
use ${{ github.action_path }}/nu/bend.nu *
setup bend
setup bend ${{steps.cache.outputs.cache-hit}}
39 changes: 33 additions & 6 deletions nu/bend.nu
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Created: 2024/06/09 20:33:15
# TODO:
# [x] Support Windows, macOS, Linux
# [x] This script should run both in Github Runners and local machines
# [x] Add Github cache support
# Description: Scripts for setting up Bend environment

use common.nu [hr-line windows? is-installed]
Expand All @@ -12,16 +12,43 @@ export-env {
$env.config.color_config.leading_trailing_space_bg = { attr: n }
}

export def 'setup bend' [] {
export def 'setup bend' [cacheHit: bool = false] {
print $'Cache hit: ($cacheHit), type: ($cacheHit | describe)'
print "Setting up Bend environment..."; hr-line
print $'Gcc version: (ansi g)(gcc --version)(ansi reset)'
print $'Cargo version: (ansi g)(cargo --version)(ansi reset)'
print 'Installing Hvm2...'; hr-line
cargo install hvm
if $cacheHit != true {
print 'Installing Hvm2...'; hr-line
cargo install hvm
}
print $'Hvm version: (ansi g)(hvm --version)(ansi reset)'
print 'Installing Bend...'; hr-line
cargo install bend-lang
if $cacheHit != true {
print 'Installing Bend...'; hr-line
cargo install bend-lang
}
print $'Bend version: (ansi g)(bend --version)(ansi reset)'
}

# Generate cache key suffix by bend and hvm version
export def gen-cache-key [] {
let bend = cargo-search bend-lang | first
let hvm = cargo-search hvm | first
let key = $'($hvm.name):($hvm.version)-($bend.name):($bend.version)'
print $'Cache key suffix: ($key)'
echo $'suffix=($key)' o>> $env.GITHUB_OUTPUT
}

def cargo-search [ query: string, --limit=5 ] {
^cargo search $query --limit $limit
| lines
| each { |line|
if ($line | str contains "#") {
$line | parse --regex '(?P<name>.+) = "(?P<version>.+)" +# (?P<description>.+)'
} else {
$line | parse --regex '(?P<name>.+) = "(?P<version>.+)"'
}
}
| flatten
}

alias main = setup bend

0 comments on commit 24d1532

Please sign in to comment.