-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
2,826 additions
and
8,548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Deploy to Cloudflare Pages | ||
name: Deploy Dev | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Deploy to Cloudflare Pages | ||
name: Deploy Devnet | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Rewards Site | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Authenticate with Google Cloud | ||
uses: google-github-actions/auth@v1 | ||
with: | ||
credentials_json: ${{ secrets.GCP_SA_KEY }} | ||
|
||
- name: Set up Google Cloud SDK | ||
uses: google-github-actions/setup-gcloud@v1 | ||
with: | ||
project_id: ${{ secrets.GCP_PROJECT_ID }} | ||
|
||
- name: Install bun | ||
uses: oven-sh/setup-bun@v1 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: "22" | ||
|
||
- name: Install pnpm | ||
run: npm install -g pnpm | ||
|
||
- name: Install Doppler CLI | ||
run: | | ||
(curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh || wget -t 3 -qO- https://cli.doppler.com/install.sh) | sudo sh | ||
- name: Set up Doppler | ||
run: doppler configure set token ${{ secrets.DEVDEPLOY_DOPPLER_TOKEN }} | ||
|
||
- name: Fetch secrets from Doppler and boot | ||
run: doppler run -- npm run boot | ||
env: | ||
DOPPLER_TOKEN: ${{ secrets.DEVDEPLOY_DOPPLER_TOKEN }} | ||
|
||
- name: Build Next.js app | ||
working-directory: ./apps/rewards-dashboard | ||
run: pnpm run build | ||
env: | ||
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} | ||
|
||
# Step 11: Upload build output to GCS | ||
- name: Upload build output to GCS | ||
run: | | ||
gsutil -m rsync -r -x "^\..*|README.md|gha-creds-.*\.json" ./apps/rewards-dashboard/out gs://${{ secrets.GCS_BUCKET_NAME }} | ||
# Step 12: Set public read access to files | ||
- name: Set public read access to files | ||
run: | | ||
gsutil iam ch allUsers:objectViewer gs://${{ secrets.GCS_BUCKET_NAME }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Website Staging Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- staging # or the branch you want to deploy from | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
environment: website | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install bun | ||
uses: oven-sh/setup-bun@v1 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: "20" # Use the Node.js version compatible with your project | ||
|
||
- name: Install pnpm | ||
run: npm install -g pnpm | ||
|
||
- name: Install Doppler CLI | ||
run: | | ||
(curl -Ls --tlsv1.2 --proto "=https" --retry 3 https://cli.doppler.com/install.sh || wget -t 3 -qO- https://cli.doppler.com/install.sh) | sudo sh | ||
- name: Set up Doppler | ||
run: doppler configure set token ${{ secrets.WEB_DOPPLER_TOKEN }} | ||
|
||
- name: Fetch secrets from Doppler and boot | ||
run: doppler run -- npm run boot | ||
env: | ||
DOPPLER_TOKEN: ${{ secrets.WEB_DOPPLER_TOKEN }} | ||
|
||
- name: Clean up build output | ||
working-directory: ./apps/website/.next | ||
run: | | ||
rm -rf cache | ||
- name: Deploy to Cloudflare Pages | ||
env: | ||
CLOUDFLARE_API_TOKEN: ${{ secrets.WEB_CLOUDFLARE_API_TOKEN }} | ||
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.WEB_CLOUDFLARE_ACCOUNT_ID }} | ||
CLOUDFLARE_PROJECT_NAME: ${{ secrets.WEB_CLOUDFLARE_PROJECT_NAME }} | ||
run: | | ||
npx wrangler pages deploy ./apps/website/out --project-name=$CLOUDFLARE_PROJECT_NAME --branch=main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DISCORD_TOKEN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "next/core-web-vitals" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.yarn/install-state.gz | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## Deployment | ||
|
||
The site is set up to automatically deploy to a bucket in GCP via a Github action found within this repository, to the rewards site project. Within the configuration is a cloud storage bucket called oss-contrib which is referenced by a load balancer named oss-contributions which has a GCP issued SSL cert. | ||
|
||
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). | ||
|
||
## Getting Started | ||
|
||
First, run the development server: | ||
|
||
```bash | ||
npm run dev | ||
# or | ||
yarn dev | ||
# or | ||
pnpm dev | ||
# or | ||
bun dev | ||
``` | ||
|
||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. | ||
|
||
You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file. | ||
|
||
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. | ||
|
||
## Learn More | ||
|
||
To learn more about Next.js, take a look at the following resources: | ||
|
||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. | ||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. | ||
|
||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! | ||
|
||
## Deploy on Vercel | ||
|
||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. | ||
|
||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { promises as fs } from 'fs'; | ||
import path from 'path'; | ||
|
||
const DISCORD_TOKEN = process.env.DISCORD_TOKEN; | ||
|
||
async function fetchDiscordUser(discordUserId) { | ||
const discordAPIBase = 'https://discord.com/api/v10'; | ||
|
||
try { | ||
const response = await fetch(`${discordAPIBase}/users/${discordUserId}`, { | ||
headers: { | ||
Authorization: `Bot ${DISCORD_TOKEN}`, | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorBody = await response.text(); | ||
throw new Error(`Failed to fetch Discord user with ID: ${discordUserId}. Status: ${response.status}. Body: ${errorBody}`); | ||
} | ||
|
||
const data = await response.json(); | ||
return { | ||
username: data?.global_name ?? data?.username, | ||
avatar: data.avatar ? `https://cdn.discordapp.com/avatars/${data.id}/${data.avatar}.png` : null, | ||
}; | ||
} catch (error) { | ||
console.error(`Error fetching Discord user with ID ${discordUserId}:`, error); | ||
return null; | ||
} | ||
} | ||
|
||
async function parseCSVFile(filePath) { | ||
try { | ||
const data = await fs.readFile(filePath, 'utf8'); | ||
const lines = data.trim().split('\n'); | ||
const headers = lines[0].split(','); | ||
return lines.slice(1).map(line => { | ||
const values = line.split(','); | ||
return headers.reduce((obj, header, index) => { | ||
obj[header.trim()] = values[index] ? values[index].trim() : null; | ||
return obj; | ||
}, {}); | ||
}); | ||
} catch (error) { | ||
console.error('Error reading or parsing CSV file:', error); | ||
throw error; | ||
} | ||
} | ||
|
||
export async function GET(req) { | ||
const csvFilePath = path.join(process.cwd(), 'public', 'ambassador_rewards.csv'); | ||
|
||
if (!DISCORD_TOKEN) { | ||
console.error('Bot token not set in environment variables'); | ||
return new Response('Server configuration error: Bot token not set', { status: 500 }); | ||
} | ||
|
||
try { | ||
const ambassadors = await parseCSVFile(csvFilePath); | ||
|
||
const enrichedAmbassadors = await Promise.all( | ||
ambassadors.map(async (ambassador) => { | ||
if (ambassador.id) { | ||
const discordUser = await fetchDiscordUser(ambassador.id); | ||
return { | ||
id: ambassador.id, | ||
username: discordUser?.username ?? 'Unknown', | ||
avatar: discordUser?.avatar ?? null, | ||
wallet_address: ambassador.wallet_address, | ||
rewards: ambassador?.rewards, | ||
contributions: null | ||
}; | ||
} else { | ||
console.warn(`Ambassador ${ambassador.username} has no ID`); | ||
return null; | ||
} | ||
}) | ||
); | ||
|
||
return new Response(JSON.stringify(enrichedAmbassadors), { | ||
status: 200, | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
} catch (error) { | ||
console.error('Error processing ambassadors:', error); | ||
return new Response(JSON.stringify({ error: 'Error processing ambassadors', details: error.message }), { | ||
status: 500, | ||
headers: { 'Content-Type': 'application/json' } | ||
}); | ||
} | ||
} |
Oops, something went wrong.