diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 92071a9..6079811 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -30,6 +30,31 @@ jobs: with: build-mount-path: /var/lib/docker/tmp + test-mount-parent-of-workspace: + name: Test mounting the parent of GITHUB_WORKSPACE + runs-on: ubuntu-latest + steps: + - name: Check out Maximize Build Space action + uses: actions/checkout@v4 + with: + path: ./.github/actions/maximize-test + + - name: Calculate parent of workspace + id: workspace-parent + run: echo "parent=$(dirname "${GITHUB_WORKSPACE}")" >> "$GITHUB_OUTPUT" + + - name: Maximize build space + uses: ./.github/actions/maximize-test + with: + build-mount-path: ${{ steps.workspace-parent.outputs.parent }} + + - name: Create file in build folder as runner user (test ownership) + run: | + mkdir -p ${{ steps.workspace-parent.outputs.parent }}/new + touch ${{ steps.workspace-parent.outputs.parent }}/new/file.txt + touch ${GITHUB_WORKSPACE}/file.txt + ls -alR ${{ steps.workspace-parent.outputs.parent }} + determine-free-space: name: Determine free space with different settings runs-on: ${{ matrix.os }} diff --git a/action.yml b/action.yml index b956952..04f3923 100644 --- a/action.yml +++ b/action.yml @@ -111,6 +111,9 @@ runs: fi echo + # store owner of $GITHUB_WORKSPACE in case the action deletes it + WORKSPACE_OWNER="$(stat -c '%U:%G' "${GITHUB_WORKSPACE}")" + # ensure mount path exists before the action sudo mkdir -p "${BUILD_MOUNT_PATH}" sudo find "${BUILD_MOUNT_PATH}" -maxdepth 0 ! -empty -exec echo 'WARNING: directory [{}] is not empty, data loss might occur. Content:' \; -exec ls -al "{}" \; @@ -182,8 +185,11 @@ runs: sudo mount "/dev/mapper/${VG_NAME}-buildlv" "${BUILD_MOUNT_PATH}" sudo chown -R "${{ inputs.build-mount-path-ownership }}" "${BUILD_MOUNT_PATH}" - # if build mount path is a parent of $GITHUB_WORKSPACE, recreate it - sudo mkdir -p "${GITHUB_WORKSPACE}" + # if build mount path is a parent of $GITHUB_WORKSPACE, and has been deleted, recreate it + if [[ ! -d "${GITHUB_WORKSPACE}" ]]; then + sudo mkdir -p "${GITHUB_WORKSPACE}" + sudo chown -R "${WORKSPACE_OWNER}" "${GITHUB_WORKSPACE}" + fi - name: Disk space report after modification shell: bash