Convert CI auto-sort system to Gitea Actions

- Move workflow from ci/auto-sort-files.yml to .gitea/workflows/auto-sort-files.yml
- Update workflow to use CI_BOT_TOKEN secret for Gitea authentication
- Configure proper git push URL for Gitea repository
- Update ci/README.md with comprehensive Gitea Actions setup instructions
- Add GITEA-ACTIONS-SETUP.md with detailed configuration guide
- Update README.md to reference Gitea Actions setup documentation
- Remove old GitHub Actions workflow file
- Provide step-by-step token creation and repository secret configuration
- Include troubleshooting guide and security considerations
This commit is contained in:
2025-08-11 10:47:39 +07:00
parent 97096f519d
commit e3b480ec33
4 changed files with 259 additions and 16 deletions

View File

@@ -67,18 +67,46 @@ The workflow can be customized by editing `auto-sort-files.yml`:
## Setup Instructions
### GitHub Actions
1. The workflow file is already configured in `.github/workflows/` (copy from `ci/auto-sort-files.yml`)
2. Ensure repository has appropriate permissions for the action to commit
3. The workflow will run automatically on pushes and pull requests
### Gitea Actions (Recommended)
This template is optimized for Gitea Actions. The workflow is already configured in `.gitea/workflows/auto-sort-files.yml`.
### GitLab CI
#### Required Setup:
1. **Enable Gitea Actions** on your Gitea instance
2. **Create CI Bot Token**:
- Go to your Gitea user settings → Applications → Generate New Token
- Name: `CI Auto-Sort Bot`
- Scopes: `repo` (full repository access)
- Copy the generated token
3. **Add Repository Secret**:
- Go to your repository → Settings → Secrets
- Add new secret: `CI_BOT_TOKEN`
- Value: Paste the token from step 2
4. **Enable Actions**: Go to repository Settings → Actions → Enable Actions
#### Token Configuration:
The workflow uses `${{ secrets.CI_BOT_TOKEN }}` to authenticate git operations. This token must have:
- **Repository access**: Read and write permissions
- **Contents permission**: To commit and push changes
- **Actions permission**: To run workflows
#### Verification:
- Push a test file with DS_ or IMG_ prefix to verify the workflow runs
- Check the Actions tab in your repository for workflow execution logs
- Verify that files are automatically moved to correct directories
### GitHub Actions (Alternative)
If using GitHub instead of Gitea:
1. Copy `.gitea/workflows/auto-sort-files.yml` to `.github/workflows/`
2. Replace `CI_BOT_TOKEN` with `GITHUB_TOKEN` in the workflow
3. Update the push URL to use GitHub's format
### GitLab CI (Alternative)
To adapt for GitLab CI, create `.gitlab-ci.yml`:
```yaml
auto-sort:
stage: organize
script:
- # Copy the bash script from auto-sort-files.yml
- # Copy the bash script from .gitea/workflows/auto-sort-files.yml
only:
- main
- develop

View File

@@ -1,113 +0,0 @@
# CI Auto-Sort Configuration for Datasheets and Images
# This GitHub Actions 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.GITHUB_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"
mv "$src" "$dest"
FILES_MOVED=true
fi
}
# Find and move datasheet files (DS_ prefix)
echo "Searching for datasheet files with DS_ prefix..."
find . -name "DS_*.pdf" -o -name "DS_*.doc" -o -name "DS_*.docx" -o -name "DS_*.txt" | while read file; do
# Skip files already in docs/datasheets/
if [[ "$file" != ./docs/datasheets/* ]]; then
filename=$(basename "$file")
move_file "$file" "docs/datasheets/$filename"
fi
done
# Find and move image files (IMG_ prefix)
echo "Searching for image files with IMG_ prefix..."
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" | while read file; do
# Skip files already in docs/images/
if [[ "$file" != ./docs/images/* ]]; then
filename=$(basename "$file")
move_file "$file" "docs/images/$filename"
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 moved files
if: steps.sort_files.outputs.files_moved == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action Auto-Sort"
git add docs/datasheets/ docs/images/
git commit -m "Auto-sort: Move DS_ and IMG_ prefixed files to correct directories
- Moved datasheet files (DS_*) to docs/datasheets/
- Moved image files (IMG_*) to docs/images/
- Automated by CI auto-sort workflow"
- name: Push changes
if: steps.sort_files.outputs.files_moved == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: Create summary
run: |
echo "## Auto-Sort Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.sort_files.outputs.files_moved }}" = "true" ]; then
echo "✅ Files were automatically moved to correct directories" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Moved Files:" >> $GITHUB_STEP_SUMMARY
echo "- Datasheet files (DS_*) → docs/datasheets/" >> $GITHUB_STEP_SUMMARY
echo "- Image files (IMG_*) → docs/images/" >> $GITHUB_STEP_SUMMARY
else
echo " No files needed to be moved - all files are properly organized" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Supported Prefixes:" >> $GITHUB_STEP_SUMMARY
echo "- **DS_**: Datasheets (PDF, DOC, DOCX, TXT)" >> $GITHUB_STEP_SUMMARY
echo "- **IMG_**: Images (PNG, JPG, SVG, GIF, PDF, WEBP)" >> $GITHUB_STEP_SUMMARY