Implement GitHub Actions for HTML/CSS Validation #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This is a basic workflow to validate HTML and CSS | |
| name: HTML and CSS Validation Workflow | |
| # Controls when the workflow will run | |
| on: | |
| # Triggers the workflow on push or pull request events but only for the "main" branch | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| # Allows you to run this workflow manually from the Actions tab | |
| workflow_dispatch: | |
| # A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
| jobs: | |
| # This workflow contains a single job called "validate_job" | |
| validate_job: | |
| # The type of runner that the job will run on | |
| runs-on: ubuntu-latest | |
| # Steps represent a sequence of tasks that will be executed as part of the job | |
| steps: | |
| # Checks out your repository under $GITHUB_WORKSPACE, so your job can access it | |
| - uses: actions/checkout@v4 | |
| # Sets up Node.js environment | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '16' | |
| # Caching pnpm dependencies | |
| - name: Cache pnpm | |
| uses: actions/cache@v3 | |
| with: | |
| path: ~/.pnpm-store | |
| key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pnpm- | |
| # Installs HTMLHint and Stylelint using pnpm | |
| - name: Install dependencies | |
| run: | | |
| set -e | |
| npm install -g pnpm | |
| pnpm install htmlhint stylelint stylelint-config-standard --save-dev | |
| # Runs HTML validation and logs errors | |
| - name: Validate HTML | |
| run: | | |
| set -e | |
| npx htmlhint . 2> html_validation_errors.log || true | |
| if [ -s html_validation_errors.log ]; then | |
| echo "HTML validation errors found. Check html_validation_errors.log for details." | |
| exit 1 | |
| fi | |
| # Runs CSS validation and logs errors | |
| - name: Validate CSS | |
| run: | | |
| set -e | |
| npx stylelint "**/*.css" 2> css_validation_errors.log || true | |
| if [ -s css_validation_errors.log ]; then | |
| echo "CSS validation errors found. Check css_validation_errors.log for details." | |
| exit 1 | |
| fi | |