- Replace GITHUB_STEP_SUMMARY with simple echo logging for Gitea compatibility - Remove GitHub-specific step summary features that don't work in Gitea Actions - Convert Create summary step to Log results step with console output - Maintain debug output and step communication for troubleshooting - Ensure workflow is fully compatible with Gitea Actions environment
136 lines
5.2 KiB
YAML
136 lines
5.2 KiB
YAML
# Gitea Actions Auto-Sort Configuration for Datasheets and Images
|
||
# This workflow automatically moves files with specific prefixes to their correct directories
|
||
|
||
name: Auto-Sort Files
|
||
|
||
on:
|
||
push:
|
||
branches: [ main, develop ]
|
||
pull_request:
|
||
branches: [ main ]
|
||
|
||
jobs:
|
||
auto-sort:
|
||
runs-on: ubuntu-latest
|
||
|
||
steps:
|
||
- name: Checkout repository
|
||
uses: actions/checkout@v4
|
||
with:
|
||
fetch-depth: 0
|
||
token: ${{ secrets.CI_BOT_TOKEN }}
|
||
|
||
- name: Auto-sort datasheets and images
|
||
run: |
|
||
#!/bin/bash
|
||
set -e
|
||
|
||
# Flag to track if any files were moved
|
||
FILES_MOVED=false
|
||
|
||
# Function to move files with logging
|
||
move_file() {
|
||
local src="$1"
|
||
local dest="$2"
|
||
local dest_dir=$(dirname "$dest")
|
||
|
||
# Create destination directory if it doesn't exist
|
||
mkdir -p "$dest_dir"
|
||
|
||
# Move file if it's not already in the correct location
|
||
if [ "$src" != "$dest" ] && [ -f "$src" ]; then
|
||
echo "Moving: $src -> $dest"
|
||
# Use git mv to preserve git tracking
|
||
git mv "$src" "$dest"
|
||
return 0 # Success - file was moved
|
||
fi
|
||
return 1 # No file moved
|
||
}
|
||
|
||
# Find and move datasheet files (DS_ prefix)
|
||
echo "Searching for datasheet files with DS_ prefix..."
|
||
mapfile -t datasheet_files < <(find . -name "DS_*.pdf" -o -name "DS_*.doc" -o -name "DS_*.docx" -o -name "DS_*.txt")
|
||
for file in "${datasheet_files[@]}"; do
|
||
if [[ -n "$file" && "$file" != ./docs/datasheets/* ]]; then
|
||
filename=$(basename "$file")
|
||
if move_file "$file" "docs/datasheets/$filename"; then
|
||
FILES_MOVED=true
|
||
fi
|
||
fi
|
||
done
|
||
|
||
# Find and move image files (IMG_ prefix)
|
||
echo "Searching for image files with IMG_ prefix..."
|
||
mapfile -t image_files < <(find . -name "IMG_*.png" -o -name "IMG_*.jpg" -o -name "IMG_*.jpeg" -o -name "IMG_*.svg" -o -name "IMG_*.gif" -o -name "IMG_*.pdf" -o -name "IMG_*.webp")
|
||
for file in "${image_files[@]}"; do
|
||
if [[ -n "$file" && "$file" != ./docs/images/* ]]; then
|
||
filename=$(basename "$file")
|
||
if move_file "$file" "docs/images/$filename"; then
|
||
FILES_MOVED=true
|
||
fi
|
||
fi
|
||
done
|
||
|
||
# Check if any files were moved
|
||
if [ "$FILES_MOVED" = true ]; then
|
||
echo "Files were moved. Setting output for commit step."
|
||
echo "files_moved=true" >> $GITHUB_OUTPUT
|
||
else
|
||
echo "No files needed to be moved."
|
||
echo "files_moved=false" >> $GITHUB_OUTPUT
|
||
fi
|
||
id: sort_files
|
||
|
||
- name: Commit and push moved files
|
||
if: steps.sort_files.outputs.files_moved == 'true'
|
||
run: |
|
||
# Get the repository URL dynamically
|
||
REPO_URL=$(git config --get remote.origin.url)
|
||
|
||
# Extract the base URL and repository path
|
||
if [[ $REPO_URL == https://* ]]; then
|
||
# HTTPS URL format: https://git.b4l.co.th/B4L/repo-name.git
|
||
DOMAIN=$(echo $REPO_URL | sed 's|https://\([^/]*\)/.*|\1|')
|
||
REPO_PATH=$(echo $REPO_URL | sed 's|https://[^/]*/\(.*\)|\1|')
|
||
PUSH_URL="https://${{ vars.WORKER_USERNAME }}:${{ secrets.CI_BOT_TOKEN }}@${DOMAIN}/${REPO_PATH}"
|
||
else
|
||
# SSH URL format: git@git.b4l.co.th:B4L/repo-name.git
|
||
DOMAIN=$(echo $REPO_URL | sed 's|git@\([^:]*\):.*|\1|')
|
||
REPO_PATH=$(echo $REPO_URL | sed 's|git@[^:]*:\(.*\)|\1|')
|
||
PUSH_URL="https://${{ vars.WORKER_USERNAME }}:${{ secrets.CI_BOT_TOKEN }}@${DOMAIN}/${REPO_PATH}"
|
||
fi
|
||
|
||
echo "Repository URL: $REPO_URL"
|
||
echo "Domain: $DOMAIN"
|
||
echo "Repository Path: $REPO_PATH"
|
||
echo "Worker: ${{ vars.WORKER_USERNAME }}"
|
||
|
||
# Commit with inline git configuration and [skip actions] flag
|
||
git -c user.name="${{ vars.WORKER_USERNAME }}" -c user.email="${{ vars.WORKER_EMAIL }}" commit -m "Auto-sort: Move DS_ and IMG_ prefixed files to correct directories [skip actions]
|
||
|
||
- Moved datasheet files (DS_*) to docs/datasheets/
|
||
- Moved image files (IMG_*) to docs/images/
|
||
- Automated by Gitea Actions auto-sort workflow"
|
||
|
||
echo "Pushing to: https://${DOMAIN}/${REPO_PATH} (with authentication)"
|
||
git push $PUSH_URL HEAD:${{ github.ref_name }}
|
||
|
||
- name: Log results
|
||
run: |
|
||
# Check if files were moved by looking at the output from sort_files step
|
||
FILES_MOVED_OUTPUT="${{ steps.sort_files.outputs.files_moved }}"
|
||
echo "Auto-Sort Results:"
|
||
echo "Debug: files_moved output = '$FILES_MOVED_OUTPUT'"
|
||
|
||
if [ "$FILES_MOVED_OUTPUT" = "true" ]; then
|
||
echo "✅ Files were automatically moved to correct directories"
|
||
echo "- Datasheet files (DS_*) → docs/datasheets/"
|
||
echo "- Image files (IMG_*) → docs/images/"
|
||
else
|
||
echo "ℹ️ No files needed to be moved - all files are properly organized"
|
||
fi
|
||
|
||
echo "Supported Prefixes:"
|
||
echo "- DS_: Datasheets (PDF, DOC, DOCX, TXT)"
|
||
echo "- IMG_: Images (PNG, JPG, SVG, GIF, PDF, WEBP)"
|