Skip to content

datacontract/datacontract-action

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 

Repository files navigation

datacontract-action

GitHub Action to run data contract tests using the Data Contract CLI.

The action supports testing data contracts in Data Contract Specification and Open Data Contract Standard format.

datacontract-action in combination with test reporter action

You can use this GitHub action to enforce data contracts whenever your data contract specification changes and for periodic checks. The action generates a test report in JUnit XML format that can be used in a subsequent step to create a GitHub test summary, as shown above.

Usage

Add this step to your Github action workflow:

      - name: Data Contract Tests
        uses: datacontract/datacontract-action@main
        with:
          location: datacontract.yaml                 # local data contract file in workspace or remote URL
          server: all                                 # The name of server to test or all
          junit-test-report: TEST-datacontract.xml    # This test report can be used with a subsequent action to create a GitHub test summary.
          publish: ''                                 # Optional URL to publish test results to (e.g. a Data Mesh Manager / Entropy Data endpoint). Leave empty to skip.
        env: # Define server credentials as environment variables. Use Github Secrets for secure configuration.
          DATACONTRACT_SNOWFLAKE_USERNAME: ${{ secrets.DATACONTRACT_SNOWFLAKE_USERNAME }}
          DATACONTRACT_SNOWFLAKE_PASSWORD: ${{ secrets.DATACONTRACT_SNOWFLAKE_PASSWORD }}
          DATACONTRACT_SNOWFLAKE_WAREHOUSE: ${{ secrets.DATACONTRACT_SNOWFLAKE_WAREHOUSE }}
          DATACONTRACT_SNOWFLAKE_ROLE: ${{ secrets.DATACONTRACT_SNOWFLAKE_ROLE }}

Writable workspace (non-root container)

This action runs the datacontract/cli Docker image, which executes as a non-root user. The JUnit test report (junit-test-report, default TEST-datacontract.xml) is written into the GitHub workspace (mounted at /github/workspace), which is owned by the runner user. If the workspace is not writable by the container user, the tests run and publish successfully but the action fails at the end when writing the report:

Error: [Errno 13] Permission denied: 'TEST-datacontract.xml'

Add a step before this action to make the workspace writable:

      - name: Make workspace writable for the datacontract container
        run: chmod -R a+rwX "$GITHUB_WORKSPACE"

a+rwX grants write access to all users; the capital X sets the traverse bit on directories only, so the container user can create the report file inside the workspace.

Full Example

This action can be used in combination with a test reporter action to create and publish a test summary.

# .github/workflows/main.yml
on:
  push:
  workflow_dispatch:

permissions:
  contents: read
  actions: read
  checks: write
  
jobs:
  datacontract-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Make workspace writable for the datacontract container
        run: chmod -R a+rwX "$GITHUB_WORKSPACE"

      - name: Data Contract Tests
        uses: datacontract/datacontract-action@main
        with:
          location: datacontract.yaml
          server: all
          junit-test-report: TEST-datacontract.xml
        env:
          DATACONTRACT_SNOWFLAKE_USERNAME: ${{ secrets.DATACONTRACT_SNOWFLAKE_USERNAME }}
          DATACONTRACT_SNOWFLAKE_PASSWORD: ${{ secrets.DATACONTRACT_SNOWFLAKE_PASSWORD }}
          DATACONTRACT_SNOWFLAKE_WAREHOUSE: ${{ secrets.DATACONTRACT_SNOWFLAKE_WAREHOUSE }}
          DATACONTRACT_SNOWFLAKE_ROLE: ${{ secrets.DATACONTRACT_SNOWFLAKE_ROLE }}

      - name: Data Contract Test Results
        uses: dorny/test-reporter@v1
        if: always()
        with:
          name: Data Contract Test Results
          path: ./TEST-datacontract.xml
          reporter: java-junit
          fail-on-error: 'false'

Publishing test results

Set the publish input to a URL to push the test results after each run, for example to a Data Mesh Manager or Entropy Data test-results endpoint. When the input is empty (the default), nothing is published and the action behaves exactly as before.

      - name: Data Contract Tests
        uses: datacontract/datacontract-action@main
        with:
          location: datacontract.yaml
          server: production
          publish: https://api.entropy-data.com/api/test-results
        env:
          DATACONTRACT_DATABRICKS_TOKEN: ${{ secrets.DATACONTRACT_DATABRICKS_TOKEN }}
          DATACONTRACT_DATABRICKS_SERVER_HOSTNAME: ${{ secrets.DATACONTRACT_DATABRICKS_SERVER_HOSTNAME }}
          DATACONTRACT_DATABRICKS_HTTP_PATH: ${{ secrets.DATACONTRACT_DATABRICKS_HTTP_PATH }}
          ENTROPY_DATA_API_KEY: ${{ secrets.ENTROPY_DATA_API_KEY }}   # auth for the publish endpoint

Credentials

Server credentials (such as username and password) can be defined as environment variables. See documentation for supported environment variables depending on the server type.

Use Github secrets to store sensitive information for your repository or environment.

License

MIT

About

Github Action to run data contract tests

Resources

Stars

Watchers

Forks

Releases

No releases published

Contributors