Skip to content

Commit

Permalink
feat: add fixes for GitHub Actions integration
Browse files Browse the repository at this point in the history
Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Jun 28, 2023
1 parent 25d2cc8 commit 87149dd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ inputs:
branch:
description: Git branch name, where changes should be pushed too. Required if Action is used on the `pull_request` event
required: false
default: ${{ github.head_ref }}
default: ${{ github.ref_name }}
file_pattern:
description: File pattern used for `git add`. For example `component-definitions/*`. Defaults to (`.`)
required: false
Expand Down Expand Up @@ -55,7 +55,7 @@ outputs:
runs:
using: "docker"
image: "Dockerfile"
entrypoint: [ "/entrypoint.sh"]
entrypoint: "/entrypoint.sh"

branding:
icon: "check"
Expand Down
27 changes: 23 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

set -eu

# Manage newest git versions (related to CVE https://github.blog/2022-04-12-git-security-vulnerability-announced/)
#
if [ -z ${GITHUB_WORKSPACE+x} ]; then
echo "Setting git safe.directory default: /github/workspace ..."
git config --global --add safe.directory /github/workspace
else
echo "Setting git safe.directory GITHUB_WORKSPACE: $GITHUB_WORKSPACE ..."
git config --global --add safe.directory "$GITHUB_WORKSPACE"
fi

if [ -z ${INPUT_REPOSITORY+x} ]; then
echo "Skipping setting working directory as safe directory"
else
echo "Setting git safe.directory default: $INPUT_REPOSITORY..."
git config --global --add safe.directory "$INPUT_REPOSITORY"
fi

exec 3>&1

trap exec 3>&- EXIT

output=$(python3.8 -m trestlebot \
--markdown-path="${INPUT_MARKDOWN_PATH}" \
--assemble-model="${INPUT_ASSEMBLE_MODEL}" \
Expand All @@ -13,9 +34,7 @@ output=$(python3.8 -m trestlebot \
--committer-email="${INPUT_COMMIT_USER_EMAIL}" \
--author-name="${INPUT_COMMIT_AUTHOR_NAME}" \
--author-email="${INPUT_COMMIT_AUTHOR_EMAIL}" \
--working-dir="${INPUT_WORKING_DIR}" 2>&1 | tee log.txt)

cat log.txt
--working-dir="${INPUT_REPOSITORY}" | tee /dev/fd/3)

commit=$(echo "$output" | grep "Commit Hash:" | sed 's/.*: //')

Expand All @@ -24,4 +43,4 @@ if [ -n "$commit" ]; then
echo "commit=$commit" >> "$GITHUB_OUTPUT"
else
echo "changes=false" >> "$GITHUB_OUTPUT"
fi
fi
11 changes: 9 additions & 2 deletions trestlebot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,15 @@ class RepoException(Exception):
def _stage_files(gitwd: Repo, patterns: List[str]) -> None:
"""Stages files in git based on file patterns"""
for pattern in patterns:
logging.info(f"Adding file for pattern {pattern}")
gitwd.index.add(pattern)
if pattern == ".":
logging.info("Staging all repository changes")
# Using check to avoid adding git directory
# https://github.com/gitpython-developers/GitPython/issues/292
gitwd.git.add(all=True)
return
else:
logging.info(f"Adding file for pattern {pattern}")
gitwd.git.add(pattern)


def _local_commit(
Expand Down
3 changes: 2 additions & 1 deletion trestlebot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ def run() -> None:
)

# Print the full commit sha
print(f" Commit Hash: {commit_sha}")
if commit_sha:
print(f"Commit Hash: {commit_sha}")

except Exception as e:
exit_code = handle_exception(e)
Expand Down

0 comments on commit 87149dd

Please sign in to comment.