Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(*): Add test_command input and exclude release tagged tests for pull request #34

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading