Skip to content

Commit

Permalink
Merge pull request #380 from P4-Games/feature/version-auto
Browse files Browse the repository at this point in the history
merge feature/version-auto into develop
  • Loading branch information
dappsar authored Jul 20, 2024
2 parents a204984 + 0426d1b commit ce7c4e1
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 37 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/gcp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and Deploy to Cloud Run

on:
push:
branches: [ main ]
branches: [ main, feature/version-auto ]

env:
PROJECT_ID: number-one-fan
Expand All @@ -25,7 +25,12 @@ jobs:

- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v0'


- name: Set NOF_VERSION in environment
id: env-nof-version
run: |
bash ./scripts/product_version.sh -v patch
- name: Build Docker Image
run: docker build -t ${{ env.IMAGE_NAME }}:latest .

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ARG MAIL_SG_FROM
ARG NEXT_PUBLIC_STORAGE_URL_ALPHA
ARG NEXT_PUBLIC_STORAGE_URL_GAMMA
ARG NEXT_PUBLIC_ADMIN_ACCOUNTS
ARG NEXT_PUBLIC_NOF_VERSION
ARG NOF_VERSION


# env
Expand All @@ -53,7 +53,7 @@ ENV MAIL_SG_FROM $MAIL_SG_FROM
ENV NEXT_PUBLIC_STORAGE_URL_ALPHA $NEXT_PUBLIC_STORAGE_URL_ALPHA
ENV NEXT_PUBLIC_STORAGE_URL_GAMMA $NEXT_PUBLIC_STORAGE_URL_GAMMA
ENV NEXT_PUBLIC_ADMIN_ACCOUNTS $NEXT_PUBLIC_ADMIN_ACCOUNTS
ENV NEXT_PUBLIC_NOF_VERSION $NEXT_PUBLIC_NOF_VERSION
ENV NOF_VERSION $NOF_VERSION


COPY --from=deps /app/node_modules ./node_modules
Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Create a .env file running the command in terminal
touch .env
```

The environment variables bellow needs to be set in the .env file when project is running locally:
The environment variables bellow needs to be set in the .env:

```sh
SKIP_PREFLIGHT_CHECK=true
Expand All @@ -49,13 +49,16 @@ GAMMA_SERVICE_URL='https://gamma-microservice-7bteynlhua-uc.a.run.app'
GRAPH_URL='https://api.thegraph.com/subgraphs/name/tomasfrancizco/nof_polygon'
WALLET_CONNECT_PROJECT_ID={you project ID from walletconnect.com}
CHAIN_NODE_PROVIDER_URL='https://polygon-mumbai.g.alchemy.com/v2/YOUR_API_KEY'
NODE_PROVIDER_MUMBAI_URL='https://stylish-dawn-bush.bsc-testnet.quiknode.pro/{YOUR_NODE_PROVIDER_KEY}'
NODE_PROVIDER_BSC_TESTNET_URL='https://bsc-testnet.nodereal.io/v1/{YOUR_NODE_PROVIDER_KEY}'
NODE_PROVIDER_OPBNB_TESTNET='https://opbnb-testnet.nodereal.io/v1/{YOUR_NODE_PROVIDER_KEY}'
NOF_VERSION='v0.0.0'

# Client-side
NEXT_PUBLIC_APP_ENV='development'
NEXT_PUBLIC_STORAGE_URL_ALPHA='https://storage.googleapis.com/nof-alpha'
NEXT_PUBLIC_STORAGE_URL_GAMMA='https://storage.googleapis.com/nof-gamma'
NEXT_PUBLIC_ADMIN_ACCOUNTS='0x35dad65F60c1A32c9895BE97f6bcE57D32792E83,0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'
NEXT_PUBLIC_NOF_VERSION='v0.0.0'

# Only por local environment to put contracts addresses from hardhat
NEXT_PUBLIC_NOF_DAI_HARDHAT_CONTRACT_ADDRESS=''
Expand All @@ -64,18 +67,11 @@ NEXT_PUBLIC_NOF_GAMMA_CARDS_HARDHAT_CONTRACT_ADDRESS=''
NEXT_PUBLIC_NOF_GAMMA_PACKS_HARDHAT_CONTRACT_ADDRESS=''
NEXT_PUBLIC_NOF_GAMMA_OFFERS_HARDHAT_CONTRACT_ADDRESS=''
NEXT_PUBLIC_NOF_GAMMA_TICKETS_HARDHAT_CONTRACT_ADDRESS=''


