Skip to content

Commit 600f620

Browse files
committed
For github: URLs any *.yaml file can be a redirect or symlink
Signed-off-by: Jan Dubois <jan.dubois@suse.com>
1 parent e14ee7b commit 600f620

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

hack/bats/tests/url-github.bats

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ load "../helpers/load"
2020
# │ └── .lima.yaml -> github:jandubois//loop/
2121
# ├── docs
2222
# │ └── .lima.yaml -> ../templates/demo.yaml
23+
# ├── example.yaml -> templates/demo.yaml
2324
# ├── invalid
2425
# │ ├── org
2526
# │ │ └── .lima.yaml -> github:lima-vm
@@ -35,9 +36,12 @@ load "../helpers/load"
3536
# └── .lima.yaml "{}"
3637
#
3738
# Both the `main` branch and the `v0.0.0` tag have this layout.
38-
39+
#
3940
# All these URLs should redirect to the same template URL (either on "main" or at "v0.0.0"):
4041
# "https://raw.githubusercontent.com/jandubois/jandubois/${tag}/templates/demo.yaml"
42+
#
43+
# Additional tests rely on jandubois/lima existing and containing the v1.2.1 tag.
44+
4145
URLS=(
4246
github:jandubois/jandubois/templates/demo.yaml@main
4347
github:jandubois/jandubois/templates/demo.yaml
@@ -54,6 +58,10 @@ URLS=(
5458
github:jandubois/
5559
github:jandubois@v0.0.0
5660
github:jandubois
61+
github:jandubois/jandubois/example.yaml
62+
github:jandubois/jandubois/example@main
63+
github:jandubois//example.yaml@v0.0.0
64+
github:jandubois//example
5765
github:jandubois/jandubois/docs/.lima.yaml@main
5866
github:jandubois/jandubois/docs/.lima.yaml
5967
github:jandubois/jandubois/docs/.lima
@@ -96,11 +104,12 @@ done
96104
}
97105

98106
@test 'hidden files without an extension get a .yaml extension' {
99-
url -0 'github:jandubois//test/.hidden'
100-
assert_output 'https://raw.githubusercontent.com/jandubois/jandubois/main/test/.hidden.yaml'
107+
url -1 'github:jandubois//test/.hidden'
108+
assert_fatal 'file "https://raw.githubusercontent.com/jandubois/jandubois/main/test/.hidden.yaml" not found or inaccessible: status 404'
101109
}
102110

103111
@test 'files that have an extension do not get a .yaml extension' {
112+
# This command doesn't fail because only *.yaml files are checked for redirects/symlinks, and therefore fail right away if they don't exist.
104113
url -0 'github:jandubois//test/.script.sh'
105114
assert_output 'https://raw.githubusercontent.com/jandubois/jandubois/main/test/.script.sh'
106115
}

pkg/limatmpl/github.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ func transformGitHubURL(ctx context.Context, input string) (string, error) {
6666
}
6767
}
6868

69-
// If filename is .lima.yaml, check if it's a symlink/redirect to another file
70-
if path.Base(filePath) == defaultFilename {
69+
// If filename has a .yaml/.yml extension, check if it's a symlink/redirect to another file
70+
ext := strings.ToLower(path.Ext(filePath))
71+
if ext == ".yaml" || ext == ".yml" {
7172
return resolveGitHubSymlink(ctx, org, repo, branch, filePath, origBranch)
7273
}
7374
return githubUserContentURL(org, repo, branch, filePath), nil

0 commit comments

Comments
 (0)