-
Notifications
You must be signed in to change notification settings - Fork 20
Add elixir 1.17 #144
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
base: main
Are you sure you want to change the base?
Add elixir 1.17 #144
Conversation
WalkthroughThis update introduces Elixir starter templates, solution files, and supporting infrastructure for a "Build Your Own Git" challenge. It adds shell scripts for compiling and running Elixir projects, project configuration files, code formatters, and documentation. The main program logic is implemented in a new Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI_Module as CLI.main/1
participant FileSystem
User->>CLI_Module: Run program with argv
alt argv is ["init"]
CLI_Module->>FileSystem: Create .git/objects and .git/refs
CLI_Module->>FileSystem: Write .git/HEAD file
CLI_Module-->>User: Print "Initialized git directory"
else argv is [unknown_command]
CLI_Module-->>User: Print "Unknown command"
CLI_Module-->>User: Exit with status 1
else argv is []
CLI_Module-->>User: Print usage instructions
CLI_Module-->>User: Exit with status 1
end
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (13)
solutions/elixir/01-gg4/code/mix.exs (2)
5-14
: Project configuration is set up for Elixir 1.17.
elixir: "~> 1.17"
specifies support for Elixir v1.17 and above.escript: [main_module: CLI]
definesCLI
as the entry point for the compiled executable.Consider pinning to the patch version (
"~> 1.17.0"
) if you intend to restrict to 1.17.x and prevent inadvertent upgrades to 1.18+.
23-29
: Dependency list is empty but ready for future additions.
You might remove the commented examples if you prefer a cleanerdeps/0
, but keeping them can help contributors learn how to add dependencies.compiled_starters/elixir/.codecrafters/run.sh (1)
9-11
: Add a pre-flight check for the compiled binary.If
/tmp/codecrafters-build-git-elixir
is missing or not executable, the script will fail with a cryptic error. Consider:+ if [ ! -x /tmp/codecrafters-build-git-elixir ]; then + echo "Error: executable not found or not executable at /tmp/codecrafters-build-git-elixir" >&2 + exit 1 + fi exec /tmp/codecrafters-build-git-elixir "$@"starter_templates/elixir/code/.codecrafters/compile.sh (1)
11-12
: Ensure dependencies are fetched before building.To support any future dependencies declared in
mix.exs
, insert:+ mix deps.get --only prod mix escript.build mv codecrafters_git /tmp/codecrafters-build-git-elixir
solutions/elixir/01-gg4/code/.codecrafters/compile.sh (1)
11-12
: Fetch and compile dependencies in CI.Even if the current solution has no external deps, adding:
+ mix deps.get --only prod mix escript.build mv codecrafters_git /tmp/codecrafters-build-git-elixir
will ensure the build remains robust when new dependencies are introduced.
starter_templates/elixir/code/mix.exs (1)
1-4
: Align the Mix project module name with the app name.The stub
App.MixProject
is generic. Renaming it to match the OTP app (:codecrafters_git
)—for example,CodecraftersGit.MixProject
—improves readability and consistency:-defmodule App.MixProject do +defmodule CodecraftersGit.MixProject do use Mix.Projectcompiled_starters/elixir/.codecrafters/compile.sh (1)
11-12
: Add dependency fetching for resilience.Although the starter has no external dependencies today, including:
+ mix deps.get --only prod mix escript.build mv codecrafters_git /tmp/codecrafters-build-git-elixir
will future-proof the compile step if deps are ever added.
solutions/elixir/01-gg4/code/lib/main.ex (1)
1-20
: LGTM: Well-structured Elixir implementation of Git initThe code properly implements the CLI functionality for initializing a Git repository with the correct directory structure and file content. It follows Elixir best practices with effective pattern matching and explicit error handling.
One potential enhancement would be to handle the case where the
.git
directory or its subdirectories already exist. For a more robust implementation, consider:- :ok = File.mkdir(".git") + :ok = File.mkdir_p(".git")And adding error handling for cases where files might already exist.
solutions/elixir/01-gg4/explanation.md (1)
28-32
: Add language specification to the fenced code blockAdding a language specification to the fenced code block will improve syntax highlighting and make the document more consistent with Markdown best practices.
-``` +```bash git add . git commit -m "pass 1st stage" # any msg git push origin master🧰 Tools
🪛 markdownlint-cli2 (0.17.2)
28-28: Fenced code blocks should have a language specified
null(MD040, fenced-code-language)
solutions/elixir/01-gg4/code/README.md (1)
7-9
: Add a comma after "Along the way" for better readabilityThis is a compound sentence with two independent clauses that should be separated by a comma.
initializing a repository, creating commits and cloning a public repository. -Along the way we'll learn about the `.git` directory, Git objects (blobs, +Along the way, we'll learn about the `.git` directory, Git objects (blobs, commits, trees etc.), Git's transfer protocols and more.🧰 Tools
🪛 LanguageTool
[uncategorized] ~8-~8: A comma might be missing here.
Context: ... cloning a public repository. Along the way we'll learn about the.git
directory,...(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)
compiled_starters/elixir/README.md (1)
7-9
: Add a comma after "Along the way" for better readabilityThis is a compound sentence with two independent clauses that should be separated by a comma.
initializing a repository, creating commits and cloning a public repository. -Along the way we'll learn about the `.git` directory, Git objects (blobs, +Along the way, we'll learn about the `.git` directory, Git objects (blobs, commits, trees etc.), Git's transfer protocols and more.🧰 Tools
🪛 LanguageTool
[uncategorized] ~8-~8: A comma might be missing here.
Context: ... cloning a public repository. Along the way we'll learn about the.git
directory,...(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)
starter_templates/elixir/code/lib/main.ex (2)
10-13
: Consider adding error handling for file operations.The code assumes file operations will always succeed with
:ok
results. In a real-world implementation, you might want to handle potential errors when creating directories or writing files.# When uncommenting, consider updating with error handling: -# :ok = File.mkdir(".git") -# :ok = File.mkdir(".git/objects") -# :ok = File.mkdir(".git/refs") -# :ok = File.write(".git/HEAD", "ref: refs/heads/main\n") +# case File.mkdir(".git") do +# :ok -> +# with {:ok, _} <- File.mkdir(".git/objects"), +# {:ok, _} <- File.mkdir(".git/refs"), +# {:ok, _} <- File.write(".git/HEAD", "ref: refs/heads/main\n") do +# IO.puts("Initialized git directory") +# else +# {:error, reason} -> +# IO.puts("Error initializing git directory: #{inspect(reason)}") +# System.halt(1) +# end +# {:error, reason} -> +# IO.puts("Error creating .git directory: #{inspect(reason)}") +# System.halt(1) +# end
1-25
: Consider adding module documentation.Adding
@moduledoc
and@doc
annotations would help users understand the purpose of the module and its functions.+# @moduledoc """ +# CLI module that implements Git-like functionality for the CodeCrafters challenge. +# """ defmodule CLI do + @doc """ + Main entry point that processes command line arguments. + + ## Parameters + + - argv: List of command-line arguments + """ def main(argv) do # You can use print statements as follows for debugging, they'll be visible when running tests. IO.puts("Logs from your program will appear here!")
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (30)
compiled_starters/elixir/.codecrafters/compile.sh
(1 hunks)compiled_starters/elixir/.codecrafters/run.sh
(1 hunks)compiled_starters/elixir/.formatter.exs
(1 hunks)compiled_starters/elixir/.gitattributes
(1 hunks)compiled_starters/elixir/.gitignore
(1 hunks)compiled_starters/elixir/README.md
(1 hunks)compiled_starters/elixir/codecrafters.yml
(1 hunks)compiled_starters/elixir/lib/main.ex
(1 hunks)compiled_starters/elixir/mix.exs
(1 hunks)compiled_starters/elixir/your_program.sh
(1 hunks)dockerfiles/elixir-1.17.Dockerfile
(1 hunks)solutions/elixir/01-gg4/code/.codecrafters/compile.sh
(1 hunks)solutions/elixir/01-gg4/code/.codecrafters/run.sh
(1 hunks)solutions/elixir/01-gg4/code/.formatter.exs
(1 hunks)solutions/elixir/01-gg4/code/.gitattributes
(1 hunks)solutions/elixir/01-gg4/code/.gitignore
(1 hunks)solutions/elixir/01-gg4/code/README.md
(1 hunks)solutions/elixir/01-gg4/code/codecrafters.yml
(1 hunks)solutions/elixir/01-gg4/code/lib/main.ex
(1 hunks)solutions/elixir/01-gg4/code/mix.exs
(1 hunks)solutions/elixir/01-gg4/code/your_program.sh
(1 hunks)solutions/elixir/01-gg4/diff/lib/main.ex.diff
(1 hunks)solutions/elixir/01-gg4/explanation.md
(1 hunks)starter_templates/elixir/code/.codecrafters/compile.sh
(1 hunks)starter_templates/elixir/code/.codecrafters/run.sh
(1 hunks)starter_templates/elixir/code/.formatter.exs
(1 hunks)starter_templates/elixir/code/.gitignore
(1 hunks)starter_templates/elixir/code/lib/main.ex
(1 hunks)starter_templates/elixir/code/mix.exs
(1 hunks)starter_templates/elixir/config.yml
(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
compiled_starters/elixir/lib/main.ex (2)
solutions/elixir/01-gg4/code/lib/main.ex (1)
main
(2-19)starter_templates/elixir/code/lib/main.ex (1)
main
(2-24)
starter_templates/elixir/code/lib/main.ex (1)
solutions/elixir/01-gg4/code/lib/main.ex (1)
main
(2-19)
solutions/elixir/01-gg4/code/lib/main.ex (2)
compiled_starters/elixir/lib/main.ex (1)
main
(2-24)starter_templates/elixir/code/lib/main.ex (1)
main
(2-24)
🪛 LanguageTool
solutions/elixir/01-gg4/code/README.md
[uncategorized] ~8-~8: A comma might be missing here.
Context: ... cloning a public repository. Along the way we'll learn about the .git
directory,...
(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)
compiled_starters/elixir/README.md
[uncategorized] ~8-~8: A comma might be missing here.
Context: ... cloning a public repository. Along the way we'll learn about the .git
directory,...
(AI_EN_LECTOR_MISSING_PUNCTUATION_COMMA)
🪛 Hadolint (2.12.0)
dockerfiles/elixir-1.17.Dockerfile
[error] 10-10: invalid flag: --exclude
(DL1000)
🪛 markdownlint-cli2 (0.17.2)
solutions/elixir/01-gg4/explanation.md
28-28: Fenced code blocks should have a language specified
null
(MD040, fenced-code-language)
🔇 Additional comments (32)
solutions/elixir/01-gg4/code/.gitattributes (1)
1-2
: Approve line-ending normalization
The.gitattributes
file correctly enforces automatic line-ending normalization for all text files in the solution directory, ensuring cross-platform consistency.compiled_starters/elixir/.gitattributes (1)
1-2
: Approve line-ending normalization in starter
This.gitattributes
entry ensures that starter files undercompiled_starters/elixir/
will have normalized line endings, matching the solution setup.compiled_starters/elixir/.formatter.exs (1)
1-5
: Approve Elixir formatter configuration
The input patterns covermix.exs
,.formatter.exs
, and all.ex
/.exs
files underconfig
,lib
, andtest
. This aligns with standard Mix formatting conventions.solutions/elixir/01-gg4/code/.gitignore (1)
1-28
: Approve Elixir solution .gitignore patterns
The ignore rules comprehensively cover build artifacts (_build/
), dependencies (deps/
), coverage reports (cover/
), and other temporary files (.ez
,erl_crash.dump
, etc.). This mirrors best practices for Mix-based projects.solutions/elixir/01-gg4/code/mix.exs (3)
1-4
: Module definition and Mix integration look correct.
TheApp.MixProject
module properly usesMix.Project
and follows standard conventions.
17-21
: Application extra applications are minimal and appropriate.
Starting only:logger
is sufficient if your runtime logic doesn’t depend on other OTP apps.
5-14
:✅ Verification successful
Verify the existence and namespace of the
CLI
module.
Ensure thatlib/main.ex
defines a top-levelCLI
module (i.e.,defmodule CLI do ... end
) so thatmix escript.build
can correctly resolve themain_module
.Run:
🏁 Script executed:
#!/bin/bash # Verify top-level CLI module declaration rg --max-count=1 "^defmodule CLI" -n solutions/elixir/01-gg4/code/libLength of output: 131
CLI module correctly defined
Verified that
CLI
is declared insolutions/elixir/01-gg4/code/lib/main.ex:1
(defmodule CLI do … end
), soescript
will resolvemain_module: CLI
without issues.starter_templates/elixir/config.yml (1)
1-3
: Starter template configuration is correct.
Therequired_executable
anduser_editable_file
keys align with our challenge runner’s expectations for setting up the development environment.solutions/elixir/01-gg4/code/.formatter.exs (1)
1-4
: Formatter inputs are correctly specified.
These patterns ensuremix format
coversmix.exs
,.formatter.exs
, and all.ex/.exs
files under the standard directories.starter_templates/elixir/code/.formatter.exs (1)
1-4
: Formatter configuration in starter matches solution.
Consistent formatting rules across starter and solution templates will help maintain code style.compiled_starters/elixir/.gitignore (5)
1-7
: Ignoring compiled binaries and build artifacts is correct.
/codecrafters_git
and/_build/
ensure that generated escripts and artifacts aren’t committed.
8-12
: Coverage and dependencies folders are excluded.
Patterns for/cover/
and/deps/
will keep test artifacts and fetched dependencies out of source control.
13-18
: Documentation and fetch artifacts are ignored.
/doc/
and/.fetch
align with Mix’s conventions.
19-21
: Erlang VM crash dumps are excluded.
erl_crash.dump
is appropriately ignored.
22-27
: Archive artifacts are covered.
*.ez
andapp-*.tar
patterns prevent hex archives from polluting the repo.solutions/elixir/01-gg4/code/codecrafters.yml (2)
5-5
: Configuration for debug logs added.
Thedebug: false
flag is a sensible default to avoid verbose output in the solution environment.
11-11
: Elixir version set to 1.17.
Lockinglanguage_pack: elixir-1.17
aligns with the PR objective to support Elixir 1.17.compiled_starters/elixir/codecrafters.yml (2)
5-5
: Default debug logging disabled.
Keepingdebug: false
in the compiled starter is appropriate for clean initial runs.
11-11
: Elixir version locked to 1.17.
Specifyingelixir-1.17
in the starter ensures consistency with the solution and the intended environment.starter_templates/elixir/code/.gitignore (2)
4-27
: Standard Elixir build artifacts are ignored.
The rest of the patterns correctly exclude_build/
,cover/
,deps/
,doc/
,.fetch
, crash dumps, archive artifacts (*.ez
), and tarballs (app-*.tar
). This aligns with typical Elixir/Mix workflows.
1-2
:✅ Verification successful
Verify compiled binary ignore pattern.
The line/codecrafters_git
should match the escript executable name produced by your Mix project (as invoked in.codecrafters/compile.sh
and.codecrafters/run.sh
). Please confirm the actual output filename inmix.exs
and update this entry if needed to ensure the binary is properly excluded.
🏁 Script executed:
#!/bin/bash # Verify escript name defined in mix.exs rg -n "escript: *:.*" starter_templates/elixir/code/mix.exsLength of output: 61
🏁 Script executed:
#!/bin/bash # Check project app name rg -n "app:" -C2 starter_templates/elixir/code/mix.exs # Check for any escript configuration rg -n "escript" -C2 starter_templates/elixir/code/mix.exsLength of output: 348
.gitignore escript ignore pattern verified
The Mix project’sapp: :codecrafters_git
together withescript: [main_module: CLI]
yields a binary namedcodecrafters_git
by default, so the/codecrafters_git
entry in.gitignore
is correct.starter_templates/elixir/code/.codecrafters/run.sh (2)
1-8
: Shell script header and comments are clear.
The shebang (#!/bin/sh
),set -e
, and documentation comments correctly frame this run script for CodeCrafters.
9-12
: Executes the compiled escript.
The call toexec /tmp/codecrafters-build-git-elixir "$@"
cleanly forwards arguments to the built escript. Ensure the compile step generates the binary at this location.solutions/elixir/01-gg4/code/.codecrafters/run.sh (2)
1-8
: Run script header is appropriately documented.
Shebang,set -e
, and usage comments are all present to meet CodeCrafters conventions.
9-12
: Executes the solution escript.
Forwarding"$@"
to the/tmp/codecrafters-build-git-elixir
binary matches the starter logic and will correctly invoke the compiled solution.compiled_starters/elixir/your_program.sh (1)
1-25
: LGTM: Shell script follows best practicesThe shell script is well-structured with proper directory navigation, error handling with
set -e
, and correct use ofexec
to pass arguments. The comments clearly explain the purpose and relationship to the remote compilation process.solutions/elixir/01-gg4/code/your_program.sh (1)
1-25
: LGTM: Consistent shell script implementationThis script is identical to the one in the compiled_starters directory, maintaining consistency across the starter and solution codebases. It correctly handles compilation and execution of the Elixir Git implementation.
solutions/elixir/01-gg4/diff/lib/main.ex.diff (1)
1-41
: LGTM: Properly uncommented the Git init implementationThe diff correctly uncomments and implements the first stage of the Git challenge. The code follows Elixir best practices with proper pattern matching, error handling, and file operations to create the expected
.git
directory structure.compiled_starters/elixir/mix.exs (1)
1-30
: LGTM: Mix.exs file is correctly configured for the Elixir 1.17 projectThe Mix project configuration is well-structured and correctly sets up:
- Proper app name and versioning
- Correct Elixir version requirement (~> 1.17)
- Escript configuration pointing to the CLI module as the main entry point
- Required applications and empty dependency list (with helpful commented examples)
compiled_starters/elixir/lib/main.ex (1)
1-25
: LGTM: The CLI module is correctly implemented as a starter templateThe CLI module is well-structured with:
- Proper entry point using the main/1 function to accept command-line arguments
- Helpful debug statement to show users how to output logs
- Well-commented code block that correctly implements the Git init command
- Proper pattern matching for different command scenarios
The implementation matches the solution example and follows Elixir best practices.
starter_templates/elixir/code/lib/main.ex (2)
1-5
: Clear module structure with helpful debug statement.The module definition and debug print statement provide a good starting point for users. The debug message clearly indicates where logs will appear during testing.
6-23
: Well-structured commented code block for the first challenge stage.The commented implementation provides clear guidance on how to initialize a Git repository, with proper directory structure creation and HEAD file setup. The pattern matching approach is idiomatic Elixir and handles the three main cases appropriately:
- Git init command
- Unknown commands
- No arguments provided
This demonstrates good practices for new Elixir developers.
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses | ||
COPY --exclude=.git --exclude=README.md . /app | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix invalid COPY flags; use .dockerignore instead
Docker’s COPY
does not support --exclude
. To prevent cache misses on .git
and README.md
, create a .dockerignore
at the repo root listing those entries, then simplify the Dockerfile copy step:
- COPY --exclude=.git --exclude=README.md . /app
+ # Ensure .dockerignore excludes .git and README.md
+ COPY . /app
Also add a .dockerignore
alongside the Dockerfile:
.git
README.md
🧰 Tools
🪛 Hadolint (2.12.0)
[error] 10-10: invalid flag: --exclude
(DL1000)
Add Dockerfile, starter template, compiled starter, and solution for Elixir v1.17
Summary by CodeRabbit
New Features
Documentation
Chores