From 8d9e2036e744c47040c1449f2eee1715d6539e86 Mon Sep 17 00:00:00 2001 From: Yann D'Isanto Date: Thu, 4 Apr 2024 17:37:20 +0200 Subject: [PATCH 1/2] feat!: support multiple test files --- .github/workflows/test.yml | 11 ++++++-- README.md | 53 +++++++++++++++++++++++++++++++++----- action.yml | 24 ++++++++++++++--- 3 files changed, 76 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fb9c094..ee46ec1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,6 +9,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 662197b..d165d39 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,56 @@ [![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 + +on: + workflow_dispatch: + +jobs: + test: + name: Run test + runs-on: ubuntu-latest + steps: + - uses: openfga/action-openfga-test@v0.1 + with: + test_path: example +``` + +### Running tests of a single file ```yaml name: Test Action @@ -25,7 +66,7 @@ jobs: steps: - uses: openfga/action-openfga-test@v0.1 with: - store-file-path: ./example/model.fga.yaml + test_path: example/model.fga.yaml ``` diff --git a/action.yml b/action.yml index fa7ddf3..fd5b279 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 From 80f082825f1c40e3e2b9235bc93e8172ce5196a4 Mon Sep 17 00:00:00 2001 From: Yann D'Isanto Date: Thu, 4 Apr 2024 17:58:06 +0200 Subject: [PATCH 2/2] ci: run test workflow on PR --- .github/workflows/test.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ee46ec1..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: