Skip to content

Commit

Permalink
feat: jargon artifacts validation pipeline (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
huynguyen-hl authored Feb 18, 2025
1 parent d9c62fa commit e7a19ed
Show file tree
Hide file tree
Showing 11 changed files with 775 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/actions/validate-jargon-artefacts/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
action.yml
Dockerfile
README.md
9 changes: 9 additions & 0 deletions .github/actions/validate-jargon-artefacts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM node:21-alpine

COPY package*.json /

RUN npm ci

COPY src /src

CMD ["node", "/src/index.js"]
79 changes: 79 additions & 0 deletions .github/actions/validate-jargon-artefacts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Validate Jargon Artefacts GitHub Action

This custom GitHub Action automates the validation of Jargon-generated UNTP artifacts, including JSON-LD contexts, schemas, and sample credentials. It ensures that the generated artifacts comply with the appropriate specifications before release.

## Features
- **Automated Validation**: Checks JSON-LD contexts, schemas, and sample credentials.
- **Webhook Integration**: Triggers validation upon receiving Jargon snapshot events.
- **Dockerized Execution**: Runs in an isolated container environment.
- **GitHub Actions Support**: Easily integrates into GitHub workflows.
- **Validation Reporting**: Outputs validation results for further processing.

## Installation
This GitHub Action is designed to be used within a workflow in the [`spec-untp`](https://github.com/uncefact/spec-untp) repository.

## Usage
To use this action in your GitHub workflow, add the following YAML configuration to your `.github/workflows/validate.yml` file:

```yaml
name: Validate Jargon Artefacts

on:
repository_dispatch:
types: [jargon_onSnapshot]

jobs:
validate-jargon-artefacts:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Run Validate Jargon Artefacts
id: validate
uses: ./.github/actions/validate-jargon-artefacts
with:
jargon-webhook-payload: ${{ toJSON(github.event.client_payload) }}

- name: Show Validation Result
run: |
echo "Jarogn Artefacts Validation Result: ${{ steps.validate.outputs.validation-result }}"
```
## Inputs
| Name | Description | Required |
|------|-------------|----------|
| `jargon-webhook-payload` | The JSON payload from the Jargon webhook | Yes |

## Outputs
| Name | Description |
|------|-------------|
| `validation-result` | The validation result of the artifacts |

## Implementation Details
- **Docker-based execution**: The action runs inside a Docker container using `node:21-alpine`.
- **Validation Scripts**:
- `schemaValidation.js`: Validates sample credentials against their schema and the context used in the sample credentials.
- `contextValidation.js`: Validates JSON-LD context files.
- **Error Handling**: If validation fails, the action sets the workflow as failed.

## Development

### Running Locally
To test this action locally, clone the repository and run:

```sh
# Build the Docker image
docker build -t validate-jargon-artefacts .
# Run the Docker container
docker run --rm -e INPUT_JARGON-WEBHOOK-PAYLOAD='{"artefacts": {...}}' validate-jargon-artefacts
```

### Modifying the Action

- Update `src/index.js` for core validation logic.
- Update `src/contextValidation.js` and `src/schemaValidation.js` for context and schema validation.
- Update `src/utils.js` for utility functions.
- Update `Dockerfile` for Docker image changes.
- Modify `action.yml` for input/output changes.
13 changes: 13 additions & 0 deletions .github/actions/validate-jargon-artefacts/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Validate Jargon Artefacts
description: Validates the Jargon snapshot artefacts.

inputs:
jargon-webhook-payload:
description: The JSON payload from the Jargon webhook.
required: true
outputs:
validation-result:
description: The validation result.
runs:
using: docker
image: Dockerfile
Loading

0 comments on commit e7a19ed

Please sign in to comment.