Skip to content

Commit

Permalink
feat(*): Add test_command input and exclude release tagged tests for …
Browse files Browse the repository at this point in the history
…pull request (#34)

* feat(test command): Add input for test command and filter by default for pull request

* docs(README): Add test_command input description

* feat(test): Disable history expansion at the top of the step
  • Loading branch information
julienloizelet authored Oct 1, 2024
1 parent abdb628 commit cfd43cb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 39 deletions.
58 changes: 32 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)


<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

**Table of Contents**

- [Quick start](#quick-start)
Expand Down Expand Up @@ -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.
Expand All @@ -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_)
Expand All @@ -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.
Expand All @@ -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`.

Expand All @@ -124,20 +125,18 @@ 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.

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.
Expand All @@ -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:
Expand All @@ -192,7 +202,6 @@ permissions:
jobs:
tests:
strategy:
matrix:
ddev_version: [stable, HEAD]
Expand All @@ -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)
Expand All @@ -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)**
43 changes: 30 additions & 13 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ author: "Julien Loizelet"
description: "A Github Action to run DDEV add-on tests"

inputs:

ddev_version:
type: choice
required: false
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cfd43cb

Please sign in to comment.