From 421ea57488cf7242805b4ec09e8e5e4f8e798761 Mon Sep 17 00:00:00 2001 From: Dimi Kot Date: Sun, 6 Oct 2024 23:46:27 -0700 Subject: [PATCH] Absolutize local_dir in the action for better slug(local-dir) purposes Pull Request: https://github.com/dimikot/ci-storage/pull/25 (main) --- .github/workflows/ci.yml | 6 +++--- action.yml | 16 +++++++--------- .../guest/entrypoint.01-ci-storage-load.sh | 4 +++- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e677db..c1d7f52 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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; } @@ -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. diff --git a/action.yml b/action.yml index 1e107fa..021aa0e 100644 --- a/action.yml +++ b/action.yml @@ -45,6 +45,7 @@ runs: date default_run_hash="${{ github.run_id }}" + whoami=$(whoami) action="${{ inputs.action }}" storage_host="${{ inputs.storage-host || '' }}" @@ -61,6 +62,10 @@ 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 @@ -68,14 +73,7 @@ runs: 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:-"*"} @@ -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[@]}" diff --git a/docker/ci-runner/guest/entrypoint.01-ci-storage-load.sh b/docker/ci-runner/guest/entrypoint.01-ci-storage-load.sh index a51f04c..088a71a 100644 --- a/docker/ci-runner/guest/entrypoint.01-ci-storage-load.sh +++ b/docker/ci-runner/guest/entrypoint.01-ci-storage-load.sh @@ -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" @@ -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=$!