-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
181 additions
and
2 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,61 @@ | ||
name: Publish Go Docs | ||
|
||
on: | ||
# Publish documentation when a new release is tagged. | ||
push: | ||
tags: [ 'v*' ] | ||
|
||
# Allow manually publishing documentation from a specific hash. | ||
workflow_dispatch: | ||
inputs: | ||
head: | ||
description: "Git commit to publish documentation for." | ||
required: true | ||
type: string | ||
|
||
# If two concurrent runs are started, prefer the latest one. | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
build: | ||
name: Build godoc website | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
# Check out head specified by workflow_dispatch, | ||
# or the tag if this fired from the push event. | ||
ref: ${{ inputs.head || github.ref }} | ||
- name: Setup Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: stable | ||
cache: true | ||
- name: Install doc2go | ||
run: go install go.abhg.dev/doc2go@latest | ||
- name: Generate API reference | ||
run: doc2go -home github.com/${{ github.repository }} ./... | ||
- name: Upload pages | ||
uses: actions/upload-pages-artifact@v1 | ||
|
||
publish: | ||
name: Publish godoc website | ||
# Don't run until the build has finished running. | ||
needs: build | ||
# Grants the GITHUB_TOKEN used by this job permissions needed to publish | ||
# the doc website. | ||
permissions: | ||
pages: write | ||
id-token: write | ||
# Deploy to the github-pages environment | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v1 |
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 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 |
---|---|---|
|
@@ -6,3 +6,69 @@ individual Rego files for each label. | |
To add a new predefined label, add its metadata to [`labels.yaml`](labels.yaml) | ||
(following the file's instructions), as well as a corresponding classification | ||
rule Rego file. | ||
|
||
## Classification Rule Rego Files | ||
|
||
Each label has a corresponding Rego file that defines the classification rule | ||
for that label. The Rego file should be named after the label, with the `.rego` | ||
extension. For example, the classification rule for the label `first_name` | ||
should be defined in a file named `first_name.rego`. | ||
|
||
The package for the rule should be named `classifier_<label>`, where `<label>` | ||
is the name of the label in lowercase. For example, the package for the | ||
classification rule for the label `first_name` should be named | ||
`classifier_first_name`. | ||
|
||
Rules should also have tests defined in a file named `<label>_test.rego`. | ||
|
||
All Rego files (including tests) should be linted using [`regal`](https://www.openpolicyagent.org/integrations/regal/) | ||
to ensure they are formatted correctly, e.g. | ||
|
||
```bash | ||
$ regal lint /path/to/label.rego | ||
``` | ||
|
||
### Input and Output | ||
|
||
The input data for a classification rule is a JSON object containing the data | ||
to be classified. This often represents a database table sample, for example. | ||
The key names in the input data object correspond to the column names in the | ||
database table, and the values are the sampled data in the table. For example, | ||
input data representing a data sample from a database table called `users` | ||
might look like this: | ||
|
||
```json | ||
{ | ||
"first_name": "John", | ||
"last_name": "Doe", | ||
"email": "[email protected]" | ||
} | ||
``` | ||
|
||
Each rule must define an output variable named `output`, which must an | ||
[object](https://www.openpolicyagent.org/docs/latest/policy-language/#objects) | ||
of the form: | ||
|
||
```json | ||
{ | ||
"key": boolean | ||
} | ||
``` | ||
|
||
where `key` is each key from the input data, and `boolean` is a boolean value | ||
indicating whether the key is classified as the label or not. For example, the | ||
output object for the `first_name` label using the example input data above | ||
would look like this: | ||
|
||
```json | ||
{ | ||
"first_name": true, | ||
"last_name": false, | ||
"email": false | ||
} | ||
``` | ||
|
||
See this example on the [Rego Playground](https://play.openpolicyagent.org/p/niTDt5JwN8). | ||
|
||
Please see the existing classification rules and their tests for examples of how | ||
to write classification rules. |