Skip to content

Commit

Permalink
Merge pull request #12 from DaveHogan/feature/bundle-and-validate-gym…
Browse files Browse the repository at this point in the history
…-equip-dataset

Added first pass attempt at bundling and validating gym equipment data
  • Loading branch information
DaveHogan authored Aug 22, 2024
2 parents 10b7b61 + 1064294 commit 60475c0
Show file tree
Hide file tree
Showing 2 changed files with 156 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!--
MAKE SURE TO READ THE CONTRIBUTING GUIDE BEFORE CREATING A PR
https://github.com/DaveHogan/GymDirectoryUK/blob/main/CONTRIBUTING.md
-->

<!-- Provide a general summary of your changes in the Title above -->
<!-- Keep the title short and descriptive, as it will be used as a commit message -->

## Description
<!-- Describe your changes in detail and why. -->
<!-- Note any issues that are resolved by this PR -->
<!-- e.g. resolves #123 or fixes #456. -->

## Type of Changes
<!-- What type of changes does your PR introduce? Put an `x` in only one box that applies best: -->
- [ ] Correction to data
- [ ] New data
- [ ] Other

## Checklist
<!-- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] The PR is submitted to the correct branch (`develop`).
- [ ] My changes follows the code style of this project.
- [ ] I have the rights to share this data and grant rights to the Gym Directory and others to use it freely
131 changes: 131 additions & 0 deletions .github/workflows/validate-and-bundle-gym-equipment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: Validate and Bundle Gym Equipment Data Set

on:
push:
branches:
- main
- '**' # Run on any branch, but only create a release on main

jobs:
validate-and-bundle:
runs-on: ubuntu-latest

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

- name: Validate markdown files
run: |
# Ensure all files in the directory are markdown files
for file in $(find ./data-sets/equipment -type f); do
if [[ "${file}" != *.md ]]; then
echo "Error: $file is not a markdown file."
exit 1
fi
done
# Validate markdown file contents
for file in ./data-sets/equipment/*.md; do
# Ignore files starting with an underscore
if [[ "$(basename "$file")" == _* ]]; then
continue
fi
# Check for required headers
if ! grep -q "^# Equipment:" "$file"; then
echo "Error: $file is missing the '# Equipment:' header."
exit 1
fi
if ! grep -q "^## Description" "$file"; then
echo "Error: $file is missing the '## Description' header."
exit 1
fi
if ! grep -q "^## Equipment Type" "$file"; then
echo "Error: $file is missing the '## Equipment Type' header."
exit 1
fi
# Validate the line after '## Equipment Type' header
if grep -q "^## Equipment Type" "$file"; then
equipment_type_line=$(grep -A 1 "^## Equipment Type" "$file" | tail -n 1)
valid_types=("Cardio" "Resistance" "FreeWeight" "Functional" "Accessory")
valid=false
for type in "${valid_types[@]}"; do
if [[ "$equipment_type_line" == *"$type"* ]]; then
valid=true
break
fi
done
if [ "$valid" = false ]; then
echo "Error: $file has an invalid value under '## Equipment Type'. Must be one of: Cardio, Resistance, FreeWeight, Functional, Accessory."
exit 1
fi
fi
if ! grep -q "^## How To Use" "$file"; then
echo "Error: $file is missing the '## How To Use' header."
exit 1
fi
if ! grep -q "^## Benefits" "$file"; then
echo "Error: $file is missing the '## Benefits' header."
exit 1
fi
if ! grep -q "^## Targeted Muscles" "$file"; then
echo "Error: $file is missing the '## Targeted Muscles' header."
exit 1
fi
if ! grep -q "^## Common Exercises" "$file"; then
echo "Error: $file is missing the '## Common Exercises' header."
exit 1
fi
if ! grep -q "^## Skill Level" "$file"; then
echo "Error: $file is missing the '## Skill Level' header."
exit 1
fi
if ! grep -q "^## Safety Tips" "$file"; then
echo "Error: $file is missing the '## Safety Tips' header."
exit 1
fi
if ! grep -q "^## Alternatives" "$file"; then
echo "Error: $file is missing the '## Alternatives' header."
exit 1
fi
done
- name: Get the current version
id: get_version
run: echo "RELEASE_VERSION=$(date +'%Y.%m.%d.%H%M%S')" >> $GITHUB_ENV

- name: Create a zip file of markdown files
run: |
mkdir -p release
cd ./data-sets/equipment
zip -r ../../release/gym_equipment_dataset_${{ env.RELEASE_VERSION }}.zip ./*.md
cd ../../
- name: Upload zip artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: gym_equipment_dataset
path: ./release/gym_equipment_dataset_${{ env.RELEASE_VERSION }}.zip

- name: Create a new release
if: github.ref == 'refs/heads/main'
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.RELEASE_VERSION }}
release_name: Release ${{ env.RELEASE_VERSION }}
draft: false
prerelease: false
files: ./release/gym_equipment_dataset_${{ env.RELEASE_VERSION }}.zip

0 comments on commit 60475c0

Please sign in to comment.