fix: update GitHub mirror action to support fine-grained personal access tokens
- Changed authentication from x-access-token to actual username (required for fine-grained tokens) - Implemented git config url.insteadOf method for better token compatibility - Added comprehensive token type detection and validation - Improved error handling with detailed troubleshooting instructions - Added clear documentation for both classic and fine-grained token setup - Enhanced security by removing credentials from remote URLs - Added automatic git config cleanup after push Required permissions for fine-grained tokens: - Repository access: the-luap/picpeak - Contents: Read and Write - Metadata: Read 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
This commit is contained in:
@@ -9,6 +9,10 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
mirror:
|
mirror:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
# Note: For GitHub fine-grained tokens, ensure the token has:
|
||||||
|
# - Repository access to the-luap/picpeak
|
||||||
|
# - Repository permissions: Contents (Read and Write), Metadata (Read)
|
||||||
|
# For classic tokens: repo scope is sufficient
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@@ -34,7 +38,10 @@ jobs:
|
|||||||
rm -rf photo-sharing-prd.md || true
|
rm -rf photo-sharing-prd.md || true
|
||||||
rm -rf CLAUDE.md || true
|
rm -rf CLAUDE.md || true
|
||||||
rm -rf storage/ || true
|
rm -rf storage/ || true
|
||||||
|
rm -rf events/ || true
|
||||||
|
rm -rf .playwright-mcp/
|
||||||
|
rm -rf .swarm || true
|
||||||
|
rm -rf .claude-flow || true
|
||||||
|
|
||||||
|
|
||||||
echo "Sensitive files removal completed"
|
echo "Sensitive files removal completed"
|
||||||
@@ -57,29 +64,68 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
if [ -z "$GITHUBTOKEN" ]; then
|
if [ -z "$GITHUBTOKEN" ]; then
|
||||||
echo "ERROR: GITHUBTOKEN secret is not set!"
|
echo "ERROR: GITHUBTOKEN secret is not set!"
|
||||||
|
echo "Please add a GitHub Personal Access Token as a secret named GITHUBTOKEN"
|
||||||
|
echo ""
|
||||||
|
echo "For fine-grained tokens:"
|
||||||
|
echo " - Go to GitHub Settings > Developer settings > Personal access tokens > Fine-grained tokens"
|
||||||
|
echo " - Create token with repository access to the-luap/picpeak"
|
||||||
|
echo " - Grant permissions: Contents (Read and Write), Metadata (Read)"
|
||||||
|
echo ""
|
||||||
|
echo "For classic tokens:"
|
||||||
|
echo " - Go to GitHub Settings > Developer settings > Personal access tokens > Tokens (classic)"
|
||||||
|
echo " - Create token with 'repo' scope"
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "GitHub token is available (length: ${#GITHUBTOKEN})"
|
echo "✅ GitHub token is available (length: ${#GITHUBTOKEN})"
|
||||||
|
# Try to detect token type (fine-grained tokens are typically longer)
|
||||||
|
if [ ${#GITHUBTOKEN} -gt 80 ]; then
|
||||||
|
echo "📌 Token appears to be a fine-grained personal access token"
|
||||||
|
else
|
||||||
|
echo "📌 Token appears to be a classic personal access token"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Push to GitHub
|
- name: Push to GitHub
|
||||||
env:
|
env:
|
||||||
GITHUBTOKEN: ${{ secrets.GITHUBTOKEN }}
|
GITHUBTOKEN: ${{ secrets.GITHUBTOKEN }}
|
||||||
|
GIT_TRACE: 1 # Enable Git trace for debugging if needed
|
||||||
run: |
|
run: |
|
||||||
# Remove existing github remote if it exists
|
# Remove existing github remote if it exists
|
||||||
git remote remove github || true
|
git remote remove github || true
|
||||||
|
|
||||||
# Add GitHub remote
|
# Configure Git to use the token for authentication
|
||||||
git remote add github https://x-access-token:${GITHUBTOKEN}@github.com/the-luap/picpeak.git
|
# This method works for both classic and fine-grained tokens
|
||||||
|
git config --global url."https://the-luap:${GITHUBTOKEN}@github.com/".insteadOf "https://github.com/"
|
||||||
|
|
||||||
|
# Add GitHub remote (clean URL without credentials)
|
||||||
|
git remote add github https://github.com/the-luap/picpeak.git
|
||||||
|
|
||||||
# Verify remote was added
|
# Verify remote was added
|
||||||
echo "GitHub remote added:"
|
echo "GitHub remote configuration:"
|
||||||
git remote -v
|
git remote -v
|
||||||
|
|
||||||
# Push to GitHub main branch
|
# Push to GitHub main branch with error handling
|
||||||
echo "Pushing to GitHub..."
|
echo "Pushing to GitHub..."
|
||||||
git push github main --force
|
if git push github main --force 2>&1; then
|
||||||
echo "✅ Push to GitHub completed!"
|
echo "✅ Push to GitHub completed successfully!"
|
||||||
|
else
|
||||||
|
echo "❌ Push to GitHub failed!"
|
||||||
|
echo ""
|
||||||
|
echo "Common issues and solutions:"
|
||||||
|
echo "1. Token permissions: Ensure your token has 'Contents: write' permission"
|
||||||
|
echo "2. Token expiration: Check if your token has expired"
|
||||||
|
echo "3. Repository access: Verify the token has access to the-luap/picpeak repository"
|
||||||
|
echo ""
|
||||||
|
echo "For fine-grained tokens, required permissions:"
|
||||||
|
echo " - Repository access: the-luap/picpeak"
|
||||||
|
echo " - Repository permissions: Contents (Read and Write), Metadata (Read)"
|
||||||
|
echo ""
|
||||||
|
echo "For classic tokens, required scope: 'repo'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Clean up the git config after push
|
||||||
|
git config --global --unset url."https://the-luap:${GITHUBTOKEN}@github.com/".insteadOf
|
||||||
|
|
||||||
- name: Workflow completed
|
- name: Workflow completed
|
||||||
run: |
|
run: |
|
||||||
|
|||||||
Reference in New Issue
Block a user