Skip to content
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
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Exclude files from releases/tarballs
tests/ export-ignore
.github/ export-ignore
.gitattributes export-ignore
45 changes: 45 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: 🐞 Bug report or Support Request
description: Create a report to help us improve.
labels: [bug]
body:
- type: checkboxes
attributes:
label: Preliminary checklist
description: Please complete the following checks before submitting an issue.
options:
- label: I am using the latest stable version of DDEV
required: true
- label: I am using the latest stable version of this add-on
required: true
- type: textarea
attributes:
label: Expected Behavior
description: What did you expect to happen?
validations:
required: true
- type: textarea
attributes:
label: Actual Behavior
description: What actually happened instead?
validations:
required: true
- type: textarea
attributes:
label: Steps To Reproduce
description: Specific steps to reproduce the behavior.
placeholder: |
1. In this environment...
2. With this config...
3. Run `...`
4. See error...
validations:
required: false
- type: textarea
attributes:
label: Anything else?
description: |
Links? References? Screenshots? Anything that will give us more context about your issue!

💡 Attach images or log files by clicking this area to highlight it and dragging files in.
validations:
required: false
35 changes: 35 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: 🚀 Feature request
description: Suggest an idea for this project.
labels: [enhancement]
body:
- type: checkboxes
attributes:
label: Is there an existing issue for this?
description: Please search existing issues to see if one already exists for your request.
options:
- label: I have searched the existing issues
required: true
- type: textarea
attributes:
label: Is your feature request related to a problem?
description: Clearly and concisely describe the problem. (Ex. I'm always frustrated when...)
validations:
required: true
- type: textarea
attributes:
label: Describe your solution
description: Clearly and concisely describe what you want to happen.
validations:
required: true
- type: textarea
attributes:
label: Describe alternatives
description: Clearly and concisely describe any alternative solutions or features you've considered.
validations:
required: false
- type: textarea
attributes:
label: Additional context
description: Add any other context or screenshots about the feature request.
validations:
required: false
26 changes: 26 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## The Issue

- Fixes #REPLACE_ME_WITH_RELATED_ISSUE_NUMBER

<!-- Provide a brief description of the issue. -->

## How This PR Solves The Issue

<!-- Describe the key change(s) in this PR that address the issue above. -->

## Manual Testing Instructions

<!-- If this PR changes logic, consider adding additional steps or context to the instructions below. -->

```bash
ddev add-on get https://github.com/DiffyWebsite/ddev-diffy/tarball/refs/pull/REPLACE_ME_WITH_THIS_PR_NUMBER/head
ddev restart
```

## Automated Testing Overview

<!-- Please describe the tests introduced by this PR, or explain why no tests are needed. -->

## Release/Deployment Notes

<!-- Does this affect anything else or have ramifications for other code? Does anything have to be done on deployment? -->
45 changes: 45 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: tests
on:
pull_request:
paths-ignore:
- "**.md"
push:
branches: [ main ]
paths-ignore:
- "**.md"

schedule:
- cron: '25 08 * * *'

workflow_dispatch:
inputs:
debug_enabled:
type: boolean
description: Debug with tmate
required: false
default: false

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
tests:
strategy:
matrix:
ddev_version: [stable, HEAD]
fail-fast: false

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 }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
.idea
.idea
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
[![add-on registry](https://img.shields.io/badge/DDEV-Add--on_Registry-blue)](https://addons.ddev.com)
[![tests](https://github.com/DiffyWebsite/ddev-diffy/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/DiffyWebsite/ddev-diffy/actions/workflows/tests.yml?query=branch%3Amain)
[![last commit](https://img.shields.io/github/last-commit/DiffyWebsite/ddev-diffy)](https://github.com/DiffyWebsite/ddev-diffy/commits)
[![release](https://img.shields.io/github/v/release/DiffyWebsite/ddev-diffy)](https://github.com/DiffyWebsite/ddev-diffy/releases/latest)

# DDEV Diffy

## What is Diffy?
## Overview

Diffy is a visual regression testing service https://diffy.website. It is primary tailored to testing Drupal and WordPress websites.
[Diffy](https://diffy.website) is a visual regression testing service. It is primarily tailored to testing Drupal and WordPress websites.

This repository is a recipe for DDEV to have a local worker that will allow taking screenshots from local website and upload them to Diffy for further comparisons.
This repository is a recipe for [DDEV](https://ddev.com/) to have a local worker that will allow taking screenshots from local website and upload them to Diffy for further comparisons.

## Installation

For DDEV v1.23.5 or above run

```sh
ddev add-on get diffywebsite/ddev-diffy
```bash
ddev add-on get DiffyWebsite/ddev-diffy
ddev restart
```

For earlier versions of DDEV run
After installation, make sure to commit the `.ddev` directory to version control.

```sh
ddev get diffywebsite/ddev-diffy
```
## Usage

Register an account in Diffy and create an [API key](https://app.diffy.website/#/keys).

Once you have your container ready after `ddev restart` we need to provide API key and project ID to `.env` file. For that go to `.ddev/diffy-worker`, copy existing example file `cp .env.example .env` and edit `.env` file to provide your credentials.
Once you have your container ready after `ddev restart`, we need to provide API key and project ID to `.env` file. For that go to `.ddev/diffy-worker`, copy existing example file `cp .env.example .env` and edit `.env` file to provide your credentials:

```bash
cp .ddev/diffy-worker/.env.example .ddev/diffy-worker/.env
ddev dotenv set .ddev/diffy-worker/.env --diffy-api-key=XXX --diffy-project-id=XXX
```

To run the screenshots do `ddev screenshot`. It will produce a URL to your screenshots uploaded to Diffy. Next you can compare them to your any other sets (production, staging, baseline etc.).

Remember to check our [documentation page](https://docs.diffy.website/features/local-development/ddev-add-on).
Remember to check our [documentation page](https://docs.diffy.website/features/local-development/ddev-add-on).

| Command | Description |
| ------- | ----------- |
| `ddev screenshot` | Launch Diffy screenshot |
| `ddev describe` | View service status for Diffy |
| `ddev logs -s diffy` | Check Diffy logs |

## Credits

**Contributed and maintained by [@ygerasimov](https://github.com/ygerasimov)**
4 changes: 2 additions & 2 deletions commands/diffy/screenshot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
#!/usr/bin/env bash
#ddev-generated: If you want to edit and own this file, remove this line.
## Description: Launch Diffy screenshot
## Usage: screenshot
## Example: "ddev screenshot"

node --env-file=.env diffy-screenshots --url=https://web --screenshot-name=$DDEV_HOSTNAME
node --env-file=.env diffy-screenshots --url=https://web --screenshot-name="${DDEV_SITENAME}.${DDEV_TLD}"
16 changes: 10 additions & 6 deletions docker-compose.diffy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
services:
diffy:
container_name: ddev-${DDEV_SITENAME}-diffy
image: 'diffywebsite2/screenshot-worker:0.0.5'
image: diffywebsite2/screenshot-worker:0.0.5
user: '$DDEV_UID:$DDEV_GID'
restart: "no"
# These labels ensure this service is discoverable by ddev.
labels:
com.ddev.site-name: ${DDEV_SITENAME}
com.ddev.approot: $DDEV_APPROOT
com.ddev.approot: ${DDEV_APPROOT}
working_dir: /diffy-worker
environment:
- DDEV_HOSTNAME
- DDEV_SITENAME
- DDEV_TLD
- npm_config_cache=/mnt/ddev-global-cache/npm
volumes:
- ".:/mnt/ddev_config"
- "ddev-global-cache:/mnt/ddev-global-cache"
- "./diffy-worker:/diffy-worker"
- ".:/mnt/ddev_config"
- "ddev-global-cache:/mnt/ddev-global-cache"
- "./diffy-worker:/diffy-worker"
x-ddev:
ssh-shell: bash
33 changes: 21 additions & 12 deletions install.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
# Details about the install.yaml file are at https://ddev.readthedocs.io/en/latest/users/extend/additional-services/#sections-and-features-of-ddev-get-add-on-installyaml

name: ddev-diffy

project_files:
- docker-compose.diffy.yaml
- commands/diffy/screenshot
- config.diffy.yaml
- docker-compose.diffy.yaml
- commands/diffy/screenshot
- config.diffy.yaml

# List of files and directories that are copied into the global .ddev directory
# DDEV environment variables can be interpolated into these filenames
global_files:
ddev_version_constraint: '>= v1.24.10'

# Download the latest version of the worker code
post_install_actions:
- rm -rf diffy-worker && mkdir diffy-worker
- docker run -it --rm -v ./diffy-worker:/diffy-worker --user $DDEV_UID:$DDEV_GID ddev/ddev-utilities bash -c "cd /diffy-worker && wget -qO- https://github.com/DiffyWebsite/diffy-worker/archive/refs/heads/main.tar.gz | tar xz --strip-components=1"
- |
#ddev-description:Download the latest version of the Diffy worker code
# Backup existing .env one level up if it exists
if [ -f diffy-worker/.env ]; then
mv diffy-worker/.env diffy-worker.env.backup
fi
# Recreate directory
rm -rf diffy-worker && mkdir diffy-worker
docker run --rm \
-v ./diffy-worker:/diffy-worker \
--user $DDEV_UID:$DDEV_GID \
ddev/ddev-utilities \
bash -c "cd /diffy-worker && wget -qO- https://github.com/DiffyWebsite/diffy-worker/archive/refs/heads/main.tar.gz | tar xz --strip-components=1"
# Restore .env if backup exists
if [ -f diffy-worker.env.backup ]; then
mv diffy-worker.env.backup diffy-worker/.env
fi

# Shell actions that can be done during removal of the add-on
removal_actions:
- rm -rf diffy-worker
89 changes: 89 additions & 0 deletions tests/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/usr/bin/env bats

# Bats is a testing framework for Bash
# Documentation https://bats-core.readthedocs.io/en/stable/
# Bats libraries documentation https://github.com/ztombol/bats-docs

# For local tests, install bats-core, bats-assert, bats-file, bats-support
# And run this in the add-on root directory:
# bats ./tests/test.bats
# To exclude release tests:
# bats ./tests/test.bats --filter-tags '!release'
# For debugging:
# bats ./tests/test.bats --show-output-of-passing-tests --verbose-run --print-output-on-failure

setup() {
set -eu -o pipefail

# Override this variable for your add-on:
export GITHUB_REPO=DiffyWebsite/ddev-diffy

TEST_BREW_PREFIX="$(brew --prefix 2>/dev/null || true)"
export BATS_LIB_PATH="${BATS_LIB_PATH}:${TEST_BREW_PREFIX}/lib:/usr/lib/bats"
bats_load_library bats-assert
bats_load_library bats-file
bats_load_library bats-support

export DIR="$(cd "$(dirname "${BATS_TEST_FILENAME}")/.." >/dev/null 2>&1 && pwd)"
export PROJNAME="test-$(basename "${GITHUB_REPO}")"
mkdir -p "${HOME}/tmp"
export TESTDIR="$(mktemp -d "${HOME}/tmp/${PROJNAME}.XXXXXX")"
export DDEV_NONINTERACTIVE=true
export DDEV_NO_INSTRUMENTATION=true
ddev delete -Oy "${PROJNAME}" >/dev/null 2>&1 || true
cd "${TESTDIR}"
run ddev config --project-name="${PROJNAME}" --project-tld=ddev.site
assert_success
run ddev start -y
assert_success
}

health_checks() {
# Check that bash is available in the diffy container
run ddev exec -s diffy command -v bash
assert_success
assert_output --partial "bash"

# Check that we have node available for the "ddev screenshot" command
run ddev exec -s diffy command -v node
assert_success
assert_output "/usr/local/bin/node"

# Check if the "ddev screenshot" command exists
run ddev help screenshot
assert_success
assert_output --partial "Launch Diffy screenshot"
}

teardown() {
set -eu -o pipefail
ddev delete -Oy "${PROJNAME}" >/dev/null 2>&1
# Persist TESTDIR if running inside GitHub Actions. Useful for uploading test result artifacts
# See example at https://github.com/ddev/github-action-add-on-test#preserving-artifacts
if [ -n "${GITHUB_ENV:-}" ]; then
[ -e "${GITHUB_ENV:-}" ] && echo "TESTDIR=${HOME}/tmp/${PROJNAME}" >> "${GITHUB_ENV}"
else
[ "${TESTDIR}" != "" ] && rm -rf "${TESTDIR}"
fi
}

@test "install from directory" {
set -eu -o pipefail
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in $(pwd)" >&3
run ddev add-on get "${DIR}"
assert_success
run ddev restart -y
assert_success
health_checks
}

# bats test_tags=release
@test "install from release" {
set -eu -o pipefail
echo "# ddev add-on get ${GITHUB_REPO} with project ${PROJNAME} in $(pwd)" >&3
run ddev add-on get "${GITHUB_REPO}"
assert_success
run ddev restart -y
assert_success
health_checks
}
Empty file added tests/testdata/.gitmanaged
Empty file.