Skip to content

Commit

Permalink
Convert to use official github action (#48)
Browse files Browse the repository at this point in the history
* Convert to use office github action

* extract health-check

* improve readability

* add `expect`

---------

Co-authored-by: tyler36 <7234392+tyler36@users.noreply.github.com>
  • Loading branch information
tyler36 and tyler36 committed Feb 1, 2024
1 parent 077a9b9 commit 9dac85f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 66 deletions.
64 changes: 7 additions & 57 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,78 +13,28 @@ on:
description: 'Debug with tmate set "debug_enabled"'
required: false
default: "false"

defaults:
run:
shell: bash

env:
NIGHTLY_DDEV_PR_URL: "https://nightly.link/ddev/ddev/actions/runs/1720215802/ddev-linux-amd64.zip"
# Allow ddev get to use a github token to prevent rate limiting by tests
DDEV_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
tests:
defaults:
run:
shell: bash

strategy:
matrix:
ddev_version: [stable, HEAD]
# ddev_version: [stable, edge, HEAD, PR]
fail-fast: false

runs-on: ubuntu-20.04
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master

- name: Environment setup
run: |
brew install bats-core mkcert
sudo apt-get update >/dev/null && sudo apt-get install -y expect >/dev/null
# Without this .curlrc some linux images don't respect mkcert certs
echo "capath=/etc/ssl/certs/" >>~/.curlrc
mkcert -install
- name: Use ddev stable
if: matrix.ddev_version == 'stable'
run: brew install ddev/ddev/ddev

- name: Use ddev edge
if: matrix.ddev_version == 'edge'
run: brew install ddev/ddev-edge/ddev
- name: Use ddev HEAD
if: matrix.ddev_version == 'HEAD'
run: brew install --HEAD ddev/ddev/ddev

- name: Use ddev PR
if: matrix.ddev_version == 'PR'
run: |
curl -sSL -o ddev_linux.zip ${NIGHTLY_DDEV_PR_URL}
unzip ddev_linux.zip
mv ddev /usr/local/bin/ddev && chmod +x /usr/local/bin/ddev
- name: Download docker images
run: |
mkdir junk && pushd junk && ddev config --auto && ddev debug download-images >/dev/null
docker pull memcached:1.6 >/dev/null
- name: tmate debugging session
uses: mxschmitt/action-tmate@v3
- uses: ddev/github-action-add-on-test@v1
with:
limit-access-to-actor: true
github-token: ${{ secrets.GITHUB_TOKEN }}
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}

- name: tests
run: bats tests

# keepalive-workflow adds a dummy commit if there's no other action here, keeps
# GitHub from turning off tests after 60 days
- uses: gautamkrishnar/keepalive-workflow@v1
if: matrix.ddev_version == 'stable'
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 }}
31 changes: 22 additions & 9 deletions tests/test.bats
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
setup() {
set -eu -o pipefail

# Fail early if old ddev is installed
ddev debug capabilities | grep multiple-dockerfiles >/dev/null || exit 3

export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.."
export TESTDIR=~/tmp/testbrowsersync
export TESTDIR=~/tmp/test-browsersync
mkdir -p "${TESTDIR}"
export PROJNAME=ddev-browsersync
export PROJNAME=test-browsersync
export DDEV_NON_INTERACTIVE=true
ddev delete -Oy ${PROJNAME} >/dev/null || true
cp tests/run-ddev-browsersync "${TESTDIR}"
cd "${TESTDIR}"
ddev config --project-name=${PROJNAME} >/dev/null
ddev config --project-name=${PROJNAME}

# Add simple page to test against.
echo "<html><head></head><body>this is a test</body>" >index.html

ddev start -y

CURLCMD="curl -s --fail"
# I can't currently get curl to trust mkcert CA on macOS
if [[ "$OSTYPE" == "darwin"* ]]; then CURLCMD="curl -s -k --fail"; fi
Expand All @@ -21,19 +27,25 @@ setup() {
teardown() {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
ddev delete -Oy ${PROJNAME} >/dev/null
ddev delete -Oy ${PROJNAME}
[ "${TESTDIR}" != "" ] && rm -rf ${TESTDIR}
}

healthcheck() {
${CURLCMD} https://${PROJNAME}.ddev.site:3000 | grep "this is a test"
}

@test "install from directory" {
set -eu -o pipefail
cd ${TESTDIR}
echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get ${DIR} >/dev/null
ddev restart >/dev/null
ddev get ${DIR}
ddev restart
./run-ddev-browsersync &
sleep 5
${CURLCMD} https://${PROJNAME}.ddev.site:3000 | grep "this is a test"

# Check service works
healthcheck
}

@test "install from release" {
Expand All @@ -44,6 +56,7 @@ teardown() {
ddev restart
./run-ddev-browsersync &
sleep 5
# After https PR goes in, this should be changed to just https
(${CURLCMD} https://${PROJNAME}.ddev.site:3000 || ${CURLCMD} http://${PROJNAME}.ddev.site:3000) | grep "this is a test"

# Check service works
healthcheck
}

0 comments on commit 9dac85f

Please sign in to comment.