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: |
|
||||
|
||||
Reference in New Issue
Block a user