Improve Gitea Actions workflow with dynamic repository URL detection
- Update .gitea/workflows/auto-sort-files.yml to dynamically fetch repository URL using git config - Support both HTTPS and SSH repository URL formats automatically - Remove hardcoded repository URL for better portability across different repositories - Add intelligent URL parsing to construct proper authenticated push URL - Update GITEA-ACTIONS-SETUP.md to document dynamic URL detection feature - Improve workflow flexibility for template reuse across different projects
This commit is contained in:
@@ -90,7 +90,24 @@ jobs:
|
||||
- name: Push changes
|
||||
if: steps.sort_files.outputs.files_moved == 'true'
|
||||
run: |
|
||||
git push https://ci-bot:${{ secrets.CI_BOT_TOKEN }}@git.b4l.co.th/B4L/b4l-project-template.git HEAD:${{ github.ref_name }}
|
||||
# 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
|
||||
BASE_URL=$(echo $REPO_URL | sed 's|https://\([^/]*\)/.*|https://\1|')
|
||||
REPO_PATH=$(echo $REPO_URL | sed 's|https://[^/]*/\(.*\)|\1|')
|
||||
PUSH_URL="${BASE_URL}/ci-bot:${{ secrets.CI_BOT_TOKEN }}@${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://ci-bot:${{ secrets.CI_BOT_TOKEN }}@${DOMAIN}/${REPO_PATH}"
|
||||
fi
|
||||
|
||||
echo "Pushing to: $PUSH_URL"
|
||||
git push $PUSH_URL HEAD:${{ github.ref_name }}
|
||||
|
||||
- name: Create summary
|
||||
run: |
|
||||
|
||||
@@ -54,7 +54,7 @@ on:
|
||||
```
|
||||
|
||||
### Authentication Method
|
||||
The workflow uses token-based authentication:
|
||||
The workflow uses token-based authentication and dynamically detects the repository URL:
|
||||
```yaml
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
@@ -62,6 +62,13 @@ The workflow uses token-based authentication:
|
||||
token: ${{ secrets.CI_BOT_TOKEN }}
|
||||
```
|
||||
|
||||
The push operation automatically detects the repository URL:
|
||||
```bash
|
||||
# Get the repository URL dynamically
|
||||
REPO_URL=$(git config --get remote.origin.url)
|
||||
# Supports both HTTPS and SSH repository URLs
|
||||
```
|
||||
|
||||
## 🧪 Testing the Setup
|
||||
|
||||
### 1. Create Test Files
|
||||
|
||||
Reference in New Issue
Block a user