From 29b4ffe5760092c913e7c635c1d7dbb14dc1f125 Mon Sep 17 00:00:00 2001 From: grabowski Date: Mon, 11 Aug 2025 11:31:59 +0700 Subject: [PATCH] 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 --- .gitea/workflows/auto-sort-files.yml | 9 +++++---- GITEA-ACTIONS-SETUP.md | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/auto-sort-files.yml b/.gitea/workflows/auto-sort-files.yml index a8b52ec..9195f40 100644 --- a/.gitea/workflows/auto-sort-files.yml +++ b/.gitea/workflows/auto-sort-files.yml @@ -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 }} diff --git a/GITEA-ACTIONS-SETUP.md b/GITEA-ACTIONS-SETUP.md index 8d765a6..084e9c8 100644 --- a/GITEA-ACTIONS-SETUP.md +++ b/GITEA-ACTIONS-SETUP.md @@ -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