Skip to content

Commit fc881a6

Browse files
authored
Merge pull request #36 from easimon/fix/ownership-of-github-workspace
fix: test build mount set to parent of current workspace
2 parents bb67daa + fadc013 commit fc881a6

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

.github/workflows/test.yaml

+25
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,31 @@ jobs:
3030
with:
3131
build-mount-path: /var/lib/docker/tmp
3232

33+
test-mount-parent-of-workspace:
34+
name: Test mounting the parent of GITHUB_WORKSPACE
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Check out Maximize Build Space action
38+
uses: actions/checkout@v4
39+
with:
40+
path: ./.github/actions/maximize-test
41+
42+
- name: Calculate parent of workspace
43+
id: workspace-parent
44+
run: echo "parent=$(dirname "${GITHUB_WORKSPACE}")" >> "$GITHUB_OUTPUT"
45+
46+
- name: Maximize build space
47+
uses: ./.github/actions/maximize-test
48+
with:
49+
build-mount-path: ${{ steps.workspace-parent.outputs.parent }}
50+
51+
- name: Create file in build folder as runner user (test ownership)
52+
run: |
53+
mkdir -p ${{ steps.workspace-parent.outputs.parent }}/new
54+
touch ${{ steps.workspace-parent.outputs.parent }}/new/file.txt
55+
touch ${GITHUB_WORKSPACE}/file.txt
56+
ls -alR ${{ steps.workspace-parent.outputs.parent }}
57+
3358
determine-free-space:
3459
name: Determine free space with different settings
3560
runs-on: ${{ matrix.os }}

action.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ runs:
111111
fi
112112
echo
113113
114+
# store owner of $GITHUB_WORKSPACE in case the action deletes it
115+
WORKSPACE_OWNER="$(stat -c '%U:%G' "${GITHUB_WORKSPACE}")"
116+
114117
# ensure mount path exists before the action
115118
sudo mkdir -p "${BUILD_MOUNT_PATH}"
116119
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:
182185
sudo mount "/dev/mapper/${VG_NAME}-buildlv" "${BUILD_MOUNT_PATH}"
183186
sudo chown -R "${{ inputs.build-mount-path-ownership }}" "${BUILD_MOUNT_PATH}"
184187
185-
# if build mount path is a parent of $GITHUB_WORKSPACE, recreate it
186-
sudo mkdir -p "${GITHUB_WORKSPACE}"
188+
# if build mount path is a parent of $GITHUB_WORKSPACE, and has been deleted, recreate it
189+
if [[ ! -d "${GITHUB_WORKSPACE}" ]]; then
190+
sudo mkdir -p "${GITHUB_WORKSPACE}"
191+
sudo chown -R "${WORKSPACE_OWNER}" "${GITHUB_WORKSPACE}"
192+
fi
187193
188194
- name: Disk space report after modification
189195
shell: bash

0 commit comments

Comments
 (0)