Skip to content

Commit

Permalink
feat: specific ruby version support (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreytse committed Apr 2, 2024
1 parent b4edbc7 commit 0a0bd15
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ inputs:
cname:
description: 'The cname to use for the site'
required: false
ruby_ver:
description: 'The Ruby version'
required: false
bundler_ver:
description: 'The Bundler version'
required: false
Expand Down
7 changes: 6 additions & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ SSH_PRIVATE_KEY=${INPUT_SSH_PRIVATE_KEY:=}
ACTOR=${INPUT_ACTOR}
REPOSITORY=${INPUT_REPOSITORY}
BRANCH=${INPUT_BRANCH}
BUNDLER_VER=${INPUT_BUNDLER_VER:=~>2.4.0}
RUBY_VER=${INPUT_RUBY_VER:=3.2.0}
BUNDLER_VER=${INPUT_BUNDLER_VER:=~>2.5.0}
JEKYLL_SRC=${INPUT_JEKYLL_SRC:=./}
JEKYLL_CFG=${INPUT_JEKYLL_CFG:=./_config.yml}
JEKYLL_BASEURL=${INPUT_JEKYLL_BASEURL:=}
Expand Down Expand Up @@ -149,4 +150,8 @@ if [[ -n "${SSH_PRIVATE_KEY}" ]]; then
rm -f ${SSH_PRIVATE_KEY_PATH}
fi

# Update cache key
echo "Update cache key..."
source ${SCRIPT_DIR}/script/update_cache_key.sh

exit ${PROVIDER_EXIT_CODE}
31 changes: 27 additions & 4 deletions script/init_environment.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

# Generate a default secret key
# To prevent archlinux-keyring from no secret key available to sign with
pacman-key --init

# Update packages database
pacman -Syu --noconfirm

Expand All @@ -11,11 +15,30 @@ if [[ -n "${SSH_PRIVATE_KEY}" ]]; then
pacman -S --noconfirm openssh
fi

# Installing ruby libraries
pacman -S --noconfirm ruby2.7 ruby-bundler
# Install asdf-vm for tools' version management
ASDF_HOME=${WORKING_DIR}/.asdf

if [[ ! -f "${ASDF_HOME}/asdf.sh" ]]; then
git clone https://github.com/asdf-vm/asdf.git \
${ASDF_HOME} --branch v0.14.0
fi

source ${ASDF_HOME}/asdf.sh

# Fix invalid cache to asdf tools' installation
ln -s ${ASDF_HOME} ${HOME}/.asdf

# Install ruby environment
pacman -S --noconfirm libyaml

if ! asdf list ruby ${RUBY_VER} &>/dev/null; then
# Clean up ruby environments avoiding unnecessary cache
rm -rf ${ASDF_HOME}/installs/ruby
asdf plugin add ruby
asdf install ruby ${RUBY_VER}
fi

# Setting default ruby version
cp /usr/bin/ruby-2.7 /usr/bin/ruby
asdf global ruby ${RUBY_VER}

# debug
ruby -v && bundle version
Expand Down
12 changes: 12 additions & 0 deletions script/update_cache_key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

CACHE_KEY_PATH=$HOME/cache.key

function sha1sumx() {
if [[ -f "$1" ]]; then
echo $(sha1sum "$1")>> $CACHE_KEY_PATH
fi
}

sha1sumx $(find "${WORKING_DIR}" -not -path "**/.asdf/**" -iname '**Gemfile.lock')
sha1sumx ${HOME}/.tool-versions

0 comments on commit 0a0bd15

Please sign in to comment.