From 238654bc52624e15866679409e8f47fbb6a5a5ef Mon Sep 17 00:00:00 2001 From: kyranjamie Date: Fri, 6 Oct 2023 15:23:22 +0200 Subject: [PATCH] fix: outdated version warning --- .github/workflows/build-extension.yml | 1 + src/app/components/header.tsx | 6 ++--- .../common/outdated-pr/outdated-pr.query.ts | 14 ++++++++++ src/shared/environment.ts | 6 +++-- webpack/webpack.config.base.js | 26 ++++++++++++------- 5 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 src/app/query/common/outdated-pr/outdated-pr.query.ts diff --git a/.github/workflows/build-extension.yml b/.github/workflows/build-extension.yml index 181de7b276b..cabbc2569c6 100644 --- a/.github/workflows/build-extension.yml +++ b/.github/workflows/build-extension.yml @@ -7,6 +7,7 @@ env: SENTRY_DSN: ${{ secrets.SENTRY_DSN }} SEGMENT_WRITE_KEY: ${{ secrets.SEGMENT_WRITE_KEY_STAGING }} TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }} + PR_NUMBER: ${{ github.event.number }} WALLET_ENVIRONMENT: feature jobs: diff --git a/src/app/components/header.tsx b/src/app/components/header.tsx index 3a9e0a3aea9..b5958d46b07 100644 --- a/src/app/components/header.tsx +++ b/src/app/components/header.tsx @@ -43,13 +43,13 @@ export const Header: React.FC = memo(props => { const version = useMemo(() => { switch (process.env.WALLET_ENVIRONMENT) { - case 'production': - case 'preview': - return `v${VERSION}`; case 'feature': return `${BRANCH_NAME}#${COMMIT_SHA?.slice(0, 8)}`; case 'development': return 'dev'; + case 'production': + case 'preview': + return `v${VERSION}`; default: return null; } diff --git a/src/app/query/common/outdated-pr/outdated-pr.query.ts b/src/app/query/common/outdated-pr/outdated-pr.query.ts new file mode 100644 index 00000000000..7174cb5a57a --- /dev/null +++ b/src/app/query/common/outdated-pr/outdated-pr.query.ts @@ -0,0 +1,14 @@ +import { useQuery } from '@tanstack/react-query'; +import axios from 'axios'; + +import { GITHUB_ORG, GITHUB_REPO } from '@shared/constants'; + +export function useOutdatedPrQuery() { + return useQuery({ + // enabled: process.env.WALLET_ENVIRONMENT === 'feature', + + async queryFn() { + return axios.get(`https://api.github.com/repos/${GITHUB_ORG}/${GITHUB_REPO}/pulls/${}`); + }, + }); +} diff --git a/src/shared/environment.ts b/src/shared/environment.ts index 84bb4bc6904..a56d5693207 100644 --- a/src/shared/environment.ts +++ b/src/shared/environment.ts @@ -1,7 +1,9 @@ export const BRANCH = process.env.GITHUB_REF; -export const BRANCH_NAME = process.env.GITHUB_HEAD_REF; +export const BRANCH_NAME = process.env.GITHUB_HEAD_REF ?? process.env.BRANCH_NAME; +export const PR_NUMBER = process.env.PR_NUMBER; +console.log({ PR_NUMBER }); export const COINBASE_APP_ID = process.env.COINBASE_APP_ID ?? ''; -export const COMMIT_SHA = process.env.GITHUB_SHA; +export const COMMIT_SHA = process.env.COMMIT_SHA ?? process.env.GITHUB_SHA; export const IS_DEV_ENV = process.env.WALLET_ENVIRONMENT === 'development'; export const IS_TEST_ENV = process.env.WALLET_ENVIRONMENT === 'testing'; export const MOONPAY_API_KEY = process.env.MOONPAY_API_KEY ?? ''; diff --git a/webpack/webpack.config.base.js b/webpack/webpack.config.base.js index c2554fe3bf9..d76d6a834be 100755 --- a/webpack/webpack.config.base.js +++ b/webpack/webpack.config.base.js @@ -10,31 +10,34 @@ const CopyWebpackPlugin = require('copy-webpack-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; -const SpeedMeasurePlugin = require('speed-measure-webpack-plugin'); const ProgressBarPlugin = require('progress-bar-webpack-plugin'); const SRC_ROOT_PATH = path.join(__dirname, '../', 'src'); const DIST_ROOT_PATH = path.join(__dirname, '../', 'dist'); +const { execSync } = require('child_process'); -const WALLET_ENVIRONMENT = process.env.WALLET_ENVIRONMENT || 'development'; +const WALLET_ENVIRONMENT = process.env.WALLET_ENVIRONMENT ?? 'development'; const ANALYZE_BUNDLE = process.env.ANALYZE === 'true'; const IS_PUBLISHING = !!process.env.IS_PUBLISHING; -const BRANCH = process.env.GITHUB_REF; const IS_DEV = WALLET_ENVIRONMENT === 'development'; const IS_PROD = !IS_DEV; const MAIN_BRANCH = 'refs/heads/main'; +function executeGitCommand(command) { + return execSync(command) + .toString('utf8') + .replace(/[\n\r\s]+$/, ''); +} + +const BRANCH_NAME = executeGitCommand('git rev-parse --abbrev-ref HEAD'); +const COMMIT_SHA = executeGitCommand('git rev-parse HEAD'); + // For non main branch builds, add a random number const getVersionWithRandomSuffix = ref => { if (ref === MAIN_BRANCH || !ref || IS_PUBLISHING) return _version; return `${_version}.${Math.floor(Math.floor(Math.random() * 1000))}`; }; -const VERSION = getVersionWithRandomSuffix(BRANCH); - -const smp = new SpeedMeasurePlugin({ - disable: !ANALYZE_BUNDLE, - granularLoaderData: true, -}); +const VERSION = getVersionWithRandomSuffix(BRANCH_NAME); const HTML_OPTIONS = { inject: 'body', @@ -247,6 +250,11 @@ const config = { new webpack.DefinePlugin({ VERSION: JSON.stringify(VERSION), }), + + new webpack.EnvironmentPlugin({ + BRANCH_NAME: BRANCH_NAME, + COMMIT_SHA: COMMIT_SHA, + }), new webpack.ProvidePlugin({ process: 'process/browser', Buffer: ['buffer', 'Buffer'],