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

Cloudflare CI/CD #443

Closed
wants to merge 7 commits into from
Closed
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
135 changes: 135 additions & 0 deletions .github/workflows/build_job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
on:
workflow_call:
inputs:
network:
required: true
type: string
test:
required: true
type: boolean
account_id:
required: true
type: string
branch:
required: true
type: string
project:
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
env:
NETWORK: ${{ inputs.network }}
steps:
- name: checkout
uses: actions/checkout@v3
- name: build
uses: actions/setup-node@v3
with:
node-version: '16.17.0'
- run: yarn global add @quasar/cli
- run: yarn install
- run: quasar build
- run: mkdir dist/spa/functions && cp -a functions/* dist/spa/functions/
- name: upload
uses: actions/upload-artifact@v3
with:
name: ${{ inputs.network }}-build
path: dist/spa
test:
name: test
runs-on: ubuntu-latest
needs:
- build
if: inputs.test
steps:
- name: checkout
uses: actions/checkout@v3
- name: test
uses: actions/setup-node@v3
- run: yarn install
- run: yarn test
- run: yarn lint

- name: Passed ✅
if: ${{ success() }}
run: |
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"context": "tests",
"state": "success",
"description": "passed ✅",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}'

- name: Failed 🚨
if: ${{ failure() }}
run: |
curl --request POST \
--url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \
--header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
--header 'content-type: application/json' \
--data '{
"context": "tests",
"state": "failure",
"description": "failed 🚨",
"target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}'
publish-tested:
name: publish-tested
runs-on: ubuntu-latest
needs: [build, test]
if: ${{ inputs.test }}
permissions:
contents: read
steps:
- uses: actions/download-artifact@v3
with:
name: ${{ inputs.network }}-build
path: dist/spa
- run: cp -a dist/spa/functions .
- name: publish
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ inputs.account_id }}
projectName: ${{ inputs.project }}
directory: dist/spa
# Optional: Enable this if you want to have GitHub Deployments triggered
# gitHubToken: ${{ secrets.GITHUB_TOKEN }}
# the branch is used for the URL, it does not need to equal the current branch so we can
# use it to set the name in the deployment URL
branch: ${{ inputs.branch }}
publish:
name: publish
runs-on: ubuntu-latest
needs: [ build ]
if: ${{ !inputs.test }}
permissions:
contents: read
steps:
- uses: actions/download-artifact@v3
with:
name: ${{ inputs.network }}-build
path: dist/spa
- run: cp -a dist/spa/functions .
- name: publish
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ inputs.account_id }}
projectName: ${{ inputs.project }}
directory: dist/spa
# Optional: Enable this if you want to have GitHub Deployments triggered
# gitHubToken: ${{ secrets.GITHUB_TOKEN }}
# the branch is used for the URL, it does not need to equal the current branch so we can
# use it to set the name in the deployment URL
branch: ${{ inputs.branch }}




44 changes: 0 additions & 44 deletions .github/workflows/main.yml

This file was deleted.

38 changes: 38 additions & 0 deletions .github/workflows/on_branch_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Push to dev or master: Build, test and deploy"

on:
push:
branches:
- master
- dev

jobs:
checkout:
name: "Checkout"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
mainnet-build:
name: "Mainnet"
needs:
- checkout
uses: ./.github/workflows/build_job.yml
with:
network: mainnet
test: false
account_id: f9b27b4c956187dbae0553f52fd4df64
branch: ${{ github.ref_name == 'master' && 'production' || github.ref_name }}
project: teloscan-mainnet
secrets: inherit
testnet-build:
name: "Testnet"
needs:
- checkout
uses: ./.github/workflows/build_job.yml
with:
network: testnet
test: false
account_id: f9b27b4c956187dbae0553f52fd4df64
branch: ${{ github.ref_name == 'master' && 'production' || github.ref_name }}
project: teloscan-testnet
secrets: inherit
60 changes: 60 additions & 0 deletions .github/workflows/on_pull_request_active.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: "PR: Build, test and deploy previews"

on:
pull_request:

jobs:
checkout:
name: "Checkout"
runs-on: ubuntu-latest
steps:
- name: "Test var ${{ env.ACCOUNT_ID }}"
run: "echo $ACCOUNT_ID"
- uses: actions/checkout@v3
mainnet-build:
name: "Mainnet"
needs:
- checkout
uses: ./.github/workflows/build_job.yml
with:
network: mainnet
test: true
account_id: f9b27b4c956187dbae0553f52fd4df64
branch: pr-${{ github.event.number }}
project: teloscan-mainnet
secrets: inherit
testnet-build:
name: "Testnet"
needs:
- checkout
uses: ./.github/workflows/build_job.yml
with:
network: testnet
test: true
account_id: f9b27b4c956187dbae0553f52fd4df64
branch: pr-${{ github.event.number }}
project: teloscan-testnet
secrets: inherit
comment:
name: "Comment Pull Request"
runs-on: ubuntu-latest
permissions:
pull-requests: write
needs:
- mainnet-build
- testnet-build
steps:
- name: Comment
uses: edumserrano/find-create-or-update-comment@v1
with:
issue-number: ${{ github.event.number }}
body-includes: '<!-- pr-ci-comment -->'
comment-author: 'github-actions[bot]'
body: | # can be a single value or you can compose text with multi-line values
<!-- pr-ci-comment -->
# <span aria-hidden="true">✅</span> Pull Request Deploy Preview Details

**<span aria-hidden="true">🔨</span> Built from SHA**: ${{ github.sha }}
**<span aria-hidden="true">🔍</span> Mainnet Deploy URL**: https://pr-${{ github.event.number }}.teloscan-mainnet.pages.dev
**<span aria-hidden="true">🔍</span> Testnet Deploy URL**: https://pr-${{ github.event.number }}.teloscan-testnet.pages.dev
edit-mode: replace
11 changes: 11 additions & 0 deletions functions/testing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Can migrate this to typescript, likely steps needed:
// - add the functions directory to the tsconfig so it gets compiled
// - change the CI workflow so it copies only the .js files


export function onRequest(context) {
const env = require('../public/env')(context);
console.dir(context);
const apiEndpoint = env.NETWORK_EVM_RPC;
return new Response(`Hello, ${context.env.NETWORK} world!!!!!!!!\n\nNetwork RPC is: ${apiEndpoint}`);
}
5 changes: 3 additions & 2 deletions env.js → public/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ The environment variables ares set based on the single variable `MAINNET=true`
`quasar.config.js`.
*/

// eslint-disable-next-line no-undef

const sharedEnv = {
NETWORK_PROTOCOL: 'https',
NETWORK_PORT: 443,
Expand Down Expand Up @@ -44,6 +46,5 @@ const MAINNET = {
TELOS_ESCROW_CONTRACT_ADDRESS: '0x95F5713A1422Aa3FBD3DCB8D553945C128ee3855',
};

const env = process.env.NETWORK === 'mainnet' ? MAINNET : TESTNET;

module.exports = env;
module.exports = processOrContext => processOrContext === 'mainnet' ? MAINNET : TESTNET;
2 changes: 1 addition & 1 deletion quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/* eslint-env node */

require('dotenv').config();
const env = require('./env');
const env = require('./public/env')(process);
const ESLintPlugin = require('eslint-webpack-plugin');
const nodePolyfillWebpackPlugin = require('node-polyfill-webpack-plugin');

Expand Down
4 changes: 4 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = "wrangler-local"

[vars]
NETWORK="mainnet"