Overview
The GitHub profile README project requires several environment variables and secrets to function properly. These are used for fetching GitHub contribution data and deploying to Cloudflare Workers.Required Secrets
GH_SECRET
A GitHub Personal Access Token (PAT) used to fetch contribution data via the GitHub GraphQL API. Purpose: Authenticates requests tohttps://api.github.com/graphql to retrieve contribution statistics.
How to obtain:
- Go to GitHub Settings > Developer settings > Personal access tokens > Tokens (classic)
- Click Generate new token > Generate new token (classic)
- Give it a descriptive name (e.g., “Profile README Stats”)
- Set an expiration date or choose “No expiration”
- Select the following scopes:
read:user- Read user profile datarepo- Full control of private repositories (if you want to include private contributions)
- Click Generate token
- Copy the token immediately (you won’t be able to see it again)
scripts/stats.ts:71):
CLOUDFLARE_API_TOKEN
Cloudflare API token with permissions to deploy Workers. Purpose: Authenticates GitHub Actions to deploy your worker to Cloudflare. How to obtain:- Log in to your Cloudflare dashboard
- Go to My Profile > API Tokens
- Click Create Token
- Use the Edit Cloudflare Workers template or create a custom token with:
- Permissions:
- Account > Workers Scripts > Edit
- Account > Account Settings > Read
- Permissions:
- (Optional) Set Account Resources to include specific accounts
- (Optional) Set IP Address Filtering for added security
- Click Continue to summary > Create Token
- Copy the token immediately
.github/workflows/deploy.yaml:42):
CLOUDFLARE_ACCOUNT_ID
Your Cloudflare account identifier. Purpose: Specifies which Cloudflare account to deploy the worker to. How to obtain:- Log in to your Cloudflare dashboard
- Select any domain or go to Workers & Pages
- Your Account ID is displayed on the right sidebar under Account ID
- Or find it in the URL:
https://dash.cloudflare.com/<ACCOUNT_ID>/
Setting Up GitHub Secrets
Add these secrets to your GitHub repository:- Go to your repository on GitHub
- Navigate to Settings > Secrets and variables > Actions
- Click New repository secret
- Add each secret:
- Name:
GH_SECRET, Value: Your GitHub Personal Access Token - Name:
CLOUDFLARE_API_TOKEN, Value: Your Cloudflare API token - Name:
CLOUDFLARE_ACCOUNT_ID, Value: Your Cloudflare account ID
- Name:
Local Development
For local development, create a.env file in the project root:
.env file is loaded by the stats generation script:
.env file to version control. It should be in your .gitignore.
Environment Variable Usage
In Scripts
Thescripts/stats.ts file uses GH_SECRET to fetch contribution data:
In GitHub Actions
The workflow files use secrets for automated deployments:Security Best Practices
Token Permissions
- Use the minimum required scopes for GitHub tokens
- Create Cloudflare tokens with specific permissions only
- Set token expiration dates when possible
Token Rotation
- Regularly rotate your API tokens
- Update GitHub secrets after rotation
- Monitor token usage in Cloudflare dashboard
Access Control
- Limit who has access to repository secrets
- Use separate tokens for development and production
- Never log or expose tokens in code or workflows
Troubleshooting
”Failed to fetch contributions” Error
This usually means yourGH_SECRET is invalid or expired:
- Verify the token hasn’t expired
- Check the token has the correct scopes (
read:userand optionallyrepo) - Regenerate the token if necessary
Cloudflare Deployment Failures
If deployment fails with authentication errors:- Verify
CLOUDFLARE_API_TOKENis correct - Check the token has Workers Scripts edit permissions
- Ensure
CLOUDFLARE_ACCOUNT_IDmatches your account
Local Development Issues
Ifpnpm stats fails locally:
- Ensure your
.envfile exists in the project root - Verify
GH_SECRETis set in the.envfile - Check the
.envfile is not in.gitignore(it should be)
Next Steps
- Learn about Cloudflare Workers Deployment
- Configure GitHub Actions Workflows
- Test your setup with
pnpm statslocally