Skip to content

Commit

Permalink
Initial commit - Cookiex plugin v1.0.0 for wordpress
Browse files Browse the repository at this point in the history
  • Loading branch information
Manoj committed Nov 17, 2024
0 parents commit 32979ba
Show file tree
Hide file tree
Showing 49 changed files with 28,011 additions and 0 deletions.
102 changes: 102 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: CI

on:
push:
tags:
- '*'

jobs:
call-install-deps:
uses: ./.github/workflows/install-deps.yml
with:
mode: 'prod'
secrets: inherit

build:
runs-on: ubuntu-latest
needs: call-install-deps

permissions:
contents: write

steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v2.1.4

- name: Restore Cache
uses: actions/cache/restore@v4
with:
path: |
vendor
node_modules
dist
key: deps-prod-${{ hashFiles('composer.lock') }}-${{ hashFiles('package-lock.json') }}
fail-on-cache-miss: true
id: cache

- name: Set Release Version
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Update Version in WordPress Files
run: |
sed -i -E "s/(const PLUGIN_VERSION = ')[^']*(';)/\1${{ env.RELEASE_VERSION }}\2/" src/Cookiex_CMP.php
sed -i -E 's/([[:blank:]]*\*[[:blank:]]*Version:[[:blank:]]*).*/\1${{ env.RELEASE_VERSION }}/' cookiex-cmp.php
sed -i -E 's/Stable tag: .*/Stable tag: ${{ env.RELEASE_VERSION }}/' README.txt
- name: Update Resources
uses: test-room-7/action-update-file@v1
with:
file-path: |
src/Cookiex_CMP.php
cookiex-cmp.php
README.txt
commit-msg: Update Version in WordPress specific files
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Prepare Release Package
run: |
mkdir cookiex-cmp
rsync -av \
--exclude='.*' \
--exclude='composer.json' \
--exclude='composer.lock' \
--exclude='package.json' \
--exclude='package-lock.json' \
--exclude='**/composer.json' \
--exclude='**/composer.lock' \
--exclude='**/package.json' \
--exclude='**/package-lock.json' \
--exclude='README.md' \
--exclude='build.sh' \
--exclude='phpunit.xml.dist' \
--exclude='phpcs.xml' \
--exclude='phpstan.neon' \
--exclude='phpcs-report.xml' \
--exclude='eslint.config.js' \
--exclude='bud.config.js' \
--exclude='.github' \
--exclude='tests' \
--exclude='bin' \
--exclude='node_modules' \
--exclude='resources' \
./ cookiex-cmp/
shell: bash

- name: Run WordPress Plugin Check
uses: wordpress/plugin-check-action@v1
with:
build-dir: 'cookiex-cmp'

- name: Zip Release Package
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y zip
zip -r cookiex-cmp-${{ env.RELEASE_VERSION }}.zip cookiex-cmp
- name: Release
uses: ncipollo/release-action@v1
with:
allowUpdates: true
omitBodyDuringUpdate: true
artifacts: "cookiex-cmp-${{ env.RELEASE_VERSION }}.zip"
98 changes: 98 additions & 0 deletions .github/workflows/install-deps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Install Dependencies
on:
workflow_call:
inputs:
mode:
description: 'Either dev or prod. Dev will install dev dependencies, prod will remove dev dependencies.'
required: true
default: 'dev'
type: string

jobs:
install-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v2.1.4

- name: Setup php
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'

- name: Cache Composer packages
id: cache-composer
uses: actions/cache@v4
with:
path: vendor
key: composer-${{ inputs.mode }}-${{ hashFiles('composer.lock') }}

- if: steps.cache-composer.outputs.cache-hit != 'true'
name: Validate composer.json and composer.lock
run: composer validate --strict
shell: bash

# Set auth for ressources if required
# - if: steps.cache-composer.outputs.cache-hit != 'true'
# name: Set composer auth
# run: |
# composer config http-basic.connect.advancedcustomfields.com \
# ${{ secrets.ACF_KEY }} https://citation.media
# shell: bash

- if: steps.cache-composer.outputs.cache-hit != 'true'
name: Install Composer dependencies on cache miss
run: |
if [ "${{ inputs.mode }}" = "dev" ]; then
composer install --prefer-dist --no-interaction --no-progress
else
composer install --no-dev --prefer-dist --no-progress --no-suggest --ignore-platform-reqs --optimize-autoloader --classmap-authoritative
fi
shell: bash

- if: steps.cache-composer.outputs.cache-hit == 'true'
name: Rebuild autoload on cache hit
run: |
composer dump-autoload --optimize
shell: bash

