diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..05a0f349 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,81 @@ +name: deploy + +on: + push: + branches: [master] + tags: ['v*'] + +jobs: + dependencies: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Node.js 14.x + uses: actions/setup-node@v1 + with: + node-version: 14.x + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + # npm cache files are stored in `~/.npm` on Linux/macOS + path: /home/runner/work/hathor-explorer/hathor-explorer/node_modules + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - name: Install Dependencies + run: | + npm install + tar -cvf node_modules.tar ./node_modules + - name: Upload node modules + uses: actions/upload-artifact@v2 + with: + name: node_modules + path: node_modules.tar + if-no-files-found: error + retention-days: 1 + deploy-testnet-explorer: + if: github.ref == 'refs/heads/master' + needs: dependencies + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Download node modules + uses: actions/download-artifact@v2 + with: + name: node_modules + - name: Build + run: | + tar -xf node_modules.tar + make testnet_build + - name: Deploy Testnet Explorer + run: | + make testnet_deploy + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: 'us-east-1' + deploy-mainnet-explorer: + if: startsWith(github.ref, 'refs/tags/v') + needs: dependencies + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Download node modules + uses: actions/download-artifact@v2 + with: + name: node_modules + - name: Build + run: | + tar -xf node_modules.tar + make mainnet_build + - name: Deploy Mainnet Explorer + run: | + make mainnet_deploy + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: 'us-east-1' \ No newline at end of file diff --git a/Makefile b/Makefile index a98ee3c8..5ff120d0 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,35 @@ -FULLNODE_HOST := node1.bravo.testnet.hathor.network -REACT_APP_BASE_URL := https://$(FULLNODE_HOST)/v1a/ -REACT_APP_WS_URL := wss://$(FULLNODE_HOST)/v1a/ws/ - -.PHONY: build -build: - REACT_APP_WS_URL=$(REACT_APP_WS_URL) \ - REACT_APP_BASE_URL=$(REACT_APP_BASE_URL) \ +.PHONY: check_version +check_version: + ./scripts/check_version + +.PHONY: check_tag +check_tag: + ./scripts/check_tag + +.PHONY: testnet_build +testnet_build: + FULLNODE_HOST=node1.foxtrot.testnet.hathor.network; \ + export REACT_APP_BASE_URL=https://$$FULLNODE_HOST/v1a/; \ + export REACT_APP_WS_URL=wss://$$FULLNODE_HOST/v1a/ws/; \ + export EXPLORER_SERVICE_BASE_URL=https://explorer-service.testnet.hathor.network/; / + npm run build + +.PHONY: testnet_deploy +testnet_deploy: + check_version + aws s3 sync --delete ./build/ s3://hathor-testnet-foxtrot-public-explorer + +.PHONY: mainnet_build +mainnet_build: + FULLNODE_HOST=node.explorer.hathor.network; \ + export REACT_APP_BASE_URL=https://$$FULLNODE_HOST/v1a/; \ + export REACT_APP_WS_URL=wss://$$FULLNODE_HOST/v1a/ws/; \ + export REACT_APP_GTM_ID=GTM-MJVX6BG; / + export EXPLORER_SERVICE_BASE_URL=https://explorer-service.hathor.network/; / npm run build -.PHONY: s3_upload -s3_upload: - ./s3_prod_upload +.PHONY: mainnet_deploy +mainnet_deploy: + check_version + check_tag + aws s3 sync --delete ./build/ s3://hathor-mainnet-public-explorer \ No newline at end of file diff --git a/s3_prod_upload b/s3_prod_upload deleted file mode 100755 index 285e518e..00000000 --- a/s3_prod_upload +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -exec aws s3 sync --delete ./build/ s3://hathor-testnet-public-explorer diff --git a/scripts/check_tag b/scripts/check_tag new file mode 100755 index 00000000..75a5fee2 --- /dev/null +++ b/scripts/check_tag @@ -0,0 +1,17 @@ +#!/bin/bash + +PACKAGE_VERSION=`grep '"version":' ./package.json | cut -d '"' -f4` +GIT_TAG_VERSION=`git describe --abbrev=0 --tags` + +# For debugging: +# echo x${PACKAGE_VERSION}x +# echo x${GIT_TAG_VERSION}x + +EXITCODE=0 + +if [[ x${PACKAGE_VERSION}x != x${GIT_TAG_VERSION:1}x ]]; then + echo Version different in package.json and git tag + EXITCODE=-1 +fi + +exit $EXITCODE \ No newline at end of file diff --git a/scripts/check_version b/scripts/check_version new file mode 100755 index 00000000..da9be2be --- /dev/null +++ b/scripts/check_version @@ -0,0 +1,17 @@ +#!/bin/bash + +SRC_VERSION=`grep "const VERSION " ./src/constants.js | cut -d"'" -f2` +PACKAGE_VERSION=`grep '"version":' ./package.json | cut -d '"' -f4` + +# For debugging: +# echo x${SRC_VERSION}x +# echo x${PACKAGE_VERSION}x + +EXITCODE=0 + +if [[ x${PACKAGE_VERSION}x != x${SRC_VERSION}x ]]; then + echo Version different in package.json and src/constants.js + EXITCODE=-1 +fi + +exit $EXITCODE \ No newline at end of file