Skip to content

lsp: Auto update examples index #21

lsp: Auto update examples index

lsp: Auto update examples index #21

# 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
- uses: open-policy-agent/setup-opa@34a30e8a924d1b03ce2cf7abe97250bbb1f332b5 # v2.2.0
with:
version: edge
static: true
- name: Restore rq cache
id: cache-rq
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/go/bin/rq
key: ${{ runner.os }}-${{ runner.arch }}-go-rq-${{ env.RQ_VERSION }}
- run: go install git.sr.ht/~charles/rq/cmd/rq@${{ env.RQ_VERSION }}
if: steps.cache-rq.outputs.cache-hit != 'true'
- name: Cache rq binary
if: steps.cache-rq.outputs.cache-hit != 'true'
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/go/bin/rq
key: ${{ runner.os }}-${{ runner.arch }}-go-rq-${{ env.RQ_VERSION }}
- name: Fetch sitemap and convert to JSON
run: |
set -o pipefail
TEMP_DIR=$(mktemp -d)
curl -L https://docs.styra.com/sitemap.xml -o "$TEMP_DIR/sitemap.xml"
cat "$TEMP_DIR/sitemap.xml" | \
rq -i xml --indent " " | \
opa eval 'data.process.symbols' \
-d build/workflows/update-example-index/process.rego \
--format=raw \
--stdin-input \
| jq \
| tee internal/lsp/examples/index.json
# - name: Commit and push changes
# uses: stefanzweifel/git-auto-commit-action@8621497c8c39c72f3e2a999a26b4ca1b5058a842 # v5.0.1
# with:
# commit_message: Update Imported Docs