From bbdc3f5a1af981856bdb44f581954ceb3b85f9ca Mon Sep 17 00:00:00 2001 From: Yann D'Isanto Date: Fri, 5 Apr 2024 00:04:02 +0200 Subject: [PATCH] feat!: support multiple test files (#8) * feat!: support multiple test files * ci: run test workflow on PR --- .github/workflows/test.yml | 16 ++++++++++-- README.md | 53 +++++++++++++++++++++++++++++++++----- action.yml | 24 ++++++++++++++--- 3 files changed, 81 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fb9c094..76ccc21 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,6 +2,11 @@ name: Test Action on: workflow_dispatch: + pull_request: + types: + - opened + - edited + - synchronize jobs: test: @@ -9,6 +14,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: ./ + - name: default values + uses: ./ + - name: specify folder + uses: ./ with: - store-file-path: ./example/model.fga.yaml \ No newline at end of file + test_path: ./example + - name: single file + uses: ./ + with: + test_path: ./example/model.fga.yaml diff --git a/README.md b/README.md index b239248..edc2e74 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,38 @@ [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fopenfga%2Faction-openfga-test.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fopenfga%2Faction-openfga-test?ref=badge_shield) -This action can be used to test your authorization model using a store file. +This action can be used to test your authorization model using store test files. ## Parameter -| Parameter | Description | -|----------|--------------| -| `store-file-path` | The path to your store file relative to the root of your project | +| Parameter | Description | Required | Default | +|----------------------|----------------------------------------------------------------------------------|----------|--------------| +| `test_path` | The path to your store test file or folder relative to the root of your project. | No | `.` | +| `test_files_pattern` | The pattern to match test files. | No | `*.fga.yaml` | -## Example +> Note: the action will fail if no test is found in the specified test path with the given pattern + + +## Examples + + +### Running tests of `*.fga.yaml` files present in the repository + +```yaml +name: Test Action + +on: + workflow_dispatch: + +jobs: + test: + name: Run test + runs-on: ubuntu-latest + steps: + - uses: openfga/action-openfga-test@v0.1 +``` + +### Running tests of `*.fga.yaml` files present in a given folder ```yaml name: Test Action @@ -25,7 +48,25 @@ jobs: steps: - uses: openfga/action-openfga-test@v0.1.0 with: - store-file-path: ./example/model.fga.yaml + test_path: example +``` + +### Running tests of a single file + +```yaml +name: Test Action + +on: + workflow_dispatch: + +jobs: + test: + name: Run test + runs-on: ubuntu-latest + steps: + - uses: openfga/action-openfga-test@v0.1 + with: + test_path: example/model.fga.yaml ``` diff --git a/action.yml b/action.yml index 5f7743b..5c01ebe 100644 --- a/action.yml +++ b/action.yml @@ -5,9 +5,14 @@ branding: color: 'green' inputs: - store-file-path: - description: The path to the store file - required: true + test_path: + description: 'Path to the test file or folder' + required: false + default: '.' + test_files_pattern: + description: 'Pattern to match the test files' + required: false + default: '*.fga.yaml' runs: using: composite @@ -19,4 +24,15 @@ runs: cache: enable - name: Run OpenFGA CLI shell: bash - run: fga model test --tests ${{ inputs.store-file-path }} + run: | + while IFS= read -r -d '' test_file + do + ((test_files_count+=1)) + echo "Running FGA test file ${test_file}" + fga model test --tests "${test_file}" + done < <(find ${{ inputs.test_path }} -name "${{ inputs.test_files_pattern }}" -print0) + + if [[ ${test_files_count} -eq 0 ]]; then + echo "No FGA test file found for path '${{ inputs.test_path }}' and pattern '${{ inputs.test_files_pattern }}'" + exit 1 + fi \ No newline at end of file