Skip to content

Commit

Permalink
chore: Use new volto addon development setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof authored Feb 21, 2023
2 parents 53821a9 + 33d3b44 commit fb4d4c5
Show file tree
Hide file tree
Showing 27 changed files with 2,969 additions and 135 deletions.
49 changes: 8 additions & 41 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
@@ -1,56 +1,23 @@
name: Code analysis checks
on: [push]
jobs:
build:
codeanalysis:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
python-version: [3.9]
env:
NAMESPACE: '@plonegovbr'
GIT_NAME: volto-code-block
GIT_USER: 'plonegovbr'
GIT_BRANCH: ${GITHUB_REF##*/}
python-version: [3.8]

steps:
- name: Main checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

# node setup
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

# node cache
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
# node install
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Install yo and @plone/generator-volto
run: npm i -g yo @plone/generator-volto

- name: Setup addon testing environment
run: npx -p @plone/scripts addon clone https://github.com/${{env.GIT_USER}}/${{env.GIT_NAME}}.git --branch ${{env.GIT_BRANCH}}

# ESlint
- name: ESlint
run: cd addon-testing-project && yarn && yarn lint

# Stylelint
- name: Stylelint
run: cd addon-testing-project && yarn && yarn stylelint

# Prettier
- name: Prettier
run: cd addon-testing-project && yarn && yarn prettier:ci
- name: Linting
run: make lint
6 changes: 1 addition & 5 deletions .github/workflows/storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ jobs:
- name: Checkout
uses: actions/[email protected]

- name: Create a new Volto project
run: |
make project
- name: Generate Storybook
run: |
make storybook
Expand All @@ -23,4 +19,4 @@ jobs:
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: addon-testing-project/storybook-static
folder: .storybook
43 changes: 9 additions & 34 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,23 @@
name: Unit tests
name: Unit Tests
on: [push]
jobs:
build:
unit:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
python-version: [3.9]
env:
NAMESPACE: '@plonegovbr'
GIT_NAME: volto-code-block
GIT_USER: 'plonegovbr'
GIT_BRANCH: ${GITHUB_REF##*/}
python-version: [3.8]

steps:
- name: Main checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

# node setup
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'

# node cache
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v1
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
# node install
- name: Install dependencies
run: yarn install --frozen-lockfile

- name: Install yo and @plone/generator-volto
run: npm i -g yo @plone/generator-volto

- name: Setup addon testing environment
run: npx -p @plone/scripts addon clone https://github.com/${{env.GIT_USER}}/${{env.GIT_NAME}}.git --branch ${{env.GIT_BRANCH}}

# Unit tests
- name: Unit tests
run: cd addon-testing-project && yarn && CI=true yarn test
- name: Linting
run: make test-ci
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ node_modules
cypress/videos/
results
build
.storybook
*~
164 changes: 109 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@ SHELL:=bash
MAKEFLAGS+=--warn-undefined-variables
MAKEFLAGS+=--no-builtin-rules

# Project settings

DIR=$(shell basename $$(pwd))
GIT_USER='plonegovbr'
GIT_NAME='volto-code-block'
GIT_BRANCH='main'
ADDON ?= "@plonegovbr/volto-code-block"
CURRENT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))

# Recipe snippets for reuse

