Skip to content

Commit 908fc10

Browse files
committed
refactor: ♻️ move copier test to own file
1 parent 988c490 commit 908fc10

File tree

2 files changed

+86
-55
lines changed

2 files changed

+86
-55
lines changed

justfile

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@_checks: check-spelling check-commits
55
# Test Seedcase and non-Seedcase projects
6-
@_tests: (test "true") (test "false")
6+
@_tests: (test "true" "netlify") (test "false" "netlify") (test "true" "gh-pages") (test "false" "gh-pages")
77
@_builds: build-contributors build-website build-readme
88

99
# Run all build-related recipes in the justfile
@@ -47,60 +47,9 @@ check-commits:
4747
check-spelling:
4848
uvx typos
4949

50-
# Test and check that a Python package can be created from the template
51-
test is_seedcase_project:
52-
#!/usr/bin/env bash
53-
test_name="test-python-package"
54-
test_dir="$(pwd)/_temp/{{ is_seedcase_project }}/$test_name"
55-
template_dir="$(pwd)"
56-
commit=$(git rev-parse HEAD)
57-
rm -rf $test_dir
58-
# vcs-ref means the current commit/head, not a tag.
59-
uvx copier copy $template_dir $test_dir \
60-
--vcs-ref=$commit \
61-
--defaults \
62-
--trust \
63-
--data package_github_repo="first-last/repo" \
64-
--data is_seedcase_project={{ is_seedcase_project }} \
65-
--data author_given_name="First" \
66-
--data author_family_name="Last" \
67-
--data author_email="[email protected]" \
68-
--data review_team="@first-last/developers" \
69-
--data github_board_number=22
70-
# Run checks in the generated test Python package
71-
cd $test_dir
72-
git add .
73-
git commit -m "test: initial copy"
74-
just check-python check-spelling
75-
# TODO: Find some way to test the `update` command
76-
# Check that recopy works
77-
echo "Testing recopy command -----------"
78-
rm .cz.toml
79-
git add .
80-
git commit -m "test: preparing to recopy from the template"
81-
uvx copier recopy \
82-
--vcs-ref=$commit \
83-
--defaults \
84-
--overwrite \
85-
--trust
86-
# Check that copying onto an existing Python package works
87-
echo "Using the template in an existing package command -----------"
88-
rm .cz.toml .copier-answers.yml LICENSE.md
89-
git add .
90-
git commit -m "test: preparing to copy onto an existing package"
91-
uvx copier copy \
92-
$template_dir $test_dir \
93-
--vcs-ref=$commit \
94-
--defaults \
95-
--trust \
96-
--overwrite \
97-
--data package_github_repo="first-last/repo" \
98-
--data is_seedcase_project={{ is_seedcase_project }} \
99-
--data author_given_name="First" \
100-
--data author_family_name="Last" \
101-
--data author_email="[email protected]" \
102-
--data review_team="@first-last/developers" \
103-
--data github_board_number=22
50+
# Test that a Python package can be created from the template, with parameters for: `is_seedcase_project` (true or false) and `hosting_provider` (either "gh-pages" or "netlify")
51+
test is_seedcase_project="true" hosting_provider="netlify":
52+
sh ./test-template.sh {{ is_seedcase_project }} {{ hosting_provider }}
10453

10554
# Clean up any leftover and temporary build files
10655
cleanup:

test-template.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
3+
# Needs two arguments:
4+
#
5+
# 1. is_seedcase_project: true or false
6+
# 2. hosting_provider: e.g., "github", "gitlab", etc.
7+
8+
# Argument naming -----
9+
is_seedcase_project="${1}"
10+
hosting_provider="${2}"
11+
12+
if [ -z "$is_seedcase_project" ] || [ -z "$hosting_provider" ]; then
13+
echo "Usage: sh $0 <is_seedcase_project> <hosting_provider>"
14+
echo "Example: sh $0 true netlify"
15+
exit 1
16+
fi
17+
18+
# Set up variables and functions for the test -----
19+
test_name="test-package-$hosting_provider"
20+
test_dir="$(pwd)/_temp/$is_seedcase_project/$test_name"
21+
template_dir="$(pwd)"
22+
# Use the latest commit for the template
23+
commit=$(git rev-parse HEAD)
24+
25+
# Needs three arguments:
26+
#
27+
# 1. Template directory
28+
# 2. Destination directory
29+
# 3. VCS ref (commit, branch, tag, etc.)
30+
copy () {
31+
# vcs-ref means the current commit/head, not a tag.
32+
uvx copier copy $1 $2 \
33+
--vcs-ref=$3 \
34+
--defaults \
35+
--data is_seedcase_project=$is_seedcase_project \
36+
--data github_user="first-last" \
37+
--data hosting_provider=$hosting_provider \
38+
--data author_given_name="First" \
39+
--data author_family_name="Last" \
40+
--data author_email="[email protected]" \
41+
--data review_team="@first-last/developers" \
42+
--data github_board_number=22 \
43+
--overwrite \
44+
--skip-tasks \
45+
--trust
46+
}
47+
48+
# Pre-test setup -----
49+
# Remove the leftover directory from previous runs
50+
rm -rf $test_dir
51+
mkdir -p $test_dir
52+
53+
# Check initial creation -----
54+
# TODO: Find some way to test the `update` command
55+
# Any step that fails will exit the script with an error and not continue
56+
echo "Testing copy for new projects when: 'is_seedcase_project'='$is_seedcase_project', 'hosting_provider'='$hosting_provider' -----------"
57+
(
58+
cd $test_dir &&
59+
copy $template_dir $test_dir $commit &&
60+
git init -b main &&
61+
git add . &&
62+
git commit --quiet -m "test: initial copy" &&
63+
# Check that recopy works -----
64+
echo "Testing recopy when: 'is_seedcase_project'='$$is_seedcase_project', 'hosting_provider'='$hosting_provider' -----------" &&
65+
rm .cz.toml &&
66+
git add . &&
67+
git commit --quiet -m "test: preparing to recopy from the template" &&
68+
uvx copier recopy \
69+
--vcs-ref=$commit \
70+
--defaults \
71+
--overwrite \
72+
--skip-tasks \
73+
--trust &&
74+
# Check that copying onto an existing package works -----
75+
echo "Testing copy in existing projects when: 'is_seedcase_project'='$is_seedcase_project', 'hosting_provider'='$hosting_provider' -----------" &&
76+
rm .cz.toml .copier-answers.yml &&
77+
git add . &&
78+
git commit --quiet -m "test: preparing to copy onto an existing package" &&
79+
copy $template_dir $test_dir $commit #&&
80+
# Checks and builds -----
81+
# just run-all
82+
)

0 commit comments

Comments
 (0)