diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e0d7c17 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +name: Test + +on: + push: + workflow_dispatch: + +jobs: + smoke-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # The datacontract container runs as a non-root user and writes the JUnit + # report into the workspace, see README. + - name: Make workspace writable for datacontract container + run: chmod -R a+rwX "$GITHUB_WORKSPACE" + - name: Run action against local test contract + uses: ./ + with: + location: tests/datacontract.yaml + server: production + junit-test-report: TEST-datacontract.xml + - name: Assert JUnit report was written + run: | + test -s TEST-datacontract.xml + grep -q 'failures="0"' TEST-datacontract.xml + cat TEST-datacontract.xml diff --git a/action.yml b/action.yml index fd5ce93..d965774 100644 --- a/action.yml +++ b/action.yml @@ -20,13 +20,18 @@ inputs: runs: using: 'docker' image: 'docker://datacontract/cli:latest' - entrypoint: /bin/sh + # The image has no shell, so the CLI is invoked directly. The runner passes empty + # args as literal "" (it does not drop them) and the CLI rejects an empty --publish + # value, so the publish option is a single `--publish=` arg that degrades to + # `--no-logs` (the CLI's default behavior anyway) when the input is unset. + entrypoint: datacontract args: - - -c - - >- - datacontract test - --server '${{ inputs.server }}' - --output-format junit - --output '${{ inputs.junit-test-report }}' - ${{ inputs.publish != '' && format('--publish ''{0}''', inputs.publish) || '' }} - '${{ inputs.location }}' + - test + - --server + - ${{ inputs.server }} + - --output-format + - junit + - --output + - ${{ inputs.junit-test-report }} + - ${{ inputs.publish != '' && format('--publish={0}', inputs.publish) || '--no-logs' }} + - ${{ inputs.location }} diff --git a/tests/data/orders.csv b/tests/data/orders.csv new file mode 100644 index 0000000..4b8d5be --- /dev/null +++ b/tests/data/orders.csv @@ -0,0 +1,4 @@ +order_id,amount +1,10.50 +2,20.00 +3,7.25 diff --git a/tests/datacontract.yaml b/tests/datacontract.yaml new file mode 100644 index 0000000..ab91bdd --- /dev/null +++ b/tests/datacontract.yaml @@ -0,0 +1,20 @@ +dataContractSpecification: 1.1.0 +id: datacontract-action-smoke-test +info: + title: Smoke test contract for the GitHub Action + version: 1.0.0 +servers: + production: + type: local + path: tests/data/orders.csv + format: csv +models: + orders: + type: table + fields: + order_id: + type: string + required: true + unique: true + amount: + type: decimal