-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Charlie Egan <[email protected]>
- Loading branch information
1 parent
d070132
commit 4782af9
Showing
2 changed files
with
99 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# this workflow is used to update the internal/lsp/examples/index.json | ||
# file containing an index of the content available on | ||
# http://docs.styra.com/opa/rego-by-example | ||
name: Update Examples Index | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 1 * * *' # Run daily at 1 AM UTC | ||
pull_request: | ||
|
||
jobs: | ||
update-examples-index: | ||
name: Update Examples Index | ||
runs-on: ubuntu-22.04 | ||
permissions: | ||
contents: write # this workflow updates repo contents | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
|
||
- name: Fetch and save index to temporary directory | ||
run: | | ||
TEMP_DIR=$(mktemp -d) | ||
curl -L https://docs.styra.com/sitemap.xml | xq . - > "$TEMP_DIR/output.json" | ||
cat "$TEMP_DIR/output.json" | \ | ||
opa eval 'data.process.symbols' \ | ||
-d build/workflows/update-examples-index/process.rego \ | ||
--format=raw \ | ||
--stdin-input \ | ||
| tee internal/lsp/examples/index.json | ||
# - name: Commit and push changes | ||
# uses: stefanzweifel/git-auto-commit-action@v4 | ||
# with: | ||
# commit_message: Update Imported Docs |
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,62 @@ | ||
package process | ||
|
||
import rego.v1 | ||
|
||
symbols := {"keywords": _keywords, "builtins": _builtins} | ||
|
||
_keywords[name] := path if { | ||
some p in _pages | ||
p[0] == "keywords" | ||
|
||
name := p[1] | ||
|
||
path := concat("/", p) | ||
} | ||
|
||
_builtins[name] := path if { | ||
some p in _pages | ||
p[0] == "builtins" | ||
|
||
l := count(p) | ||
|
||
l == 2 | ||
|
||
name := p[1] | ||
|
||
not count({p | | ||
some p in _pages | ||
p[0] == "builtins" | ||
p[1] == name | ||
}) > 1 | ||
|
||
path := concat("/", p) | ||
} | ||
|
||
_builtins[name] := path if { | ||
some p in _pages | ||
p[0] == "builtins" | ||
|
||
l := count(p) | ||
|
||
l > 2 | ||
|
||
name := concat( | ||
".", | ||
[ | ||
replace(p[1], "_", "."), | ||
concat(".", array.slice(p, 2, l)), | ||
], | ||
) | ||
|
||
path := concat("/", p) | ||
} | ||
|
||
_prefix := "https://docs.styra.com/opa/rego-by-example/" | ||
|
||
_pages contains page if { | ||
some url in input.urlset.url | ||
|
||
startswith(url.loc, _prefix) | ||
|
||
page := split(trim_prefix(url, _prefix), "/") | ||
} |