Skip to content

Commit 0be3966

Browse files
committed
CF worker runtime workflow fixes.
1 parent 05b55e5 commit 0be3966

2 files changed

Lines changed: 38 additions & 8 deletions

File tree

.github/workflows/cloudflare-pages-runtime.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ jobs:
3232
exit 1
3333
fi
3434
35+
- name: 🔒 Verify env file secret exists
36+
run: |
37+
if [ -z "${{ secrets.ENV_FILE_CONTENT }}" ]; then
38+
echo "❌ ENV_FILE_CONTENT secret is missing"
39+
exit 1
40+
fi
41+
3542
- name: 📁 Set Google services environment variable
3643
run: |
3744
echo "$GOOGLE_SERVICES_JSON_BASE64" | base64 -d > /tmp/google-services.json
@@ -45,6 +52,11 @@ jobs:
4552
env:
4653
GOOGLE_SERVICES_JSON_BASE64: ${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}
4754

55+
- name: ⚙️ Create .env file
56+
run: |
57+
printf '%s\n' "${{ secrets.ENV_FILE_CONTENT }}" > .env
58+
echo "" >> .env
59+
4860
- name: 📦 Install pnpm
4961
run: npm install -g pnpm@10
5062

src/server/jobs/reddit.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export async function storeRedditJobPosts(posts: Array<any>) {
107107
// Checks Reddit inbox for new messages and stores them
108108
export async function checkRedditMessages() {
109109
try {
110+
const redditClient = getRedditClient()
110111
const messages = await redditClient.getInbox({ filter: 'messages' })
111112
return await storeMessages(messages)
112113
} catch (error: any) {
@@ -118,14 +119,30 @@ import prisma from '@/server/db'
118119
import { logger } from '@/server/logger'
119120
import { upsertJob } from './jobs'
120121

121-
// Initialize Reddit API client with environment variables
122-
export const redditClient = new Snoowrap({
123-
userAgent: 'CodeBuilder by /u/taofullstack',
124-
clientId: process.env.REDDIT_CLIENT_ID,
125-
clientSecret: process.env.REDDIT_CLIENT_SECRET,
126-
username: process.env.REDDIT_USERNAME,
127-
password: process.env.REDDIT_PASSWORD,
128-
})
122+
function getRedditCredentials() {
123+
const clientId = process.env.REDDIT_CLIENT_ID
124+
const clientSecret = process.env.REDDIT_CLIENT_SECRET
125+
const username = process.env.REDDIT_USERNAME
126+
const password = process.env.REDDIT_PASSWORD
127+
128+
if (!clientId || !clientSecret || !username || !password) {
129+
throw new Error(
130+
'Reddit API credentials are not configured. Set REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USERNAME, and REDDIT_PASSWORD.'
131+
)
132+
}
133+
134+
return {
135+
userAgent: 'CodeBuilder by /u/taofullstack',
136+
clientId,
137+
clientSecret,
138+
username,
139+
password,
140+
}
141+
}
142+
143+
export function getRedditClient() {
144+
return new Snoowrap(getRedditCredentials())
145+
}
129146

130147
/**
131148
* Type guard to determine if a Snoowrap item is a PrivateMessage.
@@ -215,6 +232,7 @@ export function startRedditCommentStream(
215232
onComment: (comment: Snoowrap.Comment) => void,
216233
options: Partial<SnooStormOptions> = {}
217234
) {
235+
const redditClient = getRedditClient()
218236
const stream = new CommentStream(redditClient, {
219237
subreddit,
220238
limit: options.limit || 10,

0 commit comments

Comments
 (0)