├── action.yml └── README.md /action.yml: -------------------------------------------------------------------------------- 1 | name: Data Contract CLI 2 | description: Run Data Contract Tests. The result is written as a JUnit Test Report to 'TEST-datacontract.xml'. 3 | inputs: 4 | location: 5 | description: The location (url or path) of the data contract YAML. The current Github workspace is set as working dir and mounted to '/github/workspace'. 6 | required: true 7 | default: 'datacontract.yaml' 8 | server: 9 | description: The server configuration to run the schema and quality tests. Use the key of the server object in the data contract yaml file to refer to a server, e.g., `production`, or `all` for all servers (default). 10 | required: false 11 | default: all 12 | junit-test-report: 13 | description: The location where the JUnit test report file should be written to. This test report can be used with a subsequent action to create a GitHub test summary. 14 | required: false 15 | default: TEST-datacontract.xml 16 | runs: 17 | using: 'docker' 18 | image: 'docker://datacontract/cli:snapshot-latest' 19 | args: 20 | - 'test' 21 | - --server 22 | - ${{ inputs.server }} 23 | - --output-format 24 | - junit 25 | - --output 26 | - ${{ inputs.junit-test-report }} 27 | - ${{ inputs.location }} 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # datacontract-action 2 | 3 | GitHub Action to run data contract tests using the [Data Contract CLI](https://github.com/datacontract/datacontract-cli). 4 | 5 | The action supports testing data contracts in [Data Contract Specification](https://datacontract.com/) and [Open Data Contract Standard 6 | ](https://bitol-io.github.io/open-data-contract-standard/latest/) format. 7 | 8 | ![datacontract-action in combination with test reporter action](https://github.com/user-attachments/assets/50e7614b-aedd-4e90-9249-6fbfba718dfd) 9 | 10 | 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. 11 | 12 | 13 | ## Usage 14 | 15 | Add this step to your Github action workflow: 16 | 17 | ```yaml 18 | - name: Data Contract Tests 19 | uses: datacontract/datacontract-action@main 20 | with: 21 | location: datacontract.yaml # local data contract file in workspace or remote URL 22 | server: all # The name of server to test or all 23 | junit-test-report: TEST-datacontract.xml # This test report can be used with a subsequent action to create a GitHub test summary. 24 | env: # Define server credentials as environment variables. Use Github Secrets for secure configuration. 25 | DATACONTRACT_SNOWFLAKE_USERNAME: ${{ secrets.DATACONTRACT_SNOWFLAKE_USERNAME }} 26 | DATACONTRACT_SNOWFLAKE_PASSWORD: ${{ secrets.DATACONTRACT_SNOWFLAKE_PASSWORD }} 27 | DATACONTRACT_SNOWFLAKE_WAREHOUSE: ${{ secrets.DATACONTRACT_SNOWFLAKE_WAREHOUSE }} 28 | DATACONTRACT_SNOWFLAKE_ROLE: ${{ secrets.DATACONTRACT_SNOWFLAKE_ROLE }} 29 | ``` 30 | 31 | 32 | 33 | ## Full Example 34 | 35 | This action can be used in combination with a [test reporter action](https://github.com/dorny/test-reporter) to create and publish a test summary. 36 | 37 | 38 | ```yaml 39 | # .github/workflows/main.yml 40 | on: 41 | push: 42 | workflow_dispatch: 43 | 44 | permissions: 45 | contents: read 46 | actions: read 47 | checks: write 48 | 49 | jobs: 50 | datacontract-test: 51 | runs-on: ubuntu-latest 52 | steps: 53 | - name: Checkout 54 | uses: actions/checkout@v4 55 | 56 | - name: Data Contract Tests 57 | uses: datacontract/datacontract-action@main 58 | with: 59 | location: datacontract.yaml 60 | server: all 61 | junit-test-report: TEST-datacontract.xml 62 | env: 63 | DATACONTRACT_SNOWFLAKE_USERNAME: ${{ secrets.DATACONTRACT_SNOWFLAKE_USERNAME }} 64 | DATACONTRACT_SNOWFLAKE_PASSWORD: ${{ secrets.DATACONTRACT_SNOWFLAKE_PASSWORD }} 65 | DATACONTRACT_SNOWFLAKE_WAREHOUSE: ${{ secrets.DATACONTRACT_SNOWFLAKE_WAREHOUSE }} 66 | DATACONTRACT_SNOWFLAKE_ROLE: ${{ secrets.DATACONTRACT_SNOWFLAKE_ROLE }} 67 | 68 | - name: Data Contract Test Results 69 | uses: dorny/test-reporter@v1 70 | if: always() 71 | with: 72 | name: Data Contract Test Results 73 | path: ./TEST-datacontract.xml 74 | reporter: java-junit 75 | fail-on-error: 'false' 76 | ``` 77 | 78 | 79 | ## Credentials 80 | 81 | Server credentials (such as username and password) can be defined as environment variables. 82 | See [documentation](https://cli.datacontract.com/#test) for supported environment variables depending on the server type. 83 | 84 | Use [Github secrets](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions) to store sensitive information for your repository or environment. 85 | 86 | 87 | ## License 88 | 89 | MIT 90 | 91 | 92 | --------------------------------------------------------------------------------