@@ -3,76 +3,49 @@ set shell := ["bash", "-cue"]
33comp_dir := justfile_directory ()
44root_dir := ` git rev-parse --show-toplevel `
55output_dir := root_dir / " .output"
6- flake_dir := " ./tools/nix"
6+ flake_dir := root_dir / " ./tools/nix"
7+
8+ mod maintenance " ./tools/just/maintenance.just"
79
810# Default target if you do not specify a target.
911default :
10- just --list
12+ just --list --unsorted
1113
1214# Create a new project from a template.
13- create template = " python" output_dir = " build":
14- just develop just create-impl " $@"
15-
16- # Create a new project from a template with all default answers.
17- create-default template = " python" output_dir = " build":
18- just develop just create-impl " $@" -l
19-
20- [private ]
21- create-impl * args :
22- #!/usr/bin/env bash
23- set -eu
24- source ./ tools/ ci/ general.sh
25-
26- template=" $1"
27- destination=" $(realpath " $2 " )" # Make absolute (resolve symlinks etc...)
28- args=(" ${@:3}" )
15+ create * args :
16+ just develop ./ tools/ scripts/ create.sh " $@"
2917
30- [[ " $template" =~ generic|rust|go|python ]] ||
31- ci::die " No such template '$template' to template"
32-
33- mkdir -p " $destination"
34- cd " {{ root_dir}} "
35-
36- ci::print_info " Rendering 'generic' template ... "
37- copier copy --trust " ${args[@]}" \
38- " src/generic" " $destination" \
39- - -data " project_language=$template" ||
40- ci::die " Could not apply template '$template'."
41- ci::print_info " Rendering 'generic' template completed."
18+ # Format the whole repository.
19+ format * args :
20+ " {{ root_dir}} /tools/scripts/setup-config-files.sh"
21+ nix run --accept-flake-config {{ flake_dir}} #treefmt -- "$@"
4222
43- if [ " $template" != " generic" ]; then
44- answer_file=" $destination/tools/configs/copier/answers/generic.yaml"
23+ # Setup the repository.
24+ setup * args :
25+ just maintenance::setup " $@"
4526
46- ci::print_info " Rendering '$template' template ..."
47- copier copy --trust " ${args[@]}" \
48- " src/$template" " $destination" \
49- - -data " project_authors=$(yq -r " .project_authors" " $answer_file" )" \
50- - -data " project_hosts=$(yq -r " .project_hosts" " $answer_file" )" \
51- - -data " project_version=$(yq -r " .project_version" " $answer_file" )" \
52- - -data " project_description=$(yq -r " .project_description" " $answer_file" )" \
53- - -data " project_url=$(yq -r " .project_url" " $answer_file" )" ||
54- ci::die " Could not apply template '$template'."
55- ci::print_info " Rendering '$template' template completed."
56- fi
27+ # Clean output folder.
28+ clean :
29+ rm -rf ./ .output
5730
58- if ! git -C " $destination" rev-parse --show-toplevel &>/ dev/ null; then
59- # If we are not inside a Git repo we need to init.
60- ci::print_info " Initializing Git repo '$destination'"
61- git -C " $destination" init || ci::die " Could not initialize Git repo."
62- fi
31+ # Test a template.
32+ test template = " python":
33+ just maintenance::test " {{ template}} "
6334
64- if [ " $(git -C " $destination" rev-parse --show-toplevel 2>/dev/null)" == " $destination" ]; then
65- # If we are inside the top level, add the files directly.
66- ci::print_info " Staging all files."
67- git -C " $destination" add . || ci::die " Could not stage all files."
68- fi
35+ # Test everything.
36+ test-all :
37+ just maintenance::test-all
6938
39+ # Show all packages configured in the Nix `flake.nix`.
40+ nix-list * args :
41+ cd tools/ nix && nix flake --no-pure-eval show
7042
7143# Enter the default Nix development shell.
7244develop * args :
7345 just nix-develop default " $@"
7446
7547# Enter the Nix development shell `$1` and execute the command `${@:2}`.
48+ [private ]
7649nix-develop * args :
7750 #!/usr/bin/env bash
7851 set -eu
@@ -82,131 +55,3 @@ nix-develop *args:
8255 nix develop --no-pure-eval --accept-flake-config \
8356 " {{ flake_dir}} #$shell" \
8457 - -command " ${args[@]}"
85-
86- # Format the whole repository.
87- format * args :
88- " {{ root_dir}} /tools/scripts/setup-config-files.sh"
89- nix run --accept-flake-config {{ flake_dir}} #treefmt -- "$@"
90-
91- # Setup the repository.
92- setup * args :
93- ./ tools/ scripts/ setup.sh
94-
95- # Test all templates.
96- test-all :
97- just test generic
98- just test python
99- just test rust
100-
101- # Test the code scaffolding.
102- test template = " python": setup
103- #!/usr/bin/env bash
104- set -eu
105- source " {{ root_dir}} /tools/ci/general.sh"
106-
107- ci::print_info " Running test '{{ template}} '"
108- ci::print_info " ======================"
109- build_dir=" {{ output_dir}} /{{ template}} "
110- cd " {{ root_dir}} " && rm -rf " $build_dir"
111-
112- uv run copier copy --trust -w \
113- - -data " project_language={{ template}} " \
114- - -defaults \
115- src/ generic \
116- " $build_dir"
117-
118- if [ " {{ template}} " != " generic" ]; then
119- answer_file=" $build_dir/tools/configs/copier/answers/generic.yaml"
120- uv run copier copy --trust -w \
121- - -data " project_authors=$(yq -r " .project_authors" " $answer_file" )" \
122- - -data " project_hosts=$(yq -r " .project_hosts" " $answer_file" )" \
123- - -data " project_version=$(yq -r " .project_version" " $answer_file" )" \
124- - -data " project_description=$(yq -r " .project_description" " $answer_file" )" \
125- - -data " project_url=$(yq -r " .project_url" " $answer_file" )" \
126- - -defaults \
127- " src/{{ template}} " \
128- " $build_dir"
129- fi
130-
131- # Test the templated output.
132- cd " ${build_dir}" &&
133- git init && git add . && \
134- git commit -a -m " init"
135-
136- just develop just setup
137- just develop just format
138- just develop just lint
139- just develop just build
140- just develop just run
141-
142- cp tools/ nix/ flake.lock " {{ root_dir}} /src/{{ template}} /tools/nix/flake.lock"
143- if [ " {{ template}} " == " python" ]; then
144- cp uv.lock " {{ root_dir}} /src/{{ template}} /uv.lock"
145- elif [ " {{ template}} " == " go" ]; then
146- cp go.work.sum " {{ root_dir}} /src/{{ template}} /go.work.sum"
147- cp src/ tool/ go.sum " {{ root_dir}} /src/{{ template}} /src/{{{{ package_name }}/go.sum"
148- elif [ " {{ template}} " == " rust" ]; then
149- cp Cargo.lock " {{ root_dir}} /src/{{ template}} /Cargo.lock"
150- fi
151-
152- git clean -df
153-
154- if ! git diff --exit-code --quiet . ; then
155- echo " We have changes in the build folder."
156- fi
157-
158- # Create and upload the code scaffolding.
159- upload-all template = " python":
160- just upload generic
161- just upload rust
162- just upload go
163- just upload python
164-
165- # Create and upload the code scaffolding.
166- upload template = " python": setup
167- #!/usr/bin/env bash
168- set -eu
169- source " {{ root_dir}} /tools/ci/general.sh"
170-
171- temp_dir=$(mktemp -d)
172- function cleanup() {
173- [ ! -d " $temp_dir" ] || {
174- ci::print_info " removing temp dir"
175- rm -rf " $temp_dir"
176- }
177- }
178- trap cleanup EXIT
179-
180- ci::print_info " Upload '{{ template}} '"
181- ci::print_info " ======================"
182- build_dir=" $temp_dir/{{ template}} "
183-
184- cd " {{ root_dir}} " && rm -rf " $build_dir" && mkdir -p " $build_dir"
185- just create-impl " {{ template}} " " $build_dir" -l -f
186-
187- cd " $build_dir"
188-
189- # Add WARNING
190- cat <(
191- echo " > [!WARNING]"
192- echo " > This is a demo rendering of the [\` {{ template}} \` template here](https://github.com/sdsc-ordes/repository-template#{{ template}} -template)"
193- echo
194- cat README.md
195- ) > README.md.mod && mv README.md.mod README.md
196-
197- git init &&
198- just format &&
199- git add . &&
200- git commit -a -m " init"
201-
202- git remote add origin \
203- " https://github.com/sdsc-ordes/repository-template-{{ template}} .git"
204-
205- branch=" main"
206- if ! ci::is_running; then
207- branch=" test"
208- git switch -c " $branch"
209- fi
210-
211- git checkout " $branch"
212- git push origin --force
0 commit comments