diff --git a/README.md b/README.md index 15f64ab..1420a67 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,18 @@ # DDEV add-on test action --- + > A GitHub action to run tests on a DDEV add-on. + --- [![Version](https://img.shields.io/github/v/release/ddev/github-action-add-on-test)](https://github.com/ddev/github-action-add-on-test/releases) ![project is maintained](https://img.shields.io/maintenance/yes/2024.svg) [![tests](https://github.com/ddev/github-action-add-on-test/actions/workflows/add-ons-test.yml/badge.svg)](https://github.com/ddev/github-action-add-on-test/actions/workflows/add-ons-test.yml) - + **Table of Contents** - [Quick start](#quick-start) @@ -44,12 +46,12 @@ This step will install the latest stable version of DDEV and run `bats tests` co ## Inputs - ### Available keys The following keys are available as `step.with` keys: --- + - `ddev_version` (_String_) DDEV version that will be installed before your tests. @@ -74,14 +76,13 @@ Example: `${{ secrets.GITHUB_TOKEN }}`. - `addon_repository`(_String_) -GitHub repository of the tested addon (`{owner}/{repo}`). Will be used as the `repository` key during a [checkout +GitHub repository of the tested addon (`{owner}/{repo}`). Will be used as the `repository` key during a [checkout action](https://github.com/actions/checkout#usage) Required. Example: `${{ env.GITHUB_REPOSITORY }}`. - --- - `addon_ref`(_String_) @@ -96,7 +97,7 @@ Example: `${{ env.GITHUB_REF }}`. - `addon_path`(_String_) -Path (relative to `$GITHUB_WORKSPACE` ) where the addon will be cloned by a checkout action. Will be used as the `path` +Path (relative to `$GITHUB_WORKSPACE` ) where the addon will be cloned by a checkout action. Will be used as the `path` key of the [checkout action](https://github.com/actions/checkout#usage) Not required. @@ -107,7 +108,7 @@ Default: `./` - `keepalive` (_Boolean_) -Keeps GitHub from turning off tests after 60 days. +Keeps GitHub from turning off tests after 60 days. If enabled, action will use [keepalive-workflow action](https://github.com/gautamkrishnar/keepalive-workflow) when `ddev_version` has been set to `stable`. @@ -124,12 +125,11 @@ Default: `true`. --- - - `keepalive_time_elapsed` (_String_) Time elapsed from the previous commit to keep the repository active using GitHub API (in days). -Will be used as the `time_elapsed` key of the [keepalive-workflow action](https://github.com/gautamkrishnar/keepalive-workflow). +Will be used as the `time_elapsed` key of the [keepalive-workflow action](https://github.com/gautamkrishnar/keepalive-workflow). Not required. @@ -137,7 +137,6 @@ Default: `"0"`. --- - - `debug_enabled` (_Boolean_) If `true`, a tmate session will be accessible before the tests step. See [action-tmate](https://github.com/mxschmitt/action-tmate) for more details. @@ -158,27 +157,38 @@ Default: `false`. --- +- `test_command` (_String_) + +If you want to run a customized test command, you can use this input. + +If it's empty, the test command will be `bats tests --filter-tags !release` during a pull request workflow and `bats tests` otherwise. + +Not required. + +Default: `""`. + +--- + ## Usage ### Test your DDEV add-on -If your add-on is based on the [DDEV add-on template repository](https://github.com/ddev/ddev-addon-template), you +If your add-on is based on the [DDEV add-on template repository](https://github.com/ddev/ddev-addon-template), you should have a tests folder containing a `test.bats` file. -Using this GitHub action, a `.github/workflows/tests.yml` file could have the following content: - +Using this GitHub action, a `.github/workflows/tests.yml` file could have the following content: ```yaml name: tests on: pull_request: push: - branches: [ main ] + branches: [main] paths-ignore: - - '**.md' + - "**.md" schedule: - - cron: '25 08 * * *' + - cron: "25 08 * * *" workflow_dispatch: inputs: @@ -192,7 +202,6 @@ permissions: jobs: tests: - strategy: matrix: ddev_version: [stable, HEAD] @@ -201,17 +210,15 @@ jobs: runs-on: ubuntu-latest steps: - - - uses: ddev/github-action-add-on-test@v2 - with: - ddev_version: ${{ matrix.ddev_version }} - token: ${{ secrets.GITHUB_TOKEN }} - debug_enabled: ${{ github.event.inputs.debug_enabled }} - addon_repository: ${{ env.GITHUB_REPOSITORY }} - addon_ref: ${{ env.GITHUB_REF }} + - uses: ddev/github-action-add-on-test@v2 + with: + ddev_version: ${{ matrix.ddev_version }} + token: ${{ secrets.GITHUB_TOKEN }} + debug_enabled: ${{ github.event.inputs.debug_enabled }} + addon_repository: ${{ env.GITHUB_REPOSITORY }} + addon_ref: ${{ env.GITHUB_REF }} ``` - ## License [Apache](LICENSE) @@ -220,5 +227,4 @@ jobs: Anyone is welcome to submit a pull request to this repository. - **Contributed and maintained by [julienloizelet](https://github.com/julienloizelet)** diff --git a/action.yaml b/action.yaml index 33b6e99..0aa08ff 100644 --- a/action.yaml +++ b/action.yaml @@ -3,7 +3,6 @@ author: "Julien Loizelet" description: "A Github Action to run DDEV add-on tests" inputs: - ddev_version: type: choice required: false @@ -14,49 +13,53 @@ inputs: - "HEAD" addon_repository: - description: 'Repository of the tested addon' + description: "Repository of the tested addon" required: true addon_ref: - description: 'Repository ref of the tested addon' + description: "Repository ref of the tested addon" required: true addon_path: - description: 'Path to clone the addon' + description: "Path to clone the addon" required: false - default: './' + default: "./" keepalive: type: boolean - description: 'Keeps GitHub from turning off tests after 60 days' + description: "Keeps GitHub from turning off tests after 60 days" required: false default: true keepalive_time_elapsed: - description: 'Time elapsed from the most recent commit to hit API and prevent expiration (in days)' + description: "Time elapsed from the most recent commit to hit API and prevent expiration (in days)" required: false default: "0" debug_enabled: type: boolean - description: Debug with tmate + description: "Debug with tmate" required: false default: false disable_checkout_action: type: boolean - description: Disable addon checkout action + description: "Disable addon checkout action" required: false default: false token: - description: 'A Github PAT' + description: "A Github PAT" required: true + test_command: + description: "Test command to run" + required: false + default: "" + runs: using: "composite" steps: - - uses: Homebrew/actions/setup-homebrew@master - name: Environment setup @@ -102,9 +105,23 @@ runs: DDEV_NONINTERACTIVE: "true" # Don't send telemetry to amplitude DDEV_NO_INSTRUMENTATION: "true" - + # Use test_command input if provided + TEST_COMMAND_INPUT: ${{ inputs.test_command }} + # Use the addon path + ADDON_PATH: ${{ inputs.addon_path }} shell: bash - run: cd ${{ inputs.addon_path }} && bats tests + # Use of "set +H" to ensure that bash history expansion is disabled so that ! can be used in test command + run: | + set +H + if [ -n "$TEST_COMMAND_INPUT" ]; then + TEST_COMMAND="$TEST_COMMAND_INPUT" + elif [ "${{ github.event_name }}" == "pull_request" ]; then + TEST_COMMAND="bats tests --filter-tags !release" + else + TEST_COMMAND="bats tests" + fi + echo "Running: $TEST_COMMAND in $ADDON_PATH" + cd $ADDON_PATH && $TEST_COMMAND # keepalive-workflow keeps GitHub from turning off tests after 60 days - uses: gautamkrishnar/keepalive-workflow@v2