# Install node dependencies
- id: cache-npm
uses: actions/cache@v4
with:
path: node_modules
key: npm-dev-${{ hashFiles('package-lock.json') }} # Always -dev- because we need dev dependencies also for build
- name: Install npm dependencies
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci
shell: bash

# Install dev composer resources
# - if: inputs.mode == 'dev'
# name: Set Test Composer authentication (Dev)
# env:
# satispress_key: ${{ secrets.SATISPRESS_KEY }}
# run: |
# if [ "$satispress_key" != '' ]; then
# cd ./tests/setup
# composer config http-basic.plugins.juvo-design.de ${{ secrets.SATISPRESS_KEY }} satispress
# npm run composer:test
# fi
# shell: bash

# Build Assets for production and remove unused dev ressources
- if: inputs.mode == 'prod'
run: |
npm run production
rm -rf node_modules && npm ci --omit=dev
shell: bash

- name: Cache all Deps
id: cache-deps
uses: actions/cache@v4
with:
path: |
vendor
node_modules
dist
key: deps-${{ inputs.mode }}-${{ hashFiles('composer.lock') }}-${{ hashFiles('package-lock.json') }}
64 changes: 64 additions & 0 deletions .github/workflows/test-analyse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Test/Analyse

on:
push:
branches:
- '**'
tags-ignore:
- '**'
pull_request_target:

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

jobs:
call-install-deps:
uses: ./.github/workflows/install-deps.yml
with:
mode: 'dev'
secrets: inherit

test:
runs-on: ubuntu-latest
needs: call-install-deps

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup php
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
tools: cs2pr

- name: Load Cache
uses: actions/cache@v4
with:
path: |
vendor
node_modules
dist
key: deps-dev-${{ hashFiles('composer.lock') }}-${{ hashFiles('package-lock.json') }}
fail-on-cache-miss: true
id: cache

- name: Build assets
run: npm run production

- name: PHPSTAN
run: composer run phpstan:ci

- name: PHPCS
id: phpcs
continue-on-error: true
run: composer run phpcs:ci

- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml --graceful-warnings

# - name: Run integration Tests
# run: |
# npm run test:e2e
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/build/
/vendor/
/node_modules/
setup.sh
.idea
dist/
.budfiles/
/tests/cypress/screenshots/
/tests/cypress/videos/
/tests/setup/plugins
/tests/setup/vendor
bin/*
!bin/.gitkeep
/phpcs-report.xml
cookiex-cmp-[0-9]*.[0-9]*.[0-9]*.zip
74 changes: 74 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributing to CookieX Wordpress Plugin.

We welcome contributions to the CookieX WordPress plugin! This document provides guidelines for contributing to the project.

## Development Setup

1. Clone the repository:
```
git clone https://github.com/cookiex-io/wp-plugin.git
```

2. Install dependencies:
```
composer install
npm install
```

3. Set up the plugin development environment:
- Ensure you have a local WordPress installation.
- Symlink or copy the plugin directory to your WordPress plugins folder.

4. Create a zip file for deployment:
```
./build.sh
```

5. For admin interface development with hot reloading: in resources/admin/js/pages/SettingsPage.tsx, look for and follow the following instruction: "Uncomment following apiFetch for development mode".
You can then:
```
npm run development
```

## Project Structure

- `resources/`: Contains admin interface source files
- `admin/`: Admin-related React components and styles
- `bud.config.js`: Configuration for Bud.js
- `index.php`: Main plugin file

## Coding Standards

- Follow WordPress Coding Standards for PHP.
- Use ESLint for JavaScript and TypeScript.
- Use Prettier for code formatting.

## Making Changes

1. Create a new branch for your feature or bug fix.
2. Make your changes and commit them with a clear, descriptive message.
3. Push your branch and create a pull request.

## Building the Plugin

- Use `npm run build` to create production-ready assets.
- The build process is managed by Bud.js as configured in `bud.config.js`.

## Testing

- Write unit tests for PHP code using PHPUnit.
- For React components, use Jest and React Testing Library.

## Submitting Pull Requests

1. Ensure your code adheres to the project's coding standards.
2. Update documentation if you're changing functionality.
3. Include tests for new features or bug fixes.
4. Make sure all tests pass before submitting.

## Reporting Issues

- Use the GitHub issue tracker to report bugs or suggest features.
- Provide as much detail as possible, including steps to reproduce for bugs.

Thank you for contributing to CookieX wordpress plugin!
Loading

0 comments on commit 32979ba

Please sign in to comment.