Skip to content

fix(github-actions): add filesystem UID/GID fixer after action workspace modification #1262

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ jobs:

- name: Release | Python Semantic Release
id: release
uses: python-semantic-release/python-semantic-release@917a2c730cb8f6c8cd3d00f23c876d724a4a844c # v10.0.1
uses: ./
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
verbosity: 1
Expand All @@ -165,7 +165,6 @@ jobs:
GIT_COMMITTER_NAME: ${{ env.GITHUB_ACTIONS_AUTHOR_NAME }}
GIT_COMMITTER_EMAIL: ${{ env.GITHUB_ACTIONS_AUTHOR_EMAIL }}
run: |
ls -la .git/
MINOR_VERSION_TAG="$(echo "$FULL_VERSION_TAG" | cut -d. -f1,2)"
git tag --force --annotate "$MINOR_VERSION_TAG" "${FULL_VERSION_TAG}^{}" -m "$MINOR_VERSION_TAG"
git push -u origin "$MINOR_VERSION_TAG" --force
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ jobs:
test-gh-action:
name: Validate Action Build & Execution
runs-on: ubuntu-latest
if: inputs.gha-src-files-changed == 'true' || inputs.gha-test-files-changed == 'true' || inputs.ci-files-changed == 'true'
if: ${{ inputs.gha-src-files-changed == 'true' || inputs.gha-test-files-changed == 'true' || inputs.ci-files-changed == 'true' }}

needs:
- build
Expand Down
20 changes: 20 additions & 0 deletions src/gh_action/action.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

WORKSPACE_DIR="$(pwd)"

explicit_run_cmd() {
local cmd=""
cmd="$(printf '%s' "$*" | sed 's/^ *//g' | sed 's/ *$//g')"
Expand Down Expand Up @@ -49,6 +51,20 @@ eval_string_input() {
printf '%s' "${if_defined/\%s/$value}"
}

# Capture UID and GID of the external filesystem
if [ ! -f "$WORKSPACE_DIR/.git/HEAD" ]; then
echo "::error:: .git/HEAD file not found. Ensure you are in a valid git repository."
exit 1
fi

EXT_HOST_UID="$(stat -c '%u' "$WORKSPACE_DIR/.git/HEAD")"
EXT_HOST_GID="$(stat -c '%g' "$WORKSPACE_DIR/.git/HEAD")"

if [ -z "$EXT_HOST_UID" ] || [ -z "$EXT_HOST_GID" ]; then
echo "Error: Unable to determine external filesystem UID/GID from .git/HEAD"
exit 1
fi

# Convert inputs to command line arguments
ROOT_OPTIONS=()

Expand Down Expand Up @@ -165,5 +181,9 @@ export GH_TOKEN="${INPUT_GITHUB_TOKEN}"
# normalize extra spaces into single spaces as you combine the arguments
CMD_ARGS="$(printf '%s' "${ROOT_OPTIONS[*]} version ${ARGS[*]}" | sed 's/ [ ]*/ /g' | sed 's/^ *//g')"

# Make sure the workspace directory is owned by the external filesystem UID/GID no matter what
# This is to ensure that after the action, and a commit was created, the files are owned by the external filesystem
trap "chown -R $EXT_HOST_UID:$EXT_HOST_GID '$WORKSPACE_DIR'" EXIT

# Run Semantic Release (explicitly use the GitHub action version)
explicit_run_cmd "$PSR_VENV_BIN/semantic-release $CMD_ARGS"
Loading