fix #150
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
name: Node.js CI | |
on: | |
push: | |
branches: | |
- dev | |
pull_request: | |
branches: | |
- dev | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
env: | |
NETWORK: optimism_goerli | |
MNEMONIC: ${{ secrets.OPTIMISM_GOERLI_MNEMONIC }} | |
RPC_URL: ${{ secrets.OPTIMISM_GOERLI_RPC_URL }} | |
WSS_URL: ${{ secrets.OPTIMISM_GOERLI_WSS_URL }} | |
VALIDATORS: '0x7CE0Df86148326Bb6C417D7Bbf54fcEBcaD90821' | |
GAS_PRICE: 10 | |
GAS_LIMIT: 2800000 | |
DAPP_NAME: chessAppNew | |
BLOCK_CONFIRMATIONS: 1 | |
BLOCK_CONFIRMATIONS_TX: 2 | |
CHAIN_ID: 420 | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- os: self-hosted | |
node-version: 14 | |
steps: | |
- name: Build environment information | |
run: 'echo "Matrix OS: ${{ matrix.os }} on $HOSTNAME with $(getconf _NPROCESSORS_ONLN) cores"' | |
- name: Checkout main repo | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# Check for changes in /front, /deployments, and other files | |
- name: Check for changes in /front, /deployments, and other files | |
id: check-changes | |
run: | | |
FRONT_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^front/') || true | |
DEPLOYMENTS_CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '^deployments/') || true | |
OTHER_CHANGES=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -v '^front/' | grep -v '^deployments/' | grep -v '^\.workflow/' | grep -v '^nginx.conf' | grep -v '^\.gitignore') || true | |
echo "front-changed=$(if [ -z "$FRONT_CHANGED" ]; then echo false; else echo true; fi)" >> $GITHUB_ENV | |
echo "deployments-changed=$(if [ -z "$DEPLOYMENTS_CHANGED" ]; then echo false; else echo true; fi)" >> $GITHUB_ENV | |
echo "app-changed=$(if [ -z "$OTHER_CHANGES" ]; then echo false; else echo true; fi)" >> $GITHUB_ENV | |
# Prepare node | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
# # Install Docker | |
# - name: Install Docker | |
# run: | | |
# curl -fsSL https://get.docker.com -o get-docker.sh | |
# sudo sh get-docker.sh | |
# sudo usermod -aG docker $USER | |
# newgrp docker | |
# Restore node modules | |
- name: Restore node modules | |
id: restore-node | |
uses: actions/cache@v3 | |
with: | |
path: | | |
front/node_modules | |
key: node-install-${{ matrix.node-version }}-${{ hashFiles('front/package.json', 'front/package-lock.json') }} | |
# Restore dapp artifacts | |
- name: Restore dapp artifacts | |
id: restore-artifacts | |
uses: actions/cache@v3 | |
with: | |
path: | | |
deployments/localhost | |
export | |
key: restore-artifacts-${{ hashFiles('docker-compose-deploy.yml', 'docker-compose.override.yml') }} | |
# Install dependencies | |
- name: Install Yarn | |
run: npm install -g yarn | |
# # Prepare Nginx | |
# - name: Reset Nginx configurations and install Nginx | |
# run: | | |
# sudo rm -rf /etc/nginx/sites-available/default | |
# sudo rm -rf /etc/nginx/sites-enabled/default | |
# sudo apt-get update | |
# sudo apt-get install --reinstall -y nginx | |
# # Create a minimal nginx.conf | |
# echo 'events { | |
# worker_connections 1024; | |
# } | |
# http { | |
# include /etc/nginx/mime.types; | |
# default_type application/octet-stream; | |
# sendfile on; | |
# access_log /var/log/nginx/access.log; | |
# error_log /var/log/nginx/error.log debug; | |
# keepalive_timeout 65; | |
# include /etc/nginx/sites-enabled/*; | |
# }' | sudo tee /etc/nginx/nginx.conf > /dev/null | |
# - name: yarn install | |
# if: steps.restore-node.outputs.cache-hit != 'true' | |
# working-directory: front | |
# run: yarn install | |
# # Build machine | |
# - name: Build dapp | |
# if: steps.check-changes.outputs.app-changed | |
# run: docker buildx bake -f docker-bake.hcl -f docker-bake.override.hcl --load | |
# # Build machine | |
# - name: Build machine | |
# if: steps.check-changes.outputs.app-changed | |
# run: docker buildx bake -f docker-bake.hcl -f docker-bake.override.hcl machine --load | |
# #Deploy contract | |
# - name: Deploy contract | |
# if: steps.check-changes.outputs.app-changed | |
# run: DAPP_NAME=chessAppNew docker compose -f ./deploy-testnet.yml up | |
# - name: Close the deployment container | |
# if: steps.check-changes.outputs.app-changed | |
# run: DAPP_NAME=chessAppNew docker compose -f ./deploy-testnet.yml down -v || true | |
# Deploy node | |
- name: Clear node | |
run: | | |
docker compose down -v | |
DAPP_NAME=chessAppNew docker compose -f ./docker-compose-testnet.yml -f ./docker-compose.override.yml -f ./docker-compose-host-testnet.yml down -v || true | |
- name: Deploy node | |
run: | | |
DAPP_NAME=chessAppNew nohup docker compose -f ./docker-compose-testnet.yml -f ./docker-compose.override.yml -f ./docker-compose-host-testnet.yml up > deployment.log 2>&1 & | |
echo "PID=$!" >> $GITHUB_ENV | |
sleep 120 | |
#ls contents of /deployments | |
- name: | |
working-directory: deployments | |
run: ls -la | |
# Build front end | |
- name: yarn run build | |
working-directory: front | |
run: yarn run build | |
# Check if the /front/dist folder exists and remove it if it does | |
- name: Check and remove /front/dist folder if it exists | |
run: | | |
if [ -d "/front/dist" ]; then | |
sudo rm -rf /front/dist | |
fi | |
# Serve front end | |
- name: Copy nginx configuration and frontend files | |
run: | | |
sudo cp nginx.conf /etc/nginx/sites-available/default | |
sudo ln -sf /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default | |
sudo mkdir -p /front | |
sudo cp -R $GITHUB_WORKSPACE/front/dist /front/ | |
# Set Nginx file permissions | |
- name: Set Nginx file permissions | |
run: | | |
sudo chown -R www-data:www-data /front/dist | |
sudo find /front/dist -type d -exec chmod 755 {} \; | |
sudo find /front/dist -type f -exec chmod 644 {} \; | |
# Restart Nginx | |
- name: Restart Nginx | |
run: sudo systemctl restart nginx || echo "Nginx restart failed" | |
# - name: Display deployment logs | |
# run: | | |
# echo "=== Deployment Log ===" | |
# cat deployment.log |