Skip to content

Commit

Permalink
fix entrypoint.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
kvankova committed Oct 19, 2024
1 parent 953b985 commit 5613feb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ ENV GITHUB_SHA=${GITHUB_SHA}
WORKDIR /app

RUN apt-get update \
&& pip install poetry==1.8.4
&& pip install poetry==1.8.4 \
&& apt-get install -y --no-install-recommends git

RUN poetry config virtualenvs.create false

COPY . /app/

RUN chmod +x /app/entrypoint.sh

ENV PATH="$POETRY_HOME/bin:$PATH"

RUN poetry install

ENTRYPOINT ["poetry", "run", "python", "/app/main.py"]
ENTRYPOINT ["/app/entrypoint.sh"]
31 changes: 31 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh -l
git add entrypoint.sh
git update-index --chmod=+x entrypoint.sh

README_PATH=${1:-README.md}

# Update the README file as needed
echo "Updating $README_PATH with code snippets..."

python3 main.py

# Check if there are changes to commit
if [ -n "$(git status -s)" ]; then # Use [ ] instead of [[ ]]
git config --global user.name "github-actions"
git config --global user.email "[email protected]"

# Ensure we're in the correct directory
cd "$GITHUB_WORKSPACE" # This is the default location for the checked out repo

git add "$README_PATH"

# Check if there are changes to commit
if ! git diff-index --quiet HEAD --; then
git commit -m "Update $README_PATH"
git push origin HEAD:${GITHUB_REF} # Push changes to the current branch
else
echo "No changes to commit."
fi
else
echo "No changes to commit."
fi
2 changes: 2 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
readme_path = readme_path,
lookup_string = lookup_string
)
print(script_to_embed)
embed_dict = job.read_embeds_from_readme(
embed_lines=script_to_embed,
project_root = project_root,
lookup_string = lookup_string
)
print(embed_dict)

job.replace_embeds_in_readme(
readme_path = readme_path,
Expand Down
7 changes: 3 additions & 4 deletions src/job.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pathlib import Path

def find_embed_lines(readme_path, lookup_string):
embed_lines = []
Expand Down Expand Up @@ -38,7 +37,6 @@ def replace_embeds_in_readme(readme_path, embed_dict, lookup_string):
inside_replacement_script = False
# Loop through each line in the README.md
for line in readme_content:
print(line)
if line.startswith(lookup_string):
updated_lines.append(line)
inside_replacement_script = True
Expand All @@ -49,8 +47,7 @@ def replace_embeds_in_readme(readme_path, embed_dict, lookup_string):
script_content = embed_dict[embed_path]
# Add the script content as a code block after the embed tag
updated_lines.append(f"{script_content}")
elif line.startswith('```') and inside_replacement_script:
updated_lines.append("\n")
elif line.startswith('```'):
updated_lines.append(line)
inside_replacement_script = False
elif not inside_replacement_script:
Expand All @@ -61,4 +58,6 @@ def replace_embeds_in_readme(readme_path, embed_dict, lookup_string):
with open(readme_path, 'w') as readme_file:
readme_file.writelines(updated_lines)

print("README.md looks like this:", "\n".join(updated_lines))

print("README.md updated successfully.")

0 comments on commit 5613feb

Please sign in to comment.