Skip to content

Commit 71f85f7

Browse files
updated workflow
1 parent 6d7fb69 commit 71f85f7

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

.github/workflows/generate-profiles.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ permissions:
1010
contents: write # Required for pushing changes
1111
pull-requests: write # Required for creating pull requests
1212
packages: read # Required for reading package information
13+
actions: read
1314

1415
jobs:
1516
generate-images:
@@ -39,7 +40,9 @@ jobs:
3940
4041
- name: Generate profile images
4142
env:
42-
IMAGE_TOKEN: ${{ secrets.IMAGE_TOKEN }}
43+
GITHUB_REPOSITORY: ${{ github.repository }}
44+
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN || secrets.IMAGE_TOKEN }}
4346
run: |
4447
# Install required dependencies
4548
npm install node-fetch@2
@@ -52,7 +55,7 @@ jobs:
5255
5356
// Get the API URL from environment variables
5457
const API_URL = process.env.API_URL || 'http://localhost:3000';
55-
const IMAGE_TOKEN = process.env.IMAGE_TOKEN;
58+
const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
5659
5760
async function generateProfileImage(username, userId) {
5861
try {
@@ -61,7 +64,7 @@ jobs:
6164
// First, get the user data from GitHub API
6265
const userResponse = await fetch(`https://api.github.com/users/${username}`, {
6366
headers: {
64-
'Authorization': `token ${IMAGE_TOKEN}`,
67+
'Authorization': `token ${GITHUB_TOKEN}`,
6568
'Accept': 'application/vnd.github.v3+json'
6669
}
6770
});
@@ -73,14 +76,13 @@ jobs:
7376
const userData = await userResponse.json();
7477
7578
// Prepare the data for the OpenReadme API
76-
// Build the API URL with all parameters
7779
const params = new URLSearchParams({
7880
n: userData.name || username,
7981
i: userData.avatar_url || '',
8082
github: username,
8183
x: userData.twitter_username || '',
82-
l: '', // LinkedIn would need to be handled separately
83-
p: userData.blog || userData.html_url,
84+
l: userData.blog || userData.html_url,
85+
p: userData.html_url,
8486
t: 'classic' // Default theme
8587
});
8688
@@ -149,20 +151,19 @@ jobs:
149151
# Run the generation script
150152
MAPPINGS="${{ steps.user-mappings.outputs.mappings }}" \
151153
API_URL="https://openreadme.vercel.app/api/openreadme" \
152-
IMAGE_TOKEN="${{ secrets.IMAGE_TOKEN }}" \
153154
node generate-images.js
154155
155156
- name: Pull latest changes
156157
run: git pull origin main --rebase
157158
- name: Commit and push changes
158159
if: github.event_name == 'workflow_dispatch' || github.ref == 'refs/heads/main'
159160
env:
160-
IMAGE_TOKEN: ${{ secrets.IMAGE_TOKEN }}
161+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN || secrets.IMAGE_TOKEN }}
161162
run: |
162163
git config --global user.name "github-actions[bot]"
163164
git config --global user.email "[email protected]"
164165
git config --global --add safe.directory /github/workspace
165166
git add .
166167
git diff --quiet && git diff --staged --quiet || \
167168
(git commit -m "chore: update profile images [skip ci]" && \
168-
git push https://${{ github.actor }}:$IMAGE_TOKEN@github.com/${{ github.repository }}.git HEAD:main)
169+
git push https://${{ github.actor }}:$GITHUB_TOKEN@github.com/${{ github.repository }}.git HEAD:main)

app/api/openreadme/route.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ async function generateSecureFileName(username: string): Promise<string> {
3232
// Function to log usage statistics (best-effort, non-blocking)
3333
async function logUserGeneration(username: string, githubToken: string): Promise<void> {
3434
try {
35+
const repoOwner = process.env.GITHUB_REPOSITORY_OWNER || 'Open-Dev-Society';
36+
const repoName = process.env.GITHUB_REPOSITORY?.split('/')[1] || 'openreadme';
37+
38+
if (!githubToken) {
39+
console.warn('No GitHub token provided, skipping stats logging');
40+
return;
41+
}
42+
43+
const octokit = new Octokit({ auth: githubToken });
3544
const statsFile = 'stats/usage-log.json';
3645

3746
// Get existing stats
@@ -153,7 +162,7 @@ async function uploadToGitHubSafely(
153162
const rawUrl = data.content.html_url
154163
.replace('https://github.com/', 'https://raw.githubusercontent.com/')
155164
.replace('/blob/', '/');
156-
165+
157166
// Add version to URL to prevent caching issues
158167
return version ? `${rawUrl}?v=${version}` : rawUrl;
159168

0 commit comments

Comments
 (0)