Expand All @@ -27,57 +21,117 @@ GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`

PLONE_VERSION=6
VOLTO_VERSION=16.10.0

ADDON_NAME='@plonegovbr/volto-code-block'
ADDON_PATH='volto-code-block'
DEV_COMPOSE=dockerfiles/docker-compose.yml
ACCEPTANCE_COMPOSE=acceptance/docker-compose.yml
CMD=CURRENT_DIR=${CURRENT_DIR} ADDON_NAME=${ADDON_NAME} ADDON_PATH=${ADDON_PATH} VOLTO_VERSION=${VOLTO_VERSION} PLONE_VERSION=${PLONE_VERSION} docker compose
DOCKER_COMPOSE=${CMD} -p ${ADDON_PATH} -f ${DEV_COMPOSE}
ACCEPTANCE=${CMD} -p ${ADDON_PATH}-acceptance -f ${ACCEPTANCE_COMPOSE}

.PHONY: build-backend
build-backend: ## Build
@echo "$(GREEN)==> Build Backend Container $(RESET)"
${DOCKER_COMPOSE} build backend

.PHONY: start-backend
start-backend: ## Starts Docker backend
@echo "$(GREEN)==> Start Docker-based Plone Backend $(RESET)"
${DOCKER_COMPOSE} up backend -d

.PHONY: stop-backend
stop-backend: ## Stop Docker backend
@echo "$(GREEN)==> Stop Docker-based Plone Backend $(RESET)"
${DOCKER_COMPOSE} stop backend

.PHONY: build-addon
build-addon: ## Build Addon dev
@echo "$(GREEN)==> Build Addon development container $(RESET)"
${DOCKER_COMPOSE} build addon-dev
${DOCKER_COMPOSE} build addon-storybook

.PHONY: start-dev
start-dev: ## Starts Dev container
@echo "$(GREEN)==> Start Addon Development container $(RESET)"
${DOCKER_COMPOSE} up addon-dev

.PHONY: start-storybook
start-storybook: ## Starts Storybook
@echo "$(GREEN)==> Start Storybook $(RESET)"
${DOCKER_COMPOSE} up addon-storybook

.PHONY: dev
dev: ## Develop the addon
@echo "$(GREEN)==> Start Development Environment $(RESET)"
make build-backend
make start-backend
make build-addon
make start-dev

# Top-level targets
addon-testing-project/package.json:
npm install -g yo
npm install -g @plone/generator-volto
npm install -g mrs-developer
rm -Rf addon-testing-project
npx -p @plone/scripts addon clone https://github.com/${GIT_USER}/${GIT_NAME}.git --branch ${GIT_BRANCH}
@echo "-------------------"
@echo "$(GREEN)Volto project is ready!$(RESET)"

.PHONY: project
project: addon-testing-project/package.json
@echo "$(RED)Now run: cd addon-testing-project && yarn start$(RESET)"

.PHONY: storybook
storybook: addon-testing-project/package.json
@echo "$(GREEN)Create Storybook$(RESET)"
(cd addon-testing-project && yarn build-storybook)

.PHONY: all
all: project

.PHONY: format-prettier
format-prettier: ## Format Code with Prettier
yarn run prettier:fix

.PHONY: format-stylelint
format-stylelint: ## Format Code with Stylelint
yarn run stylelint:fix

.PHONY: format
format: format-prettier format-stylelint ## Format the codebase according to our standards
.PHONY: help
help: ## Show this help.
@echo -e "$$(grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :)"

# Dev Helpers
.PHONY: i18n
i18n: ## Sync i18n
yarn i18n

.PHONY: i18n-ci
i18n-ci: ## Check if i18n is not synced
yarn i18n && git diff -G'^[^\"POT]' --exit-code
.PHONY: start-test-backend
start-test-backend: ## Start Test Plone Backend
@echo "$(GREEN)==> Start Test Plone Backend$(RESET)"
docker run -i --rm -e ZSERVER_HOST=0.0.0.0 -e ZSERVER_PORT=55001 -p 55001:55001 -e SITE=plone -e APPLY_PROFILES=plone.app.contenttypes:plone-content,plone.restapi:default,plone.volto:default-homepage -e CONFIGURE_PACKAGES=plone.app.contenttypes,plone.restapi,plone.volto,plone.volto.cors -e ADDONS='plone.app.robotframework plone.app.contenttypes plone.restapi plone.volto' plone ./bin/robot-server plone.app.robotframework.testing.PLONE_ROBOT_TESTING
${DOCKER_COMPOSE} run addon-dev i18n

.PHONY: start-backend-docker
start-backend-docker: ## Starts a Docker-based backend
@echo "$(GREEN)==> Start Docker-based Plone Backend$(RESET)"
docker run -it --rm --name=plone -p 8080:8080 -e SITE=Plone plone/plone-backend:6.0.0a4
.PHONY: build-storybook
build-storybook: ## Build storybook
rm -rf .storybook
mkdir .storybook
${DOCKER_COMPOSE} run addon-storybook build-storybook

.PHONY: help
help: ## Show this help.
@echo -e "$$(grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :)"
.PHONY: format
format: ## Format codebase
${DOCKER_COMPOSE} run addon-dev lint:fix
${DOCKER_COMPOSE} run addon-dev prettier:fix
${DOCKER_COMPOSE} run addon-dev stylelint:fix

.PHONY: lint
lint: ## Lint Codebase
${DOCKER_COMPOSE} run addon-dev lint
${DOCKER_COMPOSE} run addon-dev prettier
${DOCKER_COMPOSE} run addon-dev stylelint

.PHONY: test
test: ## Run unit tests
${DOCKER_COMPOSE} run addon-dev test --watchAll

.PHONY: test-ci
test-ci: ## Run unit tests in CI
${DOCKER_COMPOSE} run -e CI=1 addon-dev test

## Acceptance
.PHONY: install-acceptance
install-acceptance: ## Install Cypress, build containers
(cd acceptance && yarn)
${ACCEPTANCE} --profile dev --profile prod build

.PHONY: start-test-acceptance-server
start-test-acceptance-server: ## Start acceptance server
${ACCEPTANCE} --profile dev up -d

.PHONY: start-test-acceptance-server-prod
start-test-acceptance-server-prod: ## Start acceptance server
${ACCEPTANCE} --profile prod up -d

.PHONY: test-acceptance
test-acceptance: ## Start Cypress
(cd acceptance && ./node_modules/.bin/cypress open)

.PHONY: test-acceptance-headless
test-acceptance-headless: ## Run cypress tests in CI
(cd acceptance && ./node_modules/.bin/cypress run)

.PHONY: stop-test-acceptance-server
stop-test-acceptance-server: ## Stop acceptance server
${ACCEPTANCE} down

.PHONY: status-test-acceptance-server
status-test-acceptance-server: ## Status of Acceptance Server
${ACCEPTANCE} ps
16 changes: 16 additions & 0 deletions acceptance/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
node_modules
cypress/videos/
results
build
*~
project
addon-testing-project

# yarn 3
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
File renamed without changes.
36 changes: 36 additions & 0 deletions acceptance/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "3"

services:

addon-acceptance:
build:
context: ../
dockerfile: ./dockerfiles/Dockerfile
args:
ADDON_NAME: "${ADDON_NAME}"
ADDON_PATH: "${ADDON_PATH}"
VOLTO_VERSION: ${VOLTO_VERSION:-16}
environment:
RAZZLE_INTERNAL_API_PATH: http://backend-acceptance:55001/plone
RAZZLE_API_PATH: http://localhost:55001/plone
ports:
- 3000:3000
depends_on:
- backend-acceptance
profiles:
- prod

backend-acceptance:
image: plone/plone-backend:${PLONE_VERSION:-6}
command: ./bin/robot-server plone.app.robotframework.testing.VOLTO_ROBOT_TESTING
environment:
ZSERVER_HOST: 0.0.0.0
ZSERVER_PORT: 55001
ADDONS: 'plone.app.robotframework==2.0.0'
APPLY_PROFILES: plone.app.contenttypes:plone-content,plone.restapi:default,plone.volto:default-homepage
CONFIGURE_PACKAGES: plone.app.contenttypes,plone.restapi,plone.volto,plone.volto.cors
ports:
- 55001:55001
profiles:
- dev
- prod
9 changes: 9 additions & 0 deletions acceptance/cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const { defineConfig } = require('cypress');

module.exports = defineConfig({
viewportWidth: 1280,
e2e: {
baseUrl: 'http://localhost:3000',
specPattern: 'cypress/tests/*.cy.{js,jsx}',
},
});
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit fb4d4c5

Please sign in to comment.