Skip to content

Commit

Permalink
Add snapshot tests for Fractal
Browse files Browse the repository at this point in the history
  • Loading branch information
opdavies committed Dec 16, 2023
1 parent 2186c29 commit 31ef9b2
Show file tree
Hide file tree
Showing 12 changed files with 273 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tests/Unit/SnapshotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class SnapshotTest extends TestCase
'drupal',
'drupal-commerce-kickstart',
'drupal-localgov',
'fractal',
];

public function testCompareFiles(): void
Expand All @@ -41,10 +42,12 @@ public function testCompareFiles(): void

private function runCliTool(string $config): void
{
$configFilePath = getcwd() . "/tests/snapshots/configs/{$config}.yaml";

$cliCommand = sprintf(
"%s app:generate --config-file %s --output-dir %s",
getcwd() . '/bin/build-configs',
getcwd() . "/tests/snapshots/configs/{$config}.yaml",
$configFilePath,
getcwd() . "/.ignored/snapshots/output/{$config}",
);

Expand Down
15 changes: 15 additions & 0 deletions tests/snapshots/configs/fractal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: docker-fractal
language: javascript
type: fractal

node:
version: 20-bullseye-slim

dockerfile: []

docker-compose:
services:
- node

experimental:
createGitHubActionsConfiguration: true
3 changes: 3 additions & 0 deletions tests/snapshots/output/fractal/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.

README.md
8 changes: 8 additions & 0 deletions tests/snapshots/output/fractal/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.

export DOCKER_UID=1000

export COMPOSE_PROJECT_NAME=docker-fractal
export COMPOSE_PROFILES=node

export DOCKER_WEB_VOLUME=.:/app
27 changes: 27 additions & 0 deletions tests/snapshots/output/fractal/.githooks/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.

# Load the issue ID from an `.issue-id` file within the project and replace the
# `ISSUE_ID` placeholder within a Git commit message.
#
# For example, running `echo "OD-123" > .issue-id` will add `Refs: OD-123` to
# the commit message.
#
# This also works with multiple issue IDs in the same string, e.g.
# "OD-123 OD-456", or IDs on multiple lines.

set -o errexit
set -o nounset
set -o pipefail

PROJECT_DIR=$(git rev-parse --show-toplevel)
ISSUE_FILE="$PROJECT_DIR/.issue-id"

if [ -f "${ISSUE_FILE}" ]; then
ISSUE_IDS=$(cat "${ISSUE_FILE}" | tr '\n' ',' | tr ' ' ',' | sed 's/,$//' | sed 's/,/, /g')

if [ -n "${ISSUE_IDS}" ]; then
sed -i.bak "s/# Refs:/Refs: $ISSUE_IDS/" "$1"
fi
fi
25 changes: 25 additions & 0 deletions tests/snapshots/output/fractal/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI

on:
pull_request:
push:
workflow_dispatch:

env:
COMPOSE_DOCKER_CLI_BUILD: 1
DOCKER_BUILDKIT: 1
DOCKER_UID: 1001

jobs:
build:
name: Build

runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4

- name: Build
run: |
./run ci:build
9 changes: 9 additions & 0 deletions tests/snapshots/output/fractal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.

node_modules

# Docker.
.env
docker-compose.override.yaml


2 changes: 2 additions & 0 deletions tests/snapshots/output/fractal/.hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- DL3059
3 changes: 3 additions & 0 deletions tests/snapshots/output/fractal/.yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.

--modules-folder /node_modules
20 changes: 20 additions & 0 deletions tests/snapshots/output/fractal/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:20-bullseye-slim AS base

WORKDIR /app

RUN mkdir /node_modules \
&& chown node:node -R /app /node_modules

COPY --chown=node:node package*.json *yarn* /app

USER node

################################################################################

FROM base AS build

RUN yarn install --frozen-lockfile

COPY --chown=node:node . .

CMD ["bash"]
44 changes: 44 additions & 0 deletions tests/snapshots/output/fractal/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.

x-proxy: &default-proxy
networks:
- default
- web
labels:
- "traefik.docker.network=traefik_proxy"
- "traefik.http.routers.${COMPOSE_PROJECT_NAME}.rule=Host(
`${COMPOSE_PROJECT_NAME}.localhost`,
)"

x-app: &default-app
volumes:
- "${DOCKER_WEB_VOLUME:-./:/app}"
env_file:
- .env
restart: "${DOCKER_RESTART_POLICY:-unless-stopped}"
networks:
- default
deploy:
resources:
limits:
cpus: "${DOCKER_MYSQL_CPUS:-0}"
memory: "${DOCKER_MYSQL_MEMORY:-0}"
labels:
- "traefik.enabled=false"
tty: true

services:

node:
<<: [*default-proxy, *default-app]
build:
context: .
target: build
volumes:
- .:/app
profiles: [node]

networks:
web:
external: true
name: traefik_proxy
113 changes: 113 additions & 0 deletions tests/snapshots/output/fractal/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/usr/bin/env bash

# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.

set -o errexit
set -o pipefail

PATH="$PATH:./node_modules/.bin"

# If we're running in CI we need to disable TTY allocation for docker compose
# commands that enable it by default, such as exec and run.
TTY="${TTY:-}"
if [[ ! -t 1 ]]; then
TTY="-T"
fi

# Remove and generated or temporary files.
function build {
cmd fractal build "${@}"
}

function ci:build {
cp -v --no-clobber .env.example .env

docker network create traefik_proxy || true

docker compose up -d

build
}

# Remove and generated or temporary files.
function clean {
rm -fr build node_modules
touch build/.keep
}

# Disable Git hooks.
function git-hooks:off {
git config --unset core.hooksPath
}

# Enable Git hooks.
function git-hooks:on {
git config core.hooksPath .githooks
}

# Create a new Fractal component.
function fractal:new {
mkdir -p "components/${1}"

echo "name: ${1}" > "components/${1}/${1}.config.yml"
echo "${1}" > "components/${1}/${1}.twig"
}

# Display a list of all available commands.
function help {
printf "%s <task> [args]\n\nTasks:\n" "${0}"

compgen -A function | grep -v "^_" | cat -n

printf "\nExtended help:\n Each task has comments for general usage\n"
}

# Start the project.
function start {
cp -v --no-clobber .env.example .env
docker compose up -d
}

function sync {
clean
fractal build

aws s3 sync "build/." s3://"${BUCKET_NAME}" \
--acl "public-read" \
--cache-control max-age=3600
}

# Run a command within the node container.
function cmd {
docker compose exec node yarn "${@}"
}

# Stop the project
function stop {
docker compose down
}

# Execute yarn commands.
function yarn {
cmd node yarn "${@}"
}

function _run {
local service="${1}"
local command="${2}"

docker compose run \
--entrypoint "${command}" \
--no-deps \
--rm \
-T \
"${service}" "${@}"
}

# Include any local tasks.
[[ -e run.local ]] && source run.local

TIMEFORMAT=$'\nTask completed in %3lR'
time "${@:-help}"

# vim: ft=bash

0 comments on commit 31ef9b2

Please sign in to comment.