diff --git a/.gitea/workflows/auto-sort-files.yml b/.gitea/workflows/auto-sort-files.yml index 56d730a..b8ff289 100644 --- a/.gitea/workflows/auto-sort-files.yml +++ b/.gitea/workflows/auto-sort-files.yml @@ -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: | diff --git a/GITEA-ACTIONS-SETUP.md b/GITEA-ACTIONS-SETUP.md index 6496a11..8d765a6 100644 --- a/GITEA-ACTIONS-SETUP.md +++ b/GITEA-ACTIONS-SETUP.md @@ -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