120 lines
3.3 KiB
Markdown
120 lines
3.3 KiB
Markdown
# Web/General Formatting Pipeline Template
|
|
|
|
This reusable Gitea Actions workflow provides formatting checks for web technologies and general file formats including JavaScript, TypeScript, JSON, YAML, Markdown, and more using Prettier and other tools.
|
|
|
|
## Features
|
|
|
|
- **Prettier formatting**: Check formatting for JS, TS, JSON, YAML, Markdown, HTML, CSS, and more
|
|
- **YAML validation**: Optional yamllint checking for YAML files
|
|
- **JSON validation**: Optional JSON syntax validation
|
|
- **Configurable**: Skip specific checks, custom prettier config, and more
|
|
|
|
## Usage
|
|
|
|
### Basic Usage
|
|
|
|
Create a workflow file in your repository (e.g., `.gitea/workflows/formatting.yml`):
|
|
|
|
```yaml
|
|
name: Formatting Check
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
|
|
jobs:
|
|
formatting:
|
|
uses: gitea.gt-proj.com/brian/CI-templates/.gitea/workflows/web/formatting.yml@main
|
|
```
|
|
|
|
### Advanced Usage with Custom Options
|
|
|
|
```yaml
|
|
name: Formatting Check
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
|
|
jobs:
|
|
formatting:
|
|
uses: gitea.gt-proj.com/brian/CI-templates/.gitea/workflows/web/formatting.yml@main
|
|
with:
|
|
working-directory: "./frontend"
|
|
node-version: "18"
|
|
prettier-config: ".prettierrc.json"
|
|
check-yaml: true
|
|
check-json: true
|
|
```
|
|
|
|
### Combined with Python Code Quality
|
|
|
|
For repositories that contain both Python and web technologies:
|
|
|
|
```yaml
|
|
name: Code Quality
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
|
|
jobs:
|
|
python-quality:
|
|
uses: gitea.gt-proj.com/brian/CI-templates/.gitea/workflows/python/code-quality.yml@main
|
|
with:
|
|
python-version: "3.12"
|
|
working-directory: "./backend"
|
|
|
|
web-formatting:
|
|
uses: gitea.gt-proj.com/brian/CI-templates/.gitea/workflows/web/formatting.yml@main
|
|
with:
|
|
working-directory: "./frontend"
|
|
check-yaml: true
|
|
```
|
|
|
|
## Input Parameters
|
|
|
|
| Parameter | Description | Required | Default | Type |
|
|
|-----------|-------------|----------|---------|------|
|
|
| `working-directory` | Working directory for the project | No | `"."` | string |
|
|
| `node-version` | Node.js version to use for prettier | No | `"20"` | string |
|
|
| `skip-prettier` | Skip prettier formatting check | No | `false` | boolean |
|
|
| `prettier-config` | Path to prettier config file | No | `""` | string |
|
|
| `check-yaml` | Check YAML files with yamllint | No | `false` | boolean |
|
|
| `check-json` | Check JSON files for validity | No | `false` | boolean |
|
|
|
|
## Prettier Configuration
|
|
|
|
You can customize Prettier behavior by:
|
|
|
|
1. **Using a config file**: Set the `prettier-config` input to point to your config file
|
|
2. **Using default prettier discovery**: Prettier will automatically find `.prettierrc`, `.prettierrc.json`, `.prettierrc.js`, etc.
|
|
3. **Using package.json**: Add prettier config to your `package.json`
|
|
|
|
Example `.prettierrc.json`:
|
|
|
|
```json
|
|
{
|
|
"semi": true,
|
|
"trailingComma": "es5",
|
|
"singleQuote": true,
|
|
"printWidth": 100,
|
|
"tabWidth": 2
|
|
}
|
|
```
|
|
|
|
## What Files Are Checked
|
|
|
|
- **Prettier**: JavaScript, TypeScript, JSON, YAML, Markdown, HTML, CSS, and more
|
|
- **yamllint**: All `.yml` and `.yaml` files (when enabled)
|
|
- **JSON validation**: All `.json` files (when enabled)
|
|
|
|
## Requirements
|
|
|
|
- Repository must be public or you must have access to the template repository
|
|
- For YAML checking: Repository should contain YAML files
|
|
- For JSON checking: Repository should contain JSON files
|