Update Examples Index #147
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 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 | |
permissions: | |
contents: read | |
jobs: | |
update-examples-index: | |
env: | |
RQ_VERSION: v0.0.9 | |
name: Update Examples Index | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: write # this is needed to open a pull request | |
pull-requests: write # this is also needed to open a pull request | |
steps: | |
- name: Check out code | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
- name: Set up go for rq | |
uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0 | |
with: | |
go-version-file: go.mod | |
- id: opa | |
name: read OPA version | |
run: echo "version=$(go list -m -f '{{.Version}}' github.com/open-policy-agent/opa)" >> $GITHUB_OUTPUT | |
- uses: open-policy-agent/setup-opa@34a30e8a924d1b03ce2cf7abe97250bbb1f332b5 # v2.2.0 | |
with: | |
version: ${{ steps.opa.outputs.version }} | |
static: true | |
- name: Restore rq cache | |
id: cache-rq | |
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.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@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.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.build.workflows.symbols' \ | |
-d build/workflows/update_example_index.rego \ | |
--format=pretty \ | |
--stdin-input | \ | |
tee internal/lsp/examples/index.json | |
- name: Open a pull request | |
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # v7.0.5 | |
with: | |
title: "lsp: Update rego-by-examples index" | |
commit-message: "lsp: Update rego-by-examples index" | |
base: main |