Merge branch 'main' into live #392
Workflow file for this run
This file contains 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
# Name: W3C HTML & CSS Validation | |
# | |
# Description: This GitHub Actions workflow performs HTML and CSS validation using the W3C Validator API and the W3C CSS Validator. It runs on the 'main', 'gh-pages', and 'validation-testing' branches whenever a push event occurs. | |
# | |
# Jobs: | |
# - validate: | |
# - Description: This job runs on the latest version of Ubuntu and performs the following steps: | |
# 1. Checkout code from the repository. | |
# 2. Set up Python environment. | |
# 3. Install dependencies (requests library). | |
# 4. Validate HTML files using the W3C Validator API. | |
# 6. Upload validation results as artifacts. | |
# 7. Fail the workflow if there were validation issues. | |
name: W3C HTML Validation | |
on: | |
push: | |
branches: | |
- main | |
- live | |
jobs: | |
validate: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.12.5" | |
- name: Install dependencies | |
run: | | |
pip install requests | |
- name: Validate HTML with W3C Validator API | |
run: | | |
mkdir -p validation_results | |
validation_failed=0 | |
for file in $(find . -name "*.html"); do | |
echo "Validating $file" | |
response=$(curl -s -F "out=json" -F "content=@$file" https://validator.w3.org/nu/?parser=html5) | |
output_file="validation_results/w3c-validation-$(basename $file .html).json" | |
echo "$response" > "$output_file" | |
errors=$(echo "$response" | python3 -c "import sys, json; data = json.load(sys.stdin); print(len([msg for msg in data['messages'] if msg['type'] in ['error', 'warning']]))") | |
if [ "$errors" -gt 0 ]; then | |
echo "Validation issues found in $file" | |
validation_failed=1 | |
fi | |
done | |
echo "$validation_failed" > validation_results/validation_failed_flag.txt | |
- name: Upload validation results | |
uses: actions/upload-artifact@v4 | |
with: | |
name: validation-results | |
path: validation_results | |
- name: Fail if validation issues found | |
run: | | |
validation_failed=$(cat validation_results/validation_failed_flag.txt) | |
if [ "$validation_failed" -eq 1 ]; then | |
echo "Validation issues found. Failing the workflow." | |
exit 1 | |
else | |
echo "Validation successful." | |
fi |