-
Notifications
You must be signed in to change notification settings - Fork 21
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
Open
mikowitz
wants to merge
1
commit into
codecrafters-io:main
Choose a base branch
from
mikowitz:mikowitz/add-elixir
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add elixir 1.17 #144
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
# | ||
# This script is used to compile your program on CodeCrafters | ||
# | ||
# This runs before .codecrafters/run.sh | ||
# | ||
# Learn more: https://codecrafters.io/program-interface | ||
|
||
set -e # Exit on failure | ||
|
||
mix escript.build | ||
mv codecrafters_git /tmp/codecrafters-build-git-elixir |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
# | ||
# This script is used to run your program on CodeCrafters | ||
# | ||
# This runs after .codecrafters/compile.sh | ||
# | ||
# Learn more: https://codecrafters.io/program-interface | ||
|
||
set -e # Exit on failure | ||
|
||
exec /tmp/codecrafters-build-git-elixir "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Ignore the compiled binary | ||
/codecrafters_git | ||
|
||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
app-*.tar | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
 | ||
|
||
This is a starting point for Elixir solutions to the | ||
["Build Your Own Git" Challenge](https://codecrafters.io/challenges/git). | ||
|
||
In this challenge, you'll build a small Git implementation that's capable of | ||
initializing a repository, creating commits and cloning a public repository. | ||
Along the way we'll learn about the `.git` directory, Git objects (blobs, | ||
commits, trees etc.), Git's transfer protocols and more. | ||
|
||
**Note**: If you're viewing this repo on GitHub, head over to | ||
[codecrafters.io](https://codecrafters.io) to try the challenge. | ||
|
||
# Passing the first stage | ||
|
||
The entry point for your Git implementation is in `lib/main.ex`. Study and | ||
uncomment the relevant code, and push your changes to pass the first stage: | ||
|
||
```sh | ||
git commit -am "pass 1st stage" # any msg | ||
git push origin master | ||
``` | ||
|
||
That's all! | ||
|
||
# Stage 2 & beyond | ||
|
||
Note: This section is for stages 2 and beyond. | ||
|
||
1. Ensure you have `mix` installed locally | ||
1. Run `./your_program.sh` to run your Git implementation, which is implemented | ||
in `lib/main.ex`. | ||
1. Commit your changes and run `git push origin master` to submit your solution | ||
to CodeCrafters. Test output will be streamed to your terminal. | ||
|
||
# Testing locally | ||
|
||
The `your_program.sh` script is expected to operate on the `.git` folder inside | ||
the current working directory. If you're running this inside the root of this | ||
repository, you might end up accidentally damaging your repository's `.git` | ||
folder. | ||
|
||
We suggest executing `your_program.sh` in a different folder when testing | ||
locally. For example: | ||
|
||
```sh | ||
mkdir -p /tmp/testing && cd /tmp/testing | ||
/path/to/your/repo/your_program.sh init | ||
``` | ||
|
||
To make this easier to type out, you could add a | ||
[shell alias](https://shapeshed.com/unix-alias/): | ||
|
||
```sh | ||
alias mygit=/path/to/your/repo/your_program.sh | ||
|
||
mkdir -p /tmp/testing && cd /tmp/testing | ||
mygit init | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Set this to true if you want debug logs. | ||
# | ||
# These can be VERY verbose, so we suggest turning them off | ||
# unless you really need them. | ||
debug: false | ||
|
||
# Use this to change the Elixir version used to run your code | ||
# on Codecrafters. | ||
# | ||
# Available versions: elixir-1.17 | ||
language_pack: elixir-1.17 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule CLI do | ||
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!") | ||
|
||
# Uncomment this block to pass the first stage | ||
# | ||
# case argv do | ||
# ["init" | _] -> | ||
# :ok = File.mkdir(".git") | ||
# :ok = File.mkdir(".git/objects") | ||
# :ok = File.mkdir(".git/refs") | ||
# :ok = File.write(".git/HEAD", "ref: refs/heads/main\n") | ||
# IO.puts("Initialized git directory") | ||
# | ||
# [command | _] -> | ||
# IO.puts("Unknown command: #{command}") | ||
# System.halt(1) | ||
# | ||
# [] -> | ||
# IO.puts("Usage: your_script.sh <command> <args>") | ||
# System.halt(1) | ||
# end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule App.MixProject do | ||
# NOTE: You do not need to change anything in this file. | ||
use Mix.Project | ||
|
||
def project do | ||
[ | ||
app: :codecrafters_git, | ||
version: "1.0.0", | ||
elixir: "~> 1.17", | ||
start_permanent: Mix.env() == :prod, | ||
deps: deps(), | ||
escript: [main_module: CLI] | ||
] | ||
end | ||
|
||
# Run "mix help compile.app" to learn about applications. | ||
def application do | ||
[ | ||
extra_applications: [:logger] | ||
] | ||
end | ||
|
||
# Run "mix help deps" to learn about dependencies. | ||
defp deps do | ||
[ | ||
# {:dep_from_hexpm, "~> 0.3.0"}, | ||
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} | ||
] | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/sh | ||
# | ||
# Use this script to run your program LOCALLY. | ||
# | ||
# Note: Changing this script WILL NOT affect how CodeCrafters runs your program. | ||
# | ||
# Learn more: https://codecrafters.io/program-interface | ||
|
||
set -e # Exit early if any commands fail | ||
|
||
# Copied from .codecrafters/compile.sh | ||
# | ||
# - Edit this to change how your program compiles locally | ||
# - Edit .codecrafters/compile.sh to change how your program compiles remotely | ||
( | ||
cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory | ||
mix escript.build | ||
mv codecrafters_git /tmp/codecrafters-build-git-elixir | ||
) | ||
|
||
# Copied from .codecrafters/run.sh | ||
# | ||
# - Edit this to change how your program runs locally | ||
# - Edit .codecrafters/run.sh to change how your program runs remotely | ||
exec /tmp/codecrafters-build-git-elixir "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# syntax=docker/dockerfile:1.7-labs | ||
FROM elixir:1.17.2-alpine | ||
|
||
# Ensures the container is re-built if dependency files change | ||
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="mix.exs" | ||
|
||
WORKDIR /app | ||
|
||
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses | ||
COPY --exclude=.git --exclude=README.md . /app | ||
|
||
# Install & cache deps | ||
RUN .codecrafters/compile.sh | ||
|
||
# If _build directory exists, move it to /app-cached | ||
RUN mkdir -p /app-cached | ||
RUN if [ -d "/app/_build" ]; then mv /app/_build /app-cached; fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
# | ||
# This script is used to compile your program on CodeCrafters | ||
# | ||
# This runs before .codecrafters/run.sh | ||
# | ||
# Learn more: https://codecrafters.io/program-interface | ||
|
||
set -e # Exit on failure | ||
|
||
mix escript.build | ||
mv codecrafters_git /tmp/codecrafters-build-git-elixir |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
# | ||
# This script is used to run your program on CodeCrafters | ||
# | ||
# This runs after .codecrafters/compile.sh | ||
# | ||
# Learn more: https://codecrafters.io/program-interface | ||
|
||
set -e # Exit on failure | ||
|
||
exec /tmp/codecrafters-build-git-elixir "$@" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Used by "mix format" | ||
[ | ||
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Ignore the compiled binary | ||
/codecrafters_git | ||
|
||
# The directory Mix will write compiled artifacts to. | ||
/_build/ | ||
|
||
# If you run "mix test --cover", coverage assets end up here. | ||
/cover/ | ||
|
||
# The directory Mix downloads your dependencies sources to. | ||
/deps/ | ||
|
||
# Where third-party dependencies like ExDoc output generated docs. | ||
/doc/ | ||
|
||
# Ignore .fetch files in case you like to edit your project deps locally. | ||
/.fetch | ||
|
||
# If the VM crashes, it generates a dump, let's ignore it too. | ||
erl_crash.dump | ||
|
||
# Also ignore archive artifacts (built via "mix archive.build"). | ||
*.ez | ||
|
||
# Ignore package tarball (built via "mix hex.build"). | ||
app-*.tar | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
 | ||
|
||
This is a starting point for Elixir solutions to the | ||
["Build Your Own Git" Challenge](https://codecrafters.io/challenges/git). | ||
|
||
In this challenge, you'll build a small Git implementation that's capable of | ||
initializing a repository, creating commits and cloning a public repository. | ||
Along the way we'll learn about the `.git` directory, Git objects (blobs, | ||
commits, trees etc.), Git's transfer protocols and more. | ||
|
||
**Note**: If you're viewing this repo on GitHub, head over to | ||
[codecrafters.io](https://codecrafters.io) to try the challenge. | ||
|
||
# Passing the first stage | ||
|
||
The entry point for your Git implementation is in `lib/main.ex`. Study and | ||
uncomment the relevant code, and push your changes to pass the first stage: | ||
|
||
```sh | ||
git commit -am "pass 1st stage" # any msg | ||
git push origin master | ||
``` | ||
|
||
That's all! | ||
|
||
# Stage 2 & beyond | ||
|
||
Note: This section is for stages 2 and beyond. | ||
|
||
1. Ensure you have `mix` installed locally | ||
1. Run `./your_program.sh` to run your Git implementation, which is implemented | ||
in `lib/main.ex`. | ||
1. Commit your changes and run `git push origin master` to submit your solution | ||
to CodeCrafters. Test output will be streamed to your terminal. | ||
|
||
# Testing locally | ||
|
||
The `your_program.sh` script is expected to operate on the `.git` folder inside | ||
the current working directory. If you're running this inside the root of this | ||
repository, you might end up accidentally damaging your repository's `.git` | ||
folder. | ||
|
||
We suggest executing `your_program.sh` in a different folder when testing | ||
locally. For example: | ||
|
||
```sh | ||
mkdir -p /tmp/testing && cd /tmp/testing | ||
/path/to/your/repo/your_program.sh init | ||
``` | ||
|
||
To make this easier to type out, you could add a | ||
[shell alias](https://shapeshed.com/unix-alias/): | ||
|
||
```sh | ||
alias mygit=/path/to/your/repo/your_program.sh | ||
|
||
mkdir -p /tmp/testing && cd /tmp/testing | ||
mygit init | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Set this to true if you want debug logs. | ||
# | ||
# These can be VERY verbose, so we suggest turning them off | ||
# unless you really need them. | ||
debug: false | ||
|
||
# Use this to change the Elixir version used to run your code | ||
# on Codecrafters. | ||
# | ||
# Available versions: elixir-1.17 | ||
language_pack: elixir-1.17 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule CLI do | ||
def main(argv) do | ||
case argv do | ||
["init" | _] -> | ||
:ok = File.mkdir(".git") | ||
:ok = File.mkdir(".git/objects") | ||
:ok = File.mkdir(".git/refs") | ||
:ok = File.write(".git/HEAD", "ref: refs/heads/main\n") | ||
IO.puts("Initialized git directory") | ||
|
||
[command | _] -> | ||
IO.puts("Unknown command: #{command}") | ||
System.halt(1) | ||
|
||
[] -> | ||
IO.puts("Usage: your_script.sh <command> <args>") | ||
System.halt(1) | ||
end | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
andREADME.md
, create a.dockerignore
at the repo root listing those entries, then simplify the Dockerfile copy step:Also add a
.dockerignore
alongside the Dockerfile:🧰 Tools
🪛 Hadolint (2.12.0)
[error] 10-10: invalid flag: --exclude
(DL1000)