Skip to content

Commit

Permalink
Merge pull request #21 from gregcube/main
Browse files Browse the repository at this point in the history
Tackles issue 10, 11, 16 and 17
  • Loading branch information
lehors authored Oct 10, 2024
2 parents 00e560e + 273ddcf commit 6ece587
Show file tree
Hide file tree
Showing 247 changed files with 32,256 additions and 83 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Deploy

on:
workflow_run:
workflows:
- Test
types:
- completed
workflow_dispatch:
inputs:
environment:
description: 'Deploy to environment'
required: true
type: environment
default: 'Stage'

jobs:
secrets-check:
runs-on: ubuntu-latest
environment: ${{ inputs.environment || 'Production' }}
steps:
- name: Check DEPLOY_HOST
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
run: |
if [ -z "$DEPLOY_HOST" ]; then
echo "DEPLOY_HOST is not set."
exit 1
fi
- name: Check DEPLOY_USER
env:
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
run: |
if [ -z "$DEPLOY_USER" ]; then
echo "DEPLOY_USER is not set."
exit 1
fi
- name: Check DEPLOY_PATH
env:
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
run: |
if [ -z "$DEPLOY_PATH" ]; then
echo "DEPLOY_PATH is not set."
exit 1
fi
- name: Check DEPLOY_KEY
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
run: |
if [ -z "$DEPLOY_KEY" ]; then
echo "DEPLOY_KEY is not set"
exit 1
fi
deploy:
runs-on: ubuntu-latest
needs: secrets-check
environment: ${{ inputs.environment || 'Production' }}
if: ${{ github.event.workflow_run.conclusion == 'success' ||
github.event_name == 'workflow_dispatch' }}

env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}

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

- name: Start ssh-agent and add key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}

- name: Add server to known hosts
run: ssh-keyscan -H $DEPLOY_HOST >> ~/.ssh/known_hosts

- name: Deploy live
run: |
rsync -az --delete \
--exclude '.git' \
--exclude '.github' \
--exclude '.env' \
--exclude 'tests' \
--exclude 'config' \
--exclude 'models/' \
./ $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH
- name: Post-deploy tasks
run: |
ssh $DEPLOY_USER@$DEPLOY_HOST << EOF
echo "Deploying to $DEPLOY_PATH"
cd $DEPLOY_PATH
composer install --no-dev --no-progress --optimize-autoloader
./vendor/bin/drush cr
./vendor/bin/drush updb -y
EOF
102 changes: 102 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
name: Test

on:
push:
branches:
- main
workflow_dispatch:
inputs:
environment:
description: 'Run tests in environment'
required: true
type: environment
default: 'Stage'

jobs:
test:
runs-on: ubuntu-latest

services:
mariadb:
image: mariadb:latest
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: drupal
MYSQL_USER: drupal
MYSQL_PASSWORD: drupal
options: >-
--health-cmd="healthcheck.sh --connect --innodb_initialized"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306

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

- name: PHP setup
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, pdo, mysql, gd, zip, intl, opcache, dom, sqlite3
coverage: none

- name: Apache setup
env:
DOCROOT: ${{ github.workspace }}/web
run: |
sudo usermod -aG docker www-data
sudo apt update
sudo apt install -y -o Dpkg::Options::="--force-confnew" apache2
echo "<VirtualHost *:80>
DocumentRoot $DOCROOT
<Directory $DOCROOT>
AllowOverride all
Require all granted
DirectoryIndex index.php
</Directory>
<FilesMatch \".+\.ph(?:ar|p|tml)$\">
SetHandler \"proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost\"
</FilesMatch>
</VirtualHost>" | sudo tee /etc/apache2/sites-available/000-default.conf
sudo a2enmod proxy_fcgi rewrite
sudo service apache2 stop
sudo service php8.3-fpm stop
sudo service apache2 start
sudo service php8.3-fpm start
- name: Install composer
run: |
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
- name: Validate composer
run: composer validate

- name: Run composer
run: composer install --no-interaction --no-progress --prefer-dist

- name: Create .env file
run: |
echo "DB_NAME=drupal" >> .env
echo "DB_USER=drupal" >> .env
echo "DB_PASS=drupal" >> .env
echo "DB_HOST=127.0.0.1" >> .env
echo "DB_PORT=3306" >> .env
echo "HASH_SALT=$(openssl rand -hex 16)" >> .env
echo "TRUSTED_HOST=localhost" >> .env
- name: Set up Drupal
run: |
cp ./web/sites/default/default.settings.php ./web/sites/default/settings.php
cp ./web/sites/default/default.services.yml ./web/sites/default/services.yml
./vendor/bin/drush site-install mot_profile --yes
- name: Run PHPUnit tests
run: |
php ./web/core/scripts/run-tests.sh \
--dburl mysql://drupal:[email protected]:3306/drupal \
--sqlite /tmp/drupal.sqlite \
--url http://localhost Drupal,Core,Bootstrap,Access
128 changes: 128 additions & 0 deletions .github/workflows/update_models.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Update models

on:
pull_request:
types:
- closed
branches:
- main
workflow_dispatch:
inputs:
environment:
description: 'Create or update models on environment'
required: true
type: environment
default: 'Stage'

jobs:
secrets-check:
runs-on: ubuntu-latest
environment: ${{ inputs.environment || 'Production' }}
steps:
- name: Check DEPLOY_HOST
env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
run: |
if [ -z "$DEPLOY_HOST" ]; then
echo "DEPLOY_HOST is not set."
exit 1
fi
- name: Check DEPLOY_USER
env:
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
run: |
if [ -z "$DEPLOY_USER" ]; then
echo "DEPLOY_USER is not set."
exit 1
fi
- name: Check DEPLOY_PATH
env:
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}
run: |
if [ -z "$DEPLOY_PATH" ]; then
echo "DEPLOY_PATH is not set."
exit 1
fi
- name: Check DEPLOY_KEY
env:
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
run: |
if [ -z "$DEPLOY_KEY" ]; then
echo "DEPLOY_KEY is not set"
exit 1
fi
update-models:
runs-on: ubuntu-latest
needs: secrets-check
environment: ${{ inputs.environment || 'Production' }}

env:
DEPLOY_HOST: ${{ secrets.DEPLOY_HOST }}
DEPLOY_USER: ${{ secrets.DEPLOY_USER }}
DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Start ssh-agent and add key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}

- name: Add server to known hosts
run: ssh-keyscan -H $DEPLOY_HOST >> ~/.ssh/known_hosts

- name: List models on PR merge
if: ${{ github.event_name == 'pull_request' &&
github.event.pull_request.merged == true }}
run: |
git fetch origin main
git diff \
--name-only \
--diff-filter=AM origin/main...${{ github.sha }} | \
grep '^models/.*\.yml$' > models.txt || true
- name: List models on workflow_dispatch
if: github.event_name == 'workflow_dispatch'
run: |
git fetch origin ${{ github.ref_name }}
mkdir tmp
rsync -az \
--include="*.yml" \
--exclude="*" \
$DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/models/ ./tmp/
find tmp/ -maxdepth 1 -type f | while read -r file; do
basefile=$(basename "$file")
if [ -f "models/$basefile" ]; then
git diff --name-only --no-index "$file" "models/$basefile" || true
fi
done > models.txt
rm -rf tmp
- name: Set model sync trigger
id: model_check
run: |
echo "sync=$([ -s models.txt ] && echo true || echo false)" >> $GITHUB_ENV
- name: Sync models
if: ${{ env.sync == 'true' }}
run: |
rsync -az \
--files-from=models.txt \
./ $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/
ssh $DEPLOY_USER@$DEPLOY_HOST << EOF
cd $DEPLOY_PATH
./vendor/bin/drush scr scripts/sync_models.php
./vendor/bin/drush cr
EOF
- name: No changes
if: ${{ env.sync == 'false' }}
run: echo "No model changes detected. Skipping"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
!/web/sites/default/settings.php
.gitattributes
.editorconfig
models/.processed
56 changes: 56 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Contributing Models to the MOT

We welcome contributions to the MOT project in the form of models.

If you'd like to contribute a model, please follow the steps below
to ensure your model is validated and accepted.

## Prerequisites

Before you start contributing, ensure you have the following installed and
set up in your local environment:

- **PHP**: Required to run the validation script.
- **Composer**: Used to manage project dependencies.

If you don’t already have PHP and Composer installed, you can find installation
instructions on their respective websites:
- [PHP Installation](https://www.php.net/manual/en/install.php)
- [Composer Installation](https://getcomposer.org/doc/00-intro.md)

Once you have these tools installed, proceed with the following steps.

## Steps to Contribute a Model

1. **Fork the repository**
- First, fork the main repository to your personal GitHub account.
- Clone the forked repository to your local machine for development.

2. **Add your model**
- Place your model file (`<your-model>.yml`) in the `models` directory of the repository.
- Ensure your model adheres to the schema located at `schema/mof_schema.json`.

3. **Validate your model locally**
- Before creating a Pull Request, validate your model locally to ensure it conforms to the project's rules.
- Run the following command to validate your model:
```
composer install
php scripts/validate-model.php models/<your-model>.yml
```
- This will check for any issues with your model before you submit it.
4. **Submit a pull request**
- Once your model passes local validation, commit your changes and push them to your fork.
- Submit a Pull Request (PR) to the main repository, ensuring the model is in the `models/` directory.
5. **Approval process**
- After submitting your PR, a maintainer will manually review and approve it.
- Once the PR is merged, the GitHub workflow will automatically validate the model again and publish it, provided it passes validation.
## Additional Notes
- Ensure that your model adheres to the schema defined in `schema/mof_schema.json`.
- Running local validation before submitting a PR can save time and ensure quicker approval of your contribution.
Thank you for contributing to the MOT.
Loading

0 comments on commit 6ece587

Please sign in to comment.