Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a basic CI deployments #4

Merged
merged 3 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
name: CI

on:
# build on PR creation/updates, also when pushing to main/develop, or create a release
pull_request:
types: [opened, synchronize]
push:
branches: [main, develop]
tags: [v*]

# env:
# REPO_NAME_SLUG: token-lists
# PR_NUMBER: ${{ github.event.number }}
# REACT_APP_PINATA_API_KEY: ${{ secrets.REACT_APP_PINATA_API_KEY }}
# REACT_APP_PINATA_SECRET_API_KEY: ${{ secrets.REACT_APP_PINATA_SECRET_API_KEY }}

jobs:
setup:
name: Setup
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up node
uses: actions/setup-node@v2
with:
node-version: lts/*

- name: Set output of cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- name: Cache yarn cache
uses: actions/cache@v2
id: cache-yarn-cache
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules1-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.node-version }}-nodemodules1-

- name: Install dependencies
run: yarn install --frozen-lockfile


build:
name: Build apps
needs: setup
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up node
uses: actions/setup-node@v2
with:
node-version: lts/*

- name: Load dependencies
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: ${{ runner.os }}-${{ matrix.node-version }}-nodemodules1-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.node-version }}-nodemodules1-


- name: Build
run: yarn build

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: token-lists
path: build



deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Download Artifacts
uses: actions/download-artifact@v2

# TODO: Uncomment in future PR
# - name: Configure AWS credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: ${{ secrets.AWS_REGION }}

# - name: 'Deploy to S3: PRaul'
# if: env.PR_NUMBER
# run: aws s3 sync token-list/lists s3://${{ secrets.AWS_REVIEW_BUCKET_NAME }}/${{ env.REPO_NAME_SLUG }}/pr${{ env.PR_NUMBER }} --delete

# - name: 'PRaul: Comment PR with app URLs'
# uses: mshick/add-pr-comment@v1
# with:
# message: |
# * **🔭 [GP Swap](${{ env.REVIEW_FEATURE_URL }})**: CoW Protocol v2 Swap UI
# repo-token: ${{ secrets.GITHUB_TOKEN }}
# repo-token-user-login: 'github-actions[bot]'
# if: env.PR_NUMBER
# env:
# REVIEW_FEATURE_URL: https://pr${{ env.PR_NUMBER }}--${{ env.REPO_NAME_SLUG }}.review.gnosisdev.com

# - name: 'Deploy to S3: Develop'
# if: github.ref == 'refs/heads/develop'
# run: aws s3 sync website s3://${{ secrets.AWS_DEV_BUCKET_NAME }} --delete

# - name: 'Deploy to S3: Staging'
# if: github.ref == 'refs/heads/main'
# run: aws s3 sync website s3://${{ secrets.AWS_STAGING_BUCKET_NAME }}/current --delete

# - name: Get the version
# id: get_version
# run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3)

# - name: 'Production deployment: Upload release build files to be deployed'
# if: startsWith(github.ref, 'refs/tags/v')
# run: aws s3 sync website s3://${{ secrets.AWS_STAGING_BUCKET_NAME }}/releases/${{ steps.get_version.outputs.VERSION }} --delete

# - name: 'Production deployment: Enable production deployment'
# if: success() && startsWith(github.ref, 'refs/tags/v')
# run: bash ./.github/scripts/prepare_production_deployment.sh
# env:
# PROD_DEPLOYMENT_HOOK_TOKEN: ${{ secrets.PROD_DEPLOYMENT_HOOK_TOKEN }}
# PROD_DEPLOYMENT_HOOK_URL: ${{ secrets.PROD_DEPLOYMENT_HOOK_URL }}
# VERSION_TAG: ${{ steps.get_version.outputs.VERSION }}

13 changes: 12 additions & 1 deletion src/coingecko.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ const PAGE_LIMIT = 50
const FILE_PREFIX = 'coingecko'
const OUTPUT_FILE = "CoinGecko.json"

// Prevent rate-limit issues https://www.coingecko.com/en/api/documentation
const WAIT_TIME_BETWEEN_REQUEST = 2000

async function fetchCoingeckoTop(limit, page) {
console.log(`Fetch page CoinGecko's Tokens, sorted by Market Cap: Page ${page} (${limit} results)`)
const url = `https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=${limit}&page=${page}&sparkline=false&category=ethereum-ecosystem`;
const res = await fetch(url);
if (!res.ok) {
throw new Error(`Error fetching page ${page}. Error: ${res.status}, Message: ${await res.text()}`)
}
const json = await res.json();
return json;
}
Expand All @@ -29,6 +35,10 @@ async function writeJson(filePath, data) {
fs.writeFileSync(filePath, data)
}

function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

function createSortMap(tokens) {
return tokens.reduce((r, e, i) => {
r[e.symbol.toLowerCase()] = i;
Expand Down Expand Up @@ -80,7 +90,7 @@ async function writeCoingeckoListFile(version) {
}

async function fetchTokens(page, limit, allTokens) {
const tokens = await fetchCoingeckoTop(limit, page);
const tokens = await fetchCoingeckoTop(limit, page); // TODO: We need to map this tokens to an enhanced version

const filteredTokens = allTokens.tokens.filter((c) =>
tokens.some((t) => t.symbol.toLowerCase() === c.symbol.toLowerCase())
Expand Down Expand Up @@ -110,6 +120,7 @@ async function main() {

for (let page=1; page<=5; page++) {
await fetchTokens(page, PAGE_LIMIT, allTokens)
await sleep(WAIT_TIME_BETWEEN_REQUEST)
}
await writeCoingeckoListFile({ patch: 1 }); // TODO: Improve versioning of the file
}
Expand Down
Loading