Skip to content

Commit

Permalink
Absolutize local_dir in the action for better slug(local-dir) purposes
Browse files Browse the repository at this point in the history
Pull Request: #25 (main)
  • Loading branch information
dimikot committed Oct 7, 2024
1 parent 1356442 commit 421ea57
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Check that dummy.txt was restored
run: |
set -e
ls -la ~/storage-dir/${{ github.repository }}/_
ls -la ~/storage-dir/${{ github.repository }}/*
[[ "$(cat dummy.txt)" == "dummy" ]] || { echo "dummy.txt must be restored"; exit 1; }
- name: Remove dir/subdir/layer.txt
Expand All @@ -81,7 +81,7 @@ jobs:
- name: Check that dir/subdir/layer.txt was restored, and dummy.txt still exists
run: |
set -e
ls -la ~/storage-dir/${{ github.repository }}/_.my-layer
ls -la ~/storage-dir/${{ github.repository }}/*
[[ "$(cat dummy.txt)" == "dummy" ]] || { echo "dummy.txt must be kept"; exit 1; }
[[ "$(cat dir/subdir/layer.txt)" == "layer" ]] || { echo "layer.txt must be restored"; exit 1; }
Expand All @@ -96,7 +96,7 @@ jobs:
- name: Check that /tmp/dir/local-dir.txt was restored
run: |
set -e
ls -la ~/storage-dir/${{ github.repository }}/_tmp_dir
ls -la ~/storage-dir/${{ github.repository }}/*
[[ "$(cat /tmp/dir/local-dir.txt)" == "local-dir" ]] || { echo "/tmp/dir/local-dir.txt must be restored"; exit 1; }
# Tests ci-scaler logic.
Expand Down
16 changes: 7 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ runs:
date
default_run_hash="${{ github.run_id }}"
whoami=$(whoami)
action="${{ inputs.action }}"
storage_host="${{ inputs.storage-host || '' }}"
Expand All @@ -61,21 +62,18 @@ runs:
storage_host=$(cat ~/ci-storage-host)
fi
if [[ "$storage_host" != "" && "$storage_host" != *@* ]]; then
storage_host="$whoami@$storage_host"
fi
if [[ "$slot_id" == "" ]]; then
slot_id="$default_run_hash"
elif [[ "$slot_id" == "*" && "$action" == "load" ]]; then
# If "*" is used, always prefer our own default_run_hash.
slot_id="$default_run_hash $slot_id"
fi
if [[ "$local_dir" == "/" ]]; then
echo "You cannot use / as local-dir."
exit 1
elif [[ "$local_dir" == "." ]]; then
storage_dir="$storage_dir/_"
else
storage_dir="$storage_dir/$(echo "$local_dir" | tr / _)"
fi
storage_dir="$storage_dir/$(realpath "$local_dir" | tr / _)"
if [[ "$layer_name" != "" ]]; then
layer_include=${layer_include:-"*"}
Expand All @@ -99,7 +97,7 @@ runs:
"$action"
)
if [[ -d "$local_dir" && "$(stat -c '%U' "$local_dir")" != "$(whoami)" ]]; then
if [[ -d "$local_dir" && "$(stat -c '%U' "$local_dir")" != "$whoami" ]]; then
sudo /usr/bin/ci-storage "${args[@]}"
else
"${{ github.action_path }}/ci-storage" "${args[@]}"
Expand Down
4 changes: 3 additions & 1 deletion docker/ci-runner/guest/entrypoint.01-ci-storage-load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ set -u -e

echo "$CI_STORAGE_HOST" > ci-storage-host

# For some reason, the default GitHub Runner's work directory is
# "$WORK_DIR/{repo-name}/{repo-name}" (i.e. repo-name is repeated twice).
local_dir=$WORK_DIR/${GH_REPOSITORY##*/}/${GH_REPOSITORY##*/}

mkdir -p "$local_dir"
Expand All @@ -18,7 +20,7 @@ if [[ "$CI_STORAGE_HOST" != "" && -f ~/.ssh/id_rsa ]]; then
say "Running the initial \"ci-storage load\" for $local_dir..."
ci-storage load \
--storage-host="$CI_STORAGE_HOST" \
--storage-dir="$WORK_DIR/$GH_REPOSITORY/_" \
--storage-dir="$WORK_DIR/$GH_REPOSITORY/$(realpath "$local_dir" | tr / _)" \
--slot-id="*" \
--local-dir="$local_dir" \
& export CI_STORAGE_PID=$!
Expand Down

0 comments on commit 421ea57

Please sign in to comment.