Refactor sync workflow to improve token handling and enhance security during public repo push

This commit is contained in:
b267a 2026-01-30 18:57:36 +01:00
parent 0dd5432bb8
commit 4b1406e79a

View file

@ -11,12 +11,16 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check if token is set - name: Check if token is set
env:
TOKEN: ${{ secrets.PUBLIC_REPO_TOKEN }}
run: | run: |
if [ -z "${{ secrets.PUBLIC_REPO_TOKEN }}" ]; then if [ -z "$TOKEN" ]; then
echo "❌ ERROR: PUBLIC_REPO_TOKEN secret is not set!" echo "❌ ERROR: PUBLIC_REPO_TOKEN secret is not set!"
exit 1 exit 1
else else
echo "✅ PUBLIC_REPO_TOKEN is set" echo "✅ PUBLIC_REPO_TOKEN is set"
echo "Token starts with: ${TOKEN:0:4}..."
echo "Token length: ${#TOKEN}"
fi fi
- name: Checkout - name: Checkout
@ -26,7 +30,7 @@ jobs:
- name: Remove sync workflow and push to public repo - name: Remove sync workflow and push to public repo
env: env:
TOKEN: ${{ secrets.PUBLIC_REPO_TOKEN }} GH_TOKEN: ${{ secrets.PUBLIC_REPO_TOKEN }}
run: | run: |
# Configure git # Configure git
git config user.name "github-actions[bot]" git config user.name "github-actions[bot]"
@ -39,6 +43,9 @@ jobs:
git rm .github/workflows/sync-to-public.yml git rm .github/workflows/sync-to-public.yml
git commit -m "Remove sync workflow for public repo" git commit -m "Remove sync workflow for public repo"
# Push to public repo using env var (more secure) # Configure git to use gh for authentication
git remote add public "https://x-access-token:${TOKEN}@github.com/wiestju/anny-booking-automation.git" gh auth setup-git
# Push to public repo
git remote add public https://github.com/wiestju/anny-booking-automation.git
git push public temp-sync-branch:main --force git push public temp-sync-branch:main --force