diff --git a/Dockerfile b/Dockerfile index 78fefa0..0fbee86 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file +ENTRYPOINT ["/app/entrypoint.sh"] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..6a2bbc9 --- /dev/null +++ b/entrypoint.sh @@ -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 "github-actions@github.com" + + # 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 \ No newline at end of file diff --git a/main.py b/main.py index d069189..6078556 100644 --- a/main.py +++ b/main.py @@ -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, diff --git a/src/job.py b/src/job.py index 2d1ecf8..52a1d39 100644 --- a/src/job.py +++ b/src/job.py @@ -1,4 +1,3 @@ -from pathlib import Path def find_embed_lines(readme_path, lookup_string): embed_lines = [] @@ -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 @@ -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: @@ -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.")