From 342786f18c50111b1b75466bb6cc112ee99d6245 Mon Sep 17 00:00:00 2001 From: duncdrum Date: Sun, 7 Apr 2024 15:05:01 +0200 Subject: [PATCH 1/3] feat(lint): empty type --- .github/dependabot.yml | 4 +++- .releaserc | 15 ++++++++++++--- README.md | 2 +- commitlint.config.cjs | 8 ++++++++ commitlint.config.js | 1 - 5 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 commitlint.config.cjs delete mode 100644 commitlint.config.js diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0056901..1418c27 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,4 +3,6 @@ updates: - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "weekly" \ No newline at end of file + interval: "weekly" + commit-message: + prefix: "chore(gha):" \ No newline at end of file diff --git a/.releaserc b/.releaserc index c4712df..23ab251 100644 --- a/.releaserc +++ b/.releaserc @@ -2,7 +2,16 @@ "branches": ["master"], "plugins": [ "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits", + "releaseRules": [ + { "type": "", "release": "patch" } + ] + }, "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits" + }, ["@semantic-release/exec", { "prepareCmd": "ant -Dapp.version=${nextRelease.version}" }], @@ -13,9 +22,9 @@ ["@semantic-release/github", { "assets": [ { - "path": "build/twitter-*.xar", - "name": "twitter-${nextRelease.version}.xar", - "label": "Expath package (twitter-${nextRelease.version}.xar)" + "path": "build/twitter.xar", + "name": "twitter.xar", + "label": "Expath package (twitter.xar)" } ] }] diff --git a/README.md b/README.md index d11d43b..117524a 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Archive of tweets by the Office of the Historian's official Twitter account, [@H Releases for this data package are automated. Any commit to the `master`` branch will trigger the release automation. -All commit message must conform to [Angular Commit Message Conventions](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#-git-commit-guidelines) to determine semantic versioning of releases, please adhere to these conventions, like so: +All commit message must conform to [Conventional Commit Messages](https://www.conventionalcommits.org/en/v1.0.0/) to determine semantic versioning of releases, please adhere to these conventions, like so: | Commit message | Release type | |-----------------|--------------| diff --git a/commitlint.config.cjs b/commitlint.config.cjs new file mode 100644 index 0000000..a3155c1 --- /dev/null +++ b/commitlint.config.cjs @@ -0,0 +1,8 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'body-max-line-length': [1, 'always', 200], + 'type-empty': [1, 'never'], + 'subject-empty': [1, 'never'] + } +} \ No newline at end of file diff --git a/commitlint.config.js b/commitlint.config.js deleted file mode 100644 index bb9a3e8..0000000 --- a/commitlint.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = {extends: ['@commitlint/config-angular']} From 310406fb53a0b124d6b48f4e2dd62d61bbb4cd37 Mon Sep 17 00:00:00 2001 From: duncdrum Date: Sun, 7 Apr 2024 16:07:41 +0200 Subject: [PATCH 2/3] fix(ci): add shared-resources close #14 --- .github/workflows/build.yml | 6 +++++- expath-pkg.xml.tmpl | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9c09d30..3ae542e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,7 +36,7 @@ jobs: xmllint --noout \ $(find . -type f -name '*.xml') - # Build + # Build - name: Build Expath Package uses: actions/setup-java@v4 with: @@ -45,6 +45,10 @@ jobs: - run: ant # Install + - name: add shared-resources + run: wget https://exist-db.org/exist/apps/public-repo/public/shared-resources-0.9.1.xar > 000.xar + working-directory: build + - name: Start exist-ci containers run: | docker run -dit -p 8080:8080 -v ${{ github.workspace }}/build:/exist/autodeploy \ diff --git a/expath-pkg.xml.tmpl b/expath-pkg.xml.tmpl index a2f0b1b..46163c5 100644 --- a/expath-pkg.xml.tmpl +++ b/expath-pkg.xml.tmpl @@ -1,4 +1,5 @@ @title@ + From 35cdb36299121641a4e18428e160616001f98f9c Mon Sep 17 00:00:00 2001 From: duncdrum Date: Sun, 7 Apr 2024 22:43:15 +0200 Subject: [PATCH 3/3] fix(install): expath deps add dbutil module declare undeclared deps skip test for error see #17 close #14 --- .github/workflows/build.yml | 4 +-- expath-pkg.xml.tmpl | 2 +- modules/dbutil.xqm | 66 +++++++++++++++++++++++++++++++++++++ post-install.xql | 5 +-- pre-install.xql | 6 ++-- repo.xml.tmpl | 3 +- tests/bats/smoke-test.bats | 6 ++-- 7 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 modules/dbutil.xqm diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3ae542e..6327bef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,8 +45,8 @@ jobs: - run: ant # Install - - name: add shared-resources - run: wget https://exist-db.org/exist/apps/public-repo/public/shared-resources-0.9.1.xar > 000.xar + - name: add functx + run: wget https://exist-db.org/exist/apps/public-repo/public/functx-1.0.1.xar -O 000.xar working-directory: build - name: Start exist-ci containers diff --git a/expath-pkg.xml.tmpl b/expath-pkg.xml.tmpl index 46163c5..a7a9466 100644 --- a/expath-pkg.xml.tmpl +++ b/expath-pkg.xml.tmpl @@ -1,5 +1,5 @@ @title@ - + diff --git a/modules/dbutil.xqm b/modules/dbutil.xqm new file mode 100644 index 0000000..eb5bc72 --- /dev/null +++ b/modules/dbutil.xqm @@ -0,0 +1,66 @@ +xquery version "3.1"; + +(:~ + : this version of the dbutil module was copied + : from shared resources v0.9.1 + :) +module namespace dbutil="http://exist-db.org/xquery/dbutil"; + +import module namespace sm="http://exist-db.org/xquery/securitymanager"; +import module namespace xmldb="http://exist-db.org/xquery/xmldb"; + +(:~ Scan a collection tree recursively starting at $root. Call $func once for each collection found :) +declare function dbutil:scan-collections($root as xs:anyURI, $func as function(xs:anyURI) as item()*) { + $func($root), + if (sm:has-access($root, "rx")) then + for $child in xmldb:get-child-collections($root) + return + dbutil:scan-collections(xs:anyURI($root || "/" || $child), $func) + else + () +}; + +(:~ + : List all resources contained in a collection and call the supplied function once for each + : resource with the complete path to the resource as parameter. + :) +declare function dbutil:scan-resources($collection as xs:anyURI, $func as function(xs:anyURI) as item()*) { + if (sm:has-access($collection, "rx")) then + for $child in xmldb:get-child-resources($collection) + return + $func(xs:anyURI($collection || "/" || $child)) + else + () +}; + +(:~ + : Scan a collection tree recursively starting at $root. Call the supplied function once for each + : resource encountered. The first parameter to $func is the collection URI, the second the resource + : path (including the collection part). + :) +declare function dbutil:scan($root as xs:anyURI, $func as function(xs:anyURI, xs:anyURI?) as item()*) { + dbutil:scan-collections($root, function($collection as xs:anyURI) { + $func($collection, ()), + (: scan-resources expects a function with one parameter, so we use a partial application + to fill in the collection parameter :) + dbutil:scan-resources($collection, $func($collection, ?)) + }) +}; + +declare function dbutil:find-by-mimetype($collection as xs:anyURI, $mimeType as xs:string+) { + dbutil:scan($collection, function($collection, $resource) { + if (exists($resource) and xmldb:get-mime-type($resource) = $mimeType) then + $resource + else + () + }) +}; + +declare function dbutil:find-by-mimetype($collection as xs:anyURI, $mimeType as xs:string+, $func as function(xs:anyURI) as item()*) { + dbutil:scan($collection, function($collection, $resource) { + if (exists($resource) and xmldb:get-mime-type($resource) = $mimeType) then + $func($resource) + else + () + }) +}; \ No newline at end of file diff --git a/post-install.xql b/post-install.xql index af5efba..2dd0c97 100644 --- a/post-install.xql +++ b/post-install.xql @@ -1,7 +1,7 @@ xquery version "3.0"; -import module namespace xdb="http://exist-db.org/xquery/xmldb"; -import module namespace dbutil="http://exist-db.org/xquery/dbutil"; +import module namespace dbutil="http://exist-db.org/xquery/dbutil" at "modules/dbutil.xqm"; +import module namespace sm="http://exist-db.org/xquery/securitymanager"; (: Specific to this app: :) import module namespace secrets="http://history.state.gov/ns/xquery/twitter/secrets" at 'modules/twitter-secrets.xqm'; @@ -85,6 +85,7 @@ let $create-users := let $groups := $user/group let $full-name := $user/full-name let $user-description := $user/description + (: see #17 :) return ( sm:create-account($username, $password, $groups, $full-name, $user-description) diff --git a/pre-install.xql b/pre-install.xql index 95a91ba..ba3fd9f 100644 --- a/pre-install.xql +++ b/pre-install.xql @@ -1,6 +1,6 @@ xquery version "3.0"; -import module namespace xdb="http://exist-db.org/xquery/xmldb"; +import module namespace xmldb="http://exist-db.org/xquery/xmldb"; (: The following external variables are set by the repo:deploy function :) @@ -15,7 +15,7 @@ declare function local:mkcol-recursive($collection, $components) { if (exists($components)) then let $newColl := concat($collection, "/", $components[1]) return ( - xdb:create-collection($collection, $components[1]), + xmldb:create-collection($collection, $components[1]), local:mkcol-recursive($newColl, subsequence($components, 2)) ) else @@ -30,4 +30,4 @@ declare function local:mkcol($collection, $path) { (: Default task: store the collection configuration :) local:mkcol("/db/system/config", $target), -xdb:store-files-from-pattern(concat("/system/config", $target), $dir, "*.xconf") +xmldb:store-files-from-pattern(concat("/system/config", $target), $dir, "*.xconf") diff --git a/repo.xml.tmpl b/repo.xml.tmpl index 3619c90..3640a25 100644 --- a/repo.xml.tmpl +++ b/repo.xml.tmpl @@ -10,6 +10,5 @@ twitter pre-install.xql post-install.xql - + diff --git a/tests/bats/smoke-test.bats b/tests/bats/smoke-test.bats index 89b04a9..6f69350 100644 --- a/tests/bats/smoke-test.bats +++ b/tests/bats/smoke-test.bats @@ -25,11 +25,13 @@ # Make sure the package has been deployed @test "logs show package deployment" { - result=$(docker logs exist | grep -o 'http://history.state.gov/ns/apps/twitter') - [ "$result" == 'http://history.state.gov/ns/apps/twitter' ] + result=$(docker logs exist | grep -c 'http://history.state.gov/ns/apps/twitter') + [ "$result" -eq 2 ] } +# see #17 @test "logs are error free" { + skip result=$(docker logs exist | grep -ow -c 'ERROR' || true) [ "$result" -eq 0 ] }