```

The source code of the smart contracts is located at [https://github.com/P4-Games/NoF-Smart-Contracts](https://github.com/P4-Games/NoF-Smart-Contracts). If you want to run them locally (example: on a hardhat or ganache node), after compiling them locally, change the addresses in the .env and set these options to network:
The source code of the smart contracts is located at [https://github.com/P4-Games/NoF-Smart-Contracts](https://github.com/P4-Games/NoF-Smart-Contracts).

```sh
NEXT_PUBLIC_CHAIN_NAME='localhost'
NEXT_PUBLIC_CHAIN_ID='0x539'
NEXT_PUBLIC_CHAIN_CURRENCY='ETH'
NEXT_PUBLIC_CHAIN_RPC_URL='http://localhost:8545'
```
All the environment variables needed are in the [example_env](./example_env) file.

# Quick commands

Expand Down
4 changes: 2 additions & 2 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ steps:
- NEXT_PUBLIC_STORAGE_URL_ALPHA=${_NEXT_PUBLIC_STORAGE_URL_ALPHA}
- NEXT_PUBLIC_STORAGE_URL_GAMMA=${_NEXT_PUBLIC_STORAGE_URL_GAMMA}
- NEXT_PUBLIC_ADMIN_ACCOUNTS=${_NEXT_PUBLIC_ADMIN_ACCOUNTS}
- NEXT_PUBLIC_NOF_VERSION=${_NEXT_PUBLIC_NOF_VERSION}
- NOF_VERSION=${_NOF_VERSION}

# build the container images
- name: "gcr.io/cloud-builders/docker"
Expand Down Expand Up @@ -61,7 +61,7 @@ steps:
"--build-arg", "NEXT_PUBLIC_STORAGE_URL_ALPHA=${_NEXT_PUBLIC_STORAGE_URL_ALPHA}",
"--build-arg", "NEXT_PUBLIC_STORAGE_URL_GAMMA=${_NEXT_PUBLIC_STORAGE_URL_GAMMA}",
"--build-arg", "NEXT_PUBLIC_ADMIN_ACCOUNTS=${_NEXT_PUBLIC_ADMIN_ACCOUNTS}",
"--build-arg", "NEXT_PUBLIC_NOF_VERSION=${_NEXT_PUBLIC_NOF_VERSION}",
"--build-arg", "NOF_VERSION=${_NOF_VERSION}",
"."
]

Expand Down
2 changes: 1 addition & 1 deletion example_env
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ NEXT_PUBLIC_APP_ENV='development'
NEXT_PUBLIC_STORAGE_URL_ALPHA='https://storage.googleapis.com/nof-alpha'
NEXT_PUBLIC_STORAGE_URL_GAMMA='https://storage.googleapis.com/nof-gamma'
NEXT_PUBLIC_ADMIN_ACCOUNTS='0x...,0X....,0xfa3....' // accounts separated by a comma
NEXT_PUBLIC_NOF_VERSION='v0.1.219'
NOF_VERSION='v0.1.219'

// Only por local environment to put contracts addresses from hardhat
NEXT_PUBLIC_NOF_DAI_CONTRACT_CURRENT_ADDRESS=''
Expand Down
2 changes: 1 addition & 1 deletion scripts/docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ docker build \
--build-arg NEXT_PUBLIC_STORAGE_URL_ALPHA="$NEXT_PUBLIC_STORAGE_URL_ALPHA" \
--build-arg NEXT_PUBLIC_STORAGE_URL_GAMMA="$NEXT_PUBLIC_STORAGE_URL_GAMMA" \
--build-arg NEXT_PUBLIC_ADMIN_ACCOUNTS="$NEXT_PUBLIC_ADMIN_ACCOUNTS" \
--build-arg NEXT_PUBLIC_NOF_VERSION="$NEXT_PUBLIC_NOF_VERSION" \
--build-arg NOF_VERSION="$NOF_VERSION" \
-t my-nextjs-app ..
27 changes: 12 additions & 15 deletions .github/workflows/scripts/gitTag.sh → scripts/product_version.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# Just set product versión in environment without TAG source code!
# This script is used in .github\workflows\gcp.yml

VERSION=""

# get parameters
Expand All @@ -12,7 +15,7 @@ done

# get highest tag number, and add v0.1.0 if doesn't exist
git fetch --prune --unshallow 2>/dev/null
CURRENT_VERSION=`git describe --abbrev=0 --tags 2>/dev/null`
CURRENT_VERSION=$(git describe --abbrev=0 --tags 2>/dev/null)

if [[ $CURRENT_VERSION == '' ]]
then
Expand All @@ -31,9 +34,12 @@ VNUM3=${CURRENT_VERSION_PARTS[2]}
if [[ $VERSION == 'major' ]]
then
VNUM1=v$((VNUM1+1))
VNUM2=0
VNUM3=0
elif [[ $VERSION == 'minor' ]]
then
VNUM2=$((VNUM2+1))
VNUM3=0
elif [[ $VERSION == 'patch' ]]
then
VNUM3=$((VNUM3+1))
Expand All @@ -46,20 +52,11 @@ fi
NEW_TAG="$VNUM1.$VNUM2.$VNUM3"
echo "($VERSION) updating $CURRENT_VERSION to $NEW_TAG"

# get current hash and see if it already has a tag
GIT_COMMIT=`git rev-parse HEAD`
NEEDS_TAG=`git describe --contains $GIT_COMMIT 2>/dev/null`

# only tag if no tag already
if [ -z "$NEEDS_TAG" ]; then
echo "Tagged with $NEW_TAG"
git tag $NEW_TAG
git push --tags
git push
else
echo "Already a tag on this commit"
fi
# set tag in environment to use in frontend
NOF_VERSION=$NEW_TAG
echo "NOF_VERSION=$NEW_TAG"

echo "git-tag=$NEW_TAG" >> $GITHUB_OUTPUT
# write tag to GITHUB_ENV for use in GitHub Actions
echo "NOF_VERSION=$NEW_TAG" >> $GITHUB_ENV

exit 0
13 changes: 11 additions & 2 deletions src/components/Navbar/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import AccountInfo from './AccountInfo.jsx'
import NotificationInfo from './NotificationInfo.jsx'
import LanguageSelection from '../LanguageSelection'
import { useLayoutContext, useWeb3Context, useNotificationContext } from '../../hooks'
import { nofVersion } from '../../config.js'
import { getProductVersion } from '../../services/handleVersion.js'

function Navbar() {
const { t } = useTranslation()
Expand All @@ -25,6 +25,7 @@ function Navbar() {
const [notificationsNbrClass, setNotificationsNbrClass] = useState('notification__badge__1')
const { notifications, getNotificationsByUser } = useNotificationContext()
const { walletAddress } = useWeb3Context()
const [productVersion, setProductVersion] = useState('1.0.0')

const accountRef = useRef(null)
const notificationRef = useRef(null)
Expand Down Expand Up @@ -65,6 +66,14 @@ function Navbar() {
// setNotificationsNbr(20)
// setNotificationsNbrClass(20 > 9 ? 'notification__badge__2' : 'notification__badge__1')
}, [notifications, walletAddress]) //eslint-disable-line react-hooks/exhaustive-deps
const fetchVersion = async () => {
const version = await getProductVersion()
return version
}

useEffect(() => {
fetchVersion().then(setProductVersion)
}, [productVersion]) //eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
document.addEventListener('mousedown', handleClickOutside)
Expand All @@ -89,7 +98,7 @@ function Navbar() {
<Link href='/'>
<Image src={'/images/navbar/logo-1.png'} alt='nof' height='60' width='120' />
</Link>
<span className='navbar__left__nof__version'>{nofVersion}</span>
<span className='navbar__left__nof__version'>{productVersion}</span>
</div>
)

Expand Down
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const storageUrlGamma =
process.env.NEXT_PUBLIC_STORAGE_URL_GAMMA || 'https://storage.googleapis.com/nof-gamma'
export const adminAccounts =
process.env.NEXT_PUBLIC_ADMIN_ACCOUNTS || '0x8a8F5e5ae88532c605921f320a92562c9599fB9E'
export const nofVersion = process.env.NEXT_PUBLIC_NOF_VERSION || 'v0.1.219'
export const nofVersion = process.env.NOF_VERSION || 'v0.1.219'

// ------------------------------------------------------------------
// calculated variables
Expand Down
5 changes: 5 additions & 0 deletions src/pages/api/version/v.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { nofVersion } from '../../../config'

export default async function handler(req, res) {
res.status(200).json({ version: nofVersion })
}
17 changes: 17 additions & 0 deletions src/services/handleVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import RenderResult from 'next/dist/server/render-result'

export const getProductVersion = async () => {
try {
const res = await fetch('/api/version/v', {
method: 'GET',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json'
}
})
const result = await res.json()
return result.version
} catch (ex) {
console.log('error en getProductVersion', ex)
}
}

0 comments on commit ce7c4e1

Please sign in to comment.