Skip to content

Commit

Permalink
Merge branch 'feature/DIGITAL-36-validate-action' into feature/digita…
Browse files Browse the repository at this point in the history
…l-27
  • Loading branch information
cathybaptista committed Oct 23, 2024
2 parents 814fe7c + 88bf53f commit 83f8fd3
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 23 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/run-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Run validation with RoboValidate

on:
# Run on any branch so validate branch can always run.
push:
# Commit message validation requires a target branch which is only available in a PR.
pull_request:

jobs:
validate:
runs-on: ubuntu-latest

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
tools: composer:v2
# https://github.com/shivammathur/setup-php?tab=readme-ov-file#disable-coverage
coverage: none

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer

- name: Install Composer dependencies and initialize Robo
run: |
composer install --ignore-platform-reqs --optimize-autoloader --no-progress --no-ansi
# If a Robo command exits with a failure and a RoboFile.php does not exist
# a warning about 'Robo is not initialized here. Please run `robo init` to create a new RoboFile.'
# will be created, which might make users think that is what the error was caused by.
if [ ! -f "RoboFile.php" ]; then
vendor/bin/robo init
fi
- name: Validate a change to any branch
if: github.event_name == 'push'
run: |
# Initialize status variables to 0
status1=0
status2=0
status3=0
# Run all commands and capture their exit statuses
vendor/bin/robo validate:branch-name || status1=$? || status1=0
vendor/bin/robo validate:composer-lock || status3=$? || status3=0
vendor/bin/robo validate:coding-standards || status2=$? || status2=0
# Exit with a non-zero status if any command failed
if [ "$status1" -ne 0 ] || [ "$status2" -ne 0 ] || [ "$status3" -ne 0 ]; then
exit 1
fi
- name: Validate pull requests
if: github.event_name == 'pull_request'
run: |
vendor/bin/robo validate:commit-messages --target-branch="${{ github.base_ref }}" --current-branch="${{ github.head_ref }}"
22 changes: 18 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,22 @@ Simply edit or add new content, then run `./robo.sh drupal-project:export-conten

## Validation

We will soon have validation on branches, commits, composer.lock, and code. I'm waiting until our move to Jira.
* Uses [RoboValidate](https://github.com/mattsqd/robovalidate) to run the various validations.
* Can be run manually locally via: `./robo.sh validate:all`
* Is run when any branch is pushed to GitHub via GitHub Actions. Validation on Git commits is only run remotely when a pull request is made so that only new commits are checked.

To start:
* Follow Drupal & DrupalPractice coding standards.
* Create feature branches in the form `feature/short-description`
### Branch Names

All branches created towards tasks should be in the form `feature/DIGITAL-X-Y`. `X` is the Jira ticket number and `Y` is a short description in lower case separated by dashes.

### Commits

Commit messages must be in the form: `DIGITAL-X:YZ`. `X` is the Jira ticket number, `Y` is a space and `Z` is a short description of the work done.

### Coding Standards

See the [coding standards](https://www.drupal.org/docs/develop/standards) documentation for Drupal. The project validates against the `Drupal` and `DrupalPractice` documentation.

#### IDE

[Enable coding standards help in your IDE](https://www.drupal.org/docs/extending-drupal/contributed-modules/contributed-module-documentation/coder/installing-coder#s-ide-and-editor-configuration) so you're not surprised by a bunch of errors when you push up.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"drush/drush": "^12.5",
"league/commonmark": "^2.5",
"mattsqd/drupal-env": "dev-main",
"mattsqd/drupal-env-lando": "dev-main"
"mattsqd/drupal-env-lando": "dev-main",
"mattsqd/robovalidate": "@alpha"
},
"conflict": {
"drupal/drupal": "*"
Expand Down
53 changes: 51 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions composer.log
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ ae2759e9c45acbf0d8378d04e842d0a8|Matt Poole|develop|Tue Jul 2 13:45:43 EDT 2024
8a86ff66fb8673b6889c9c4b0ab02673|Christian Medders|feature/config-content-types|Fri Oct 11 10:58:09 EDT 2024|./composer.sh require drupal/field_group
4df8b37fbf31532557c120dddc00593b|Cathy Baptista|feature/dg-26-add-paragraphs-to-content-types|Fri Oct 11 12:00:34 EDT 2024|./composer.sh require drupal/paragraphs
834a753fafaa65adba97795d28e5f6b0|Christian Medders|feature/dg-25-enable-auto-complete|Tue Oct 15 14:25:50 EDT 2024|./composer.sh require drupal/inline_entity_form:^3.0@RC
85ee634efd1237c31d3f2d88c373a543|Matt Poole|feature/DIGITAL-36-validate-action|Thu Oct 17 16:16:53 EDT 2024|./composer.sh require mattsqd/robovalidate:@alpha
24 changes: 24 additions & 0 deletions robo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Automatically Generated from 'robo validate:init-robo-yml'.
# See ./vendor/mattsqd/robovalidate/robo.example.yml for additional context.
command:
validate:
options:
project-id: DIGITAL
branch-name:
options:
# These refer to all the possible branch names. There are 4 different types and they will be
# described below. If you'd like to override any of these, you must put all back in that you'd like to
# use, they will not be merged together.
valid-branch-names:
# Matches a branch named 'develop'.
- 'explicit|develop'
# Matches a branch named 'main'.
- 'explicit|main'
# Matches a custom regular expression found in $pattern.
- 'custom|'
# Matches a branch like: hotfix/2.1.3.
- 'semantic|hotfix'
# Matches a branch like (the last number MUST be a 0): release/2.1.0.
- 'semantic_end_0|release'
# Matches a branch named 'stage' (MOD FROM DEFAULTS).
- 'explicit|stage'
20 changes: 10 additions & 10 deletions web/modules/custom/convert_text/src/ConvertText.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ class ConvertText {
* @return string
* The converted text.
*/
static protected function convertText(string $source_text, string $field_type): string {
protected static function convert(string $source_text, string $field_type): string {
// Start by removing space before and after.
$source_text = trim($source_text);
// Remove extra spaces before new lines.
$source_text = preg_replace('/\n\s+n/', "\n", $source_text);

switch ($field_type) {
case 'plain_text':
return html_entity_decode($source_text,ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 , 'UTF-8');
return html_entity_decode($source_text, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8');

case 'html':
$converter = new CommonMarkConverter();
Expand All @@ -49,23 +49,23 @@ static protected function convertText(string $source_text, string $field_type):
* The original source value.
*
* @return string
* The converted text.
* The converted text.
*/
static public function plainText(string $source_text): string {
return self::convertText($source_text, 'plain_text');
public static function plainText(string $source_text): string {
return self::convert($source_text, 'plain_text');
}

/**
* Gets text ready to be stored in html text fields.
*
* @var string $source_text
* The original source value.
* The original source value.
*
* @return string
* The converted text.
* The converted text.
*/
static public function htmlText(string $source_text): string {
return self::convertText($source_text, 'html');
public static function htmlText(string $source_text): string {
return self::convert($source_text, 'html');
}

}
}
4 changes: 2 additions & 2 deletions web/modules/custom/convert_text/src/Form/ConvertTextForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Drupal\convert_text\Form;

use Drupal\convert_text\ConvertText;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\convert_text\ConvertText;

/**
* Provides a Convert Text form.
Expand Down Expand Up @@ -57,7 +57,7 @@ public function buildForm(array $form, FormStateInterface $form_state): array {
'reset' => [
'#type' => 'submit',
'#value' => $this->t('Reset'),
]
],
];

return $form;
Expand Down
8 changes: 4 additions & 4 deletions web/themes/custom/digital_gov/digital_gov.libraries.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Main theme library.
global:
js:
static/dist/js/main.js: { minified: true }
static/dist/js/uswds.js: {}
static/dist/js/uswds-init.js: {}
static/dist/js/main.min.js: { minified: true }
static/dist/js/uswds.min.js: { minified: true }
static/dist/js/uswds-init.min.js: { minified: true }
css:
base:
static/dist/styles.css: { minified: true }
static/dist/styles.min.css: { minified: true }
5 changes: 5 additions & 0 deletions web/themes/custom/digital_gov/digital_gov.theme
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

/**
* @file
* Functions to support theming in the Digital.gov theme.
*/

declare(strict_types=1);

/**
Expand Down
2 changes: 2 additions & 0 deletions web/themes/custom/digital_gov/gulp-includes/gulp/scripts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { src, dest, series } = require("gulp");
const webpack = require("webpack-stream");
const compiler = require("webpack");
const rename = require("gulp-rename");
const TerserPlugin = require('terser-webpack-plugin');

// Directories
Expand Down Expand Up @@ -55,6 +56,7 @@ function compile() {
compiler
)
)
.pipe(rename({ suffix: ".min" }))
.pipe(dest(JS_DEST, { sourcemaps: true }));
}

Expand Down
1 change: 1 addition & 0 deletions web/themes/custom/digital_gov/gulp-includes/gulp/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function buildSass() {
return (
src([`${PROJECT_SASS_SRC}/**/*.scss`])
.pipe(sourcemaps.init({ largeFile: true }))
.pipe(rename({ suffix: ".min" }))
.pipe(
sass({
includePaths: [
Expand Down

0 comments on commit 83f8fd3

Please sign in to comment.