forked from cashapp/hermit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
autoversion: Support CSS selectors (cashapp#394)
autoversion currently only supports XPath for searching for versions in an HTML page. This works great, but CSS selectors are arguably more approachable for newcomers, and more widely understood. This change adds support for CSS selectors to autoversion using the github.com/andybalholm/cascadia package (BSD2 licensed) for matching them. To fit that in, this extracts the search logic into a new abstraction called htmlMatcher with an implementation for XPath and one for CSS. Following this change, you can do something like the following: ```hcl auto-version { html { url = "https://example.com" css = "div.version" } } ``` It is invalid to specify both `xpath` and `css` in the same auto-version block.
- Loading branch information
Showing
10 changed files
with
2,532 additions
and
30 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,45 @@ | ||
package autoversion | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/alecthomas/assert/v2" | ||
"github.com/cashapp/hermit/manifest" | ||
) | ||
|
||
func TestHTMLNoVersionsFound(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
htmlBlock *manifest.HTMLAutoVersionBlock | ||
}{ | ||
{ | ||
name: "XPath", | ||
htmlBlock: &manifest.HTMLAutoVersionBlock{ | ||
URL: "http://example.com", | ||
XPath: "/html/body/div", | ||
}, | ||
}, | ||
{ | ||
name: "CSS", | ||
htmlBlock: &manifest.HTMLAutoVersionBlock{ | ||
URL: "http://example.com", | ||
CSS: "body > div", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
_, err := htmlAutoVersion(&http.Client{ | ||
Transport: testHTTPClient{ | ||
path: "testdata/no_versions.html", | ||
}, | ||
}, &manifest.AutoVersionBlock{ | ||
HTML: tt.htmlBlock, | ||
}) | ||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "no versions matched") | ||
}) | ||
} | ||
} |
This file contains 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,19 @@ | ||
description = "Zig is a general-purpose programming language and toolchain for maintaining robust, optimal and reusable software" | ||
strip = 1 | ||
|
||
linux { | ||
source = "https://ziglang.org/download/${version}/zig-linux-${xarch}-${version}.tar.xz" | ||
} | ||
|
||
darwin { | ||
source = "https://ziglang.org/download/${version}/zig-macos-${xarch}-${version}.tar.xz" | ||
} | ||
|
||
version "0.10.0" "0.11.0" { | ||
auto-version { | ||
html { | ||
url = "https://ziglang.org/download/" | ||
css = "h2[id^=release-0]" | ||
} | ||
} | ||
} |
Oops, something went wrong.