Skip to content

Commit

Permalink
ci: adjust loading of different env file
Browse files Browse the repository at this point in the history
  • Loading branch information
microHoffman committed Nov 30, 2024
1 parent 210daf1 commit 17c387d
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 14 deletions.
12 changes: 0 additions & 12 deletions .env.example

This file was deleted.

99 changes: 99 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Deploy app
on:
workflow_call:
pull_request:
push:
branches:
- "master"

env:
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Determine environment file
shell: bash
run: |
if [ "$BRANCH_NAME" = "master" ]; then
echo "ENV_FILE=.env.production" >> $GITHUB_ENV
echo "BUILD_COMMAND=bun run build-prod" >> $GITHUB_ENV
else
echo "ENV_FILE=.env.development" >> $GITHUB_ENV
echo "BUILD_COMMAND=bun run build-dev" >> $GITHUB_ENV
fi
- name: Checkout
uses: actions/checkout@v4

- name: Install Node
uses: actions/setup-node@v4
with:
node-version-file: 'package.json'

- uses: oven-sh/setup-bun@v2

- uses: actions/cache@v4
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-${{ matrix.bun }}-bun-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-${{ matrix.bun }}-bun-
- name: Install dependencies
run: bun install --frozen-lockfile

- name: Fill env values with secrets
uses: Langsdorf/env-replace@v1.0.6
with:
file: "~/env/${{ env.ENV_FILE }}"
replace-all: |
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=${{ secrets.NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID }}
NEXT_PUBLIC_ETHEREUM_RPC_URL=${{ secrets.NEXT_PUBLIC_ETHEREUM_RPC_URL }}
NEXT_PUBLIC_SEPOLIA_RPC_URL=${{ secrets.NEXT_PUBLIC_SEPOLIA_RPC_URL }}
NEXT_PUBLIC_WEB3_STORAGE_KEY=${{ secrets.NEXT_PUBLIC_WEB3_STORAGE_KEY }}
NEXT_PUBLIC_ETHERSCAN_API_KEY=${{ secrets.NEXT_PUBLIC_ETHERSCAN_API_KEY }}
- name: Build
run: ${{ env.BUILD_COMMAND }}

- name: Deploy to Cloudflare
id: deploy-cloudflare
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
command: pages deploy .output/public --project-name=pwn-voting-ui --branch=${{ env.BRANCH_NAME }} --commit-hash=${{ github.sha }}

- name: Add comment to PR with deployed URL
if: github.event_name == 'pull_request'
uses: thollander/actions-comment-pull-request@v3
with:
message: |
Deployed on <${{ steps.deploy-cloudflare.outputs.pages-deployment-alias-url }}>!
comment-tag: execution

# TODO make this work!
# - name: Deploy to IPFS
# if: ${{ env.BRANCH_NAME }} == 'master'
# uses: web3-storage/add-to-web3@v3
# id: deploy-ipfs
# with:
# path_to_add: '.output/public'
# proof: './delegation.car'
# secret_key: ${{ secrets.WEB3_STORAGE_KEY }}

# - name: Update DNSLink
# if: ${{ env.BRANCH_NAME }} == 'master'
# env:
# CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
# CLOUDFLARE_ZONE_ID: ${{ secrets.CLOUDFLARE_ZONE_ID }}
# RECORD_DOMAIN: "pwn.xyz"
# RECORD_NAME: "_dnslink.staking"
# uses: PabiGamito/cloudflare-update-dnslink@master
# with:
# cid: ${{ steps.deploy-ipfs.outputs.cid }}


Binary file modified bun.lockb
Binary file not shown.
13 changes: 13 additions & 0 deletions env/.env.app.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Chains
NEXT_PUBLIC_ENABLED_CHAIN_IDS=1,11155111
NEXT_PUBLIC_PREFERRED_CHAIN_ID=11155111

# IPFS
NEXT_PUBLIC_IPFS_ENDPOINTS=https://ipfs.io/ipfs,https://api-staging.pwn.xyz/ipfs,https://gateway.pinata.cloud/ipfs,https://dweb.link/ipfs,https://4everland.io/ipfs

# Secrets
NEXT_PUBLIC_ETHEREUM_RPC_URL=
NEXT_PUBLIC_SEPOLIA_RPC_URL=
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=
NEXT_PUBLIC_WEB3_STORAGE_KEY=
NEXT_PUBLIC_ETHERSCAN_API_KEY=
13 changes: 13 additions & 0 deletions env/.env.app.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Chains
NEXT_PUBLIC_ENABLED_CHAIN_IDS=1
NEXT_PUBLIC_PREFERRED_CHAIN_ID=1

# IPFS
NEXT_PUBLIC_IPFS_ENDPOINTS=https://ipfs.io/ipfs,https://api-staging.pwn.xyz/ipfs,https://gateway.pinata.cloud/ipfs,https://dweb.link/ipfs,https://4everland.io/ipfs

# Secrets
NEXT_PUBLIC_ETHEREUM_RPC_URL=
NEXT_PUBLIC_SEPOLIA_RPC_URL=
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=
NEXT_PUBLIC_WEB3_STORAGE_KEY=
NEXT_PUBLIC_ETHERSCAN_API_KEY=
13 changes: 13 additions & 0 deletions env/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Network and services
NEXT_PUBLIC_ENABLED_CHAIN_IDS=TODO (e.g. 1,11155111)
NEXT_PUBLIC_PREFERRED_CHAIN_ID=TODO (e.g. 11155111)

# ipfs config
NEXT_PUBLIC_IPFS_ENDPOINTS=https://ipfs.io/ipfs,https://api-staging.pwn.xyz/ipfs,https://gateway.pinata.cloud/ipfs,https://dweb.link/ipfs,https://4everland.io/ipfs

# api keys
NEXT_PUBLIC_ETHEREUM_RPC_URL=TODO
NEXT_PUBLIC_SEPOLIA_RPC_URL=TODO
NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=TODO
NEXT_PUBLIC_WEB3_STORAGE_KEY=TODO
NEXT_PUBLIC_ETHERSCAN_API_KEY=TODO
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"scripts": {
"dev": "next dev --port 8080",
"build": "next build",
"build-prod": "env-cmd -f env/.env.app.production bun run build",
"build-dev": "env-cmd -f env/.env.app.development bun run build",
"start": "next start",
"lint": "next lint",
"lint:fix": "bun run lint --fix",
"format": "prettier --check .; echo 'To write the changes: bun run format:fix'",
"format:fix": "prettier -w . --list-different",
"deploy-dao": "bun ./scripts/deploy.ts",
"prepare": "husky",
"test": "bun test",
"ts-check": "tsc --noEmit"
Expand Down Expand Up @@ -52,14 +53,15 @@
"@aragon/osx-commons-configs": "^0.7.0",
"@types/bun": "latest",
"@types/dompurify": "^3.2.0",
"@types/libsodium-wrappers": "^0.7.14",
"@types/node": "^20.17.6",
"@types/react": "^18.3.12",
"@types/libsodium-wrappers": "^0.7.14",
"@types/react-blockies": "^1.4.4",
"@types/react-dom": "^18.3.1",
"@typescript-eslint/eslint-plugin": "latest",
"autoprefixer": "^10.4.20",
"dotenv": "^16.4.5",
"env-cmd": "^10.1.0",
"eslint": "^8.57.1",
"eslint-config-next": "^14.1.4",
"eslint-config-prettier": "^9.1.0",
Expand Down

0 comments on commit 17c387d

Please sign in to comment.