Compare commits

...
37 Commits
Author SHA1 Message Date
github-actions[bot]andBot 1a5ca78da5 Update package dependencies + tidy (#41)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2024-03-06 12:00:44 +00:00
Ian Davis 5147d5f6cd Updated github workflows 2024-02-21 10:52:50 +00:00
github-actions[bot]andBot 1971468038 Update package dependencies + tidy (#40)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2024-02-14 09:46:47 +00:00
github-actions[bot]andBot 0d98c9d29d Update package dependencies + tidy (#39)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2024-01-10 10:04:51 +00:00
github-actions[bot]andBot fba0473ccd Update package dependencies + tidy (#38)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2023-11-29 09:04:00 +00:00
Ian Davis d3f130af1c Updated github workflows 2023-11-25 13:56:48 +00:00
Ian Davis f953915e15 Updated github workflows 2023-11-25 13:51:42 +00:00
Ian Davis fc1ff57fc8 Updated github workflows 2023-11-25 13:47:07 +00:00
Ian Davis feb7d5cf4b Updated github workflows 2023-11-25 13:39:16 +00:00
Ian Davis 571566e249 Update to go1.21 2023-11-25 13:03:07 +00:00
Ian Davis edc9e85854 Update to go1.21 2023-11-25 13:00:28 +00:00
Ian Davis 3e5cb04a71 Updated github workflows 2023-11-25 12:21:48 +00:00
Ian Davis aaacbab37c Updated github workflows 2023-11-24 14:58:53 +00:00
github-actions[bot]andBot 64ebdfdbe4 Update package dependencies + tidy (#30)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2023-10-04 10:01:48 +01:00
github-actions[bot]andBot 74e31628d0 Update package dependencies + tidy (#18)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2023-06-27 14:42:42 +01:00
Ian Davis ed149868fa Updated github workflows 2023-05-29 15:29:04 +01:00
github-actions[bot]andBot 3e11d3b1a6 Update package dependencies + tidy (#16)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2023-05-28 20:18:28 +01:00
Ian Davis 1c3e758e66 Updated github workflows 2023-03-03 11:01:57 +00:00
Ian Davis 6e2c7f6f56 Updated github workflows 2023-03-03 10:59:32 +00:00
Ian Davis 6b71cfa931 Updated github workflows 2023-03-03 10:43:10 +00:00
Ian Davis 3dad76a6cc Updated github workflows 2023-03-03 10:40:09 +00:00
Ian Davis a9974e706d Updated github workflows 2023-02-08 12:43:49 +00:00
github-actions[bot]andBot 99ed0dc05e Update package dependencies + tidy (#14)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2023-01-09 09:54:16 +00:00
github-actions[bot]andBot 8dc01b9156 Update package dependencies + tidy (#13)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2022-12-15 09:49:49 +00:00
github-actions[bot]andBot bc8eb4cda6 Update package dependencies + tidy (#12)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2022-11-14 11:18:22 +00:00
github-actions[bot]andBot fe0918b88f Update package dependencies + tidy (#11)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2022-10-24 15:27:14 +01:00
github-actions[bot]andBot 89fa0b8601 Update package dependencies + tidy (#10)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2022-10-17 15:12:47 +01:00
github-actions[bot]andBot 046856f5eb Update package dependencies + tidy (#9)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2022-10-10 10:18:43 +01:00
github-actions[bot]andBot cae8f6da0a Update package dependencies + tidy (#8)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2022-10-03 11:27:47 +01:00
github-actions[bot]andBot db34356431 Update package dependencies + tidy (#7)
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.

Co-authored-by: Bot <bot@iandavis.com>
2022-09-26 14:14:40 +01:00
Ian Davis 09593b7a92 Updated github workflows 2022-09-26 12:56:01 +01:00
Ian Davis 8e5263131f Updated github workflows 2022-09-21 16:32:42 +01:00
Ian Davis 6eca7f6e5c Updated github workflows 2022-09-20 13:36:41 +01:00
Ian Davis 52a051450d Updated github workflows 2022-09-20 13:32:43 +01:00
Ian Davis f9a084323d Merge pull request #6 from dnesting/master
Ensure itemscope always starts a new item
2020-10-11 17:59:04 +01:00
David M. Nesting ca93c08d53 ensure itemscope always starts a new item 2020-10-11 12:30:55 -04:00
David M. Nesting a5d3d8ae37 adding test for inner itemscoped item 2020-10-07 15:43:29 -04:00
8 changed files with 257 additions and 69 deletions

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
on:
workflow_dispatch:
name: Update package dependencies
jobs:
dep_update:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Update minor and patch-level dependencies
run: go get -t -u ./...
- name: Tidy
run: go mod tidy
- name: Create pull request
uses: peter-evans/create-pull-request@v4
with:
title: "Update package dependencies + tidy"
body: |
This is a change initiated automatically on a weekly basis by a
GitHub Action that updates the projects dependencies to their latest
minor and patch-level versions. This lets us stay up to date
incrementally so that updates are less effort to get merged compared
to large monolithic updates, and gets us security updates more
expediently.
If the build passes, you are probably A-OK to merge and deploy this.
If not, try to dig into what's not working and see if you can fix it
so that the dep train stays on its rails.
Note that although minor/patch level changes are handled
automatically, notably major version changes like you'd find in
stripe-go are not and those upgrades need to be performed manually.
That should theoretically not be a problem if fixes are backported
to all previous majors, but in practice they are often not, so it's
worthwhile to occasionally look for new majors and integrate them.
branch: "autodep"
branch-suffix: "timestamp"
commit-message: |
Update package dependencies + tidy
Weekly update to the project's package dependencies initiated by an
automatic GitHub Action running on cron. Keeps upgrades less of a
monolithic task and lets security-related patches trickle in more
quickly.
author: "Bot <bot@iandavis.com>"
committer: "Bot <bot@iandavis.com>"
delete-branch: true
draft: true
reviewers: |
iand
assignees: |
iand
+80
View File
@@ -0,0 +1,80 @@
on:
workflow_dispatch:
pull_request:
types: [opened, reopened, ready_for_review, synchronize]
push:
branches:
- main
- master
name: Run tests
jobs:
check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Get StaticCheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Gomod
run: |
go mod tidy
if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then
echo "go.sum was added by go mod tidy"
exit 1
fi
git diff --exit-code -- go.sum go.mod
- name: Gofmt
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: |
out=$(gofmt -s -l .)
if [[ -n "$out" ]]; then
echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}'
exit 1
fi
- name: Vet
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: go vet ./...
- name: StaticCheck
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: staticcheck ./...
test:
strategy:
matrix:
os: ["ubuntu", "windows", "macos"]
runs-on: ${{ matrix.os }}-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Test
run: go test ./...
- name: Test 32 bit
if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX.
env:
GOARCH: 386
run: go test ./...
- name: Test with race detector
if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow
run: go test -race ./...
+24
View File
@@ -0,0 +1,24 @@
name: Bump version
on:
workflow_dispatch:
workflow_run:
workflows: ["Run tests"]
types:
- completed
branches:
- main
- master
jobs:
version:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
-20
View File
@@ -1,20 +0,0 @@
language: go
go:
- "1.14.x"
- "1.15.x"
- tip
matrix:
allow_failures:
- go: tip
fast_finish: true
before_script:
- GO_FILES=$(find . -iname '*.go' | grep -v /vendor/)
- PKGS=$(go list ./... | grep -v /vendor/)
script:
- test -z $(gofmt -s -l $GO_FILES)
- go test -v -race $PKGS
- go vet $PKGS
+2 -2
View File
@@ -1,5 +1,5 @@
module github.com/iand/microdata
go 1.16
go 1.21.4
require golang.org/x/net v0.0.0-20200904194848-62affa334b73
require golang.org/x/net v0.22.0
+2 -9
View File
@@ -1,9 +1,2 @@
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20200904194848-62affa334b73 h1:MXfv8rhZWmFeqX3GNZRsd6vOLoaCHjYEX3qkRo3YBUA=
golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
+19 -37
View File
@@ -121,8 +121,18 @@ func (p *Parser) Parse() (*Microdata, error) {
})
for _, node := range topLevelItemNodes {
item := NewItem()
p.data.Items = append(p.data.Items, item)
p.data.Items = append(p.data.Items, p.readItem(nil, node))
}
return p.data, nil
}
func (p *Parser) readItem(item *Item, node *html.Node) *Item {
var parent *Item
if _, exists := getAttr("itemscope", node); exists {
parent, item = item, NewItem()
if itemtypes, exists := getAttr("itemtype", node); exists {
for _, itemtype := range strings.Split(strings.TrimSpace(itemtypes), " ") {
itemtype = strings.TrimSpace(itemtype)
@@ -143,53 +153,24 @@ func (p *Parser) Parse() (*Microdata, error) {
itemref = strings.TrimSpace(itemref)
if refnode, exists := p.identifiedNodes[itemref]; exists {
if refnode != node {
p.readItem(item, refnode)
}
}
}
for child := node.FirstChild; child != nil; {
p.readItem(item, child)
child = child.NextSibling
}
}
return p.data, nil
}
func (p *Parser) readItem(item *Item, node *html.Node) {
if itemprop, exists := getAttr("itemprop", node); exists {
if _, exists := getAttr("itemscope", node); exists {
subitem := NewItem()
if itemrefs, exists := getAttr("itemref", node); exists {
for _, itemref := range strings.Split(strings.TrimSpace(itemrefs), " ") {
itemref = strings.TrimSpace(itemref)
if refnode, exists := p.identifiedNodes[itemref]; exists {
if refnode != node {
p.readItem(subitem, refnode)
}
}
}
}
for child := node.FirstChild; child != nil; {
p.readItem(subitem, child)
child = child.NextSibling
}
if parent != nil {
// an itemprop on an itemscope has value of the item created by the itemscope
for _, propertyName := range strings.Split(strings.TrimSpace(itemprop), " ") {
propertyName = strings.TrimSpace(propertyName)
if propertyName != "" {
item.AddItem(propertyName, subitem)
parent.AddItem(propertyName, item)
}
}
return
}
} else {
var propertyValue string
switch node.DataAtom {
@@ -241,7 +222,7 @@ func (p *Parser) readItem(item *Item, node *html.Node) {
}
}
}
}
}
for child := node.FirstChild; child != nil; {
@@ -249,6 +230,7 @@ func (p *Parser) readItem(item *Item, node *html.Node) {
child = child.NextSibling
}
return item
}
func getAttr(name string, node *html.Node) (string, bool) {
+68 -1
View File
@@ -583,8 +583,9 @@ func TestSkipSelfReferencingItemref(t *testing.T) {
actual := ParseData(html, t)
child := NewItem()
child.AddString("title", "Foo")
child.AddType("http://data-vocabulary.org/Breadcrumb")
child.AddString("url", "http://example.com/foo/bar")
child.AddString("title", "Foo")
item := NewItem()
item.AddType("http://schema.org/WebPage")
@@ -597,3 +598,69 @@ func TestSkipSelfReferencingItemref(t *testing.T) {
t.Errorf("Expecting %v but got %v", expected, actual)
}
}
// This test validates that properties within an itemscope'd element remain
// with that contained item even if it is not, via itemprop, made an explicit child
// of its container item.
func TestPropertiesInContainedItem(t *testing.T) {
html := `
<body itemscope itemtype="http://schema.org/WebPage">
<meta itemprop="foo" content="foo value">
<div itemscope itemtype="http://schema.org/Person">
<meta itemprop="bar" content="bar value">
</div>
<div itemscope itemtype="http://schema.org/Person" itemprop="author">
<meta itemprop="baz" content="baz value">
</div>
</body>`
actual := ParseData(html, t)
// There should be two top-level items: WebPage and the Person that isn't an author.
if len(actual.Items) != 2 {
t.Fatalf("expected 2 top-level items, got %d", len(actual.Items))
}
outer := actual.Items[0]
inner := actual.Items[1]
// The first item should be a WebPage. The properties in its contained items should
// not be properties of the containing item.
if len(outer.Types) != 1 || outer.Types[0] != "http://schema.org/WebPage" {
t.Fatalf("expected outer to be http://schema.org/WebPage, got %v", outer.Types)
}
if _, present := outer.Properties["bar"]; present {
t.Errorf("outer should not have a 'bar' property, got %v", outer.Properties["bar"])
}
if _, present := outer.Properties["baz"]; present {
t.Errorf("outer should not have a 'baz' property, got %v", outer.Properties["baz"])
}
// The second item should be the non-author child element of outer. Since there is
// no itemprop attribute, it's not a child *item* of outer but it should stand as its
// own item.
if len(inner.Types) != 1 || inner.Types[0] != "http://schema.org/Person" {
t.Fatalf("expected inner to be http://schema.org/Person, got %v", inner.Types)
}
if _, present := inner.Properties["bar"]; !present {
t.Errorf("inner should have a 'bar' property")
}
// The third item is the author, which should be a child item (via the 'author' itemprop)
// of outer. It, too, should have its own discrete type and property.
if list := outer.Properties["author"]; len(list) == 1 {
if author, ok := list[0].(*Item); ok {
if len(author.Types) != 1 || author.Types[0] != "http://schema.org/Person" {
t.Fatalf("expected author to be http://schema.org/Person, got %v", author.Types)
}
if _, present := author.Properties["baz"]; !present {
t.Errorf("inner should have a 'baz' property")
}
} else {
t.Errorf("expected author item, got %v", list)
}
} else {
t.Errorf("expected outer to have a child of author, got %v", outer.Properties["author"])
}
}