Add configurable worker credentials for git operations

- Replace hardcoded git user email and name with configurable variables
- Add WORKER_EMAIL and WORKER_USERNAME variables for git commits and authentication
- Update workflow to use vars.WORKER_EMAIL and vars.WORKER_USERNAME
- Use WORKER_USERNAME in push URL authentication instead of hardcoded 'ci-bot'
- Update GITEA-ACTIONS-SETUP.md with instructions for setting up repository variables
- Add variables to setup checklist for complete configuration
- Provide flexibility for different organizations and naming conventions
This commit is contained in:
2025-08-11 11:31:59 +07:00
parent 0e800242d7
commit 29b4ffe576
2 changed files with 20 additions and 5 deletions

View File

@@ -83,8 +83,8 @@ jobs:
- name: Commit moved files
if: steps.sort_files.outputs.files_moved == 'true'
run: |
git config --local user.email "ci-bot@b4l.co.th"
git config --local user.name "B4L CI Auto-Sort Bot"
git config --local user.email "${{ vars.WORKER_EMAIL }}"
git config --local user.name "${{ vars.WORKER_USERNAME }}"
git add docs/datasheets/ docs/images/
git commit -m "Auto-sort: Move DS_ and IMG_ prefixed files to correct directories
@@ -103,17 +103,18 @@ jobs:
# 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://ci-bot:${{ secrets.CI_BOT_TOKEN }}@${DOMAIN}/${REPO_PATH}"
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://ci-bot:${{ secrets.CI_BOT_TOKEN }}@${DOMAIN}/${REPO_PATH}"
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 }}"
echo "Pushing to: https://${DOMAIN}/${REPO_PATH} (with authentication)"
git push $PUSH_URL HEAD:${{ github.ref_name }}

View File

@@ -27,7 +27,19 @@ Ensure your Gitea instance has Actions enabled:
- Value: Paste the token from step 2
- Click "Add Secret"
### 4. Enable Repository Actions
### 4. Add Repository Variables
1. **Go to Repository Settings**:
- Navigate to your repository → Settings → Variables
2. **Add Worker Email Variable**:
- Name: `WORKER_EMAIL`
- Value: Email for git commits (e.g., `ci-bot@your-domain.com`)
- Click "Add Variable"
3. **Add Worker Username Variable**:
- Name: `WORKER_USERNAME`
- Value: Username for git commits (e.g., `CI Auto-Sort Bot`)
- Click "Add Variable"
### 5. Enable Repository Actions
1. **Repository Settings**: Go to Settings → Actions
2. **Enable Actions**: Check "Enable Actions"
3. **Allow all actions**: Select appropriate action permissions
@@ -209,6 +221,8 @@ When reporting issues, include:
- [ ] Gitea Actions enabled on instance
- [ ] CI bot token created with `repo` scope
- [ ] `CI_BOT_TOKEN` secret added to repository
- [ ] `WORKER_EMAIL` variable added to repository
- [ ] `WORKER_USERNAME` variable added to repository
- [ ] Repository Actions enabled
- [ ] Test files created and pushed
- [ ] Workflow executed successfully