Skip to content

Commit

Permalink
Merge pull request #36 from easimon/fix/ownership-of-github-workspace
Browse files Browse the repository at this point in the history
fix: test build mount set to parent of current workspace
  • Loading branch information
easimon authored Dec 4, 2023
2 parents bb67daa + fadc013 commit fc881a6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
10 changes: 8 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "{}" \;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fc881a6

Please sign in to comment.