Skip to content

Commit

Permalink
Merge pull request #16735 from staszekscp/internal-build-pr-badge
Browse files Browse the repository at this point in the history
Add PR number badge for internal builds
  • Loading branch information
Julesssss authored Apr 20, 2023
2 parents 3dbfc33 + 5f6ac8a commit 1cd304c
Show file tree
Hide file tree
Showing 22 changed files with 148 additions and 22 deletions.
28 changes: 26 additions & 2 deletions .github/workflows/testBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha || needs.getBranchRef.outputs.REF }}

- name: Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it
run: |
cp .env.staging .env.adhoc
sed -i 's/ENVIRONMENT=staging/ENVIRONMENT=adhoc/' .env.adhoc
echo "PULL_REQUEST_NUMBER=$PULL_REQUEST_NUMBER" >> .env.adhoc
- uses: Expensify/App/.github/actions/composite/setupNode@main

- uses: ruby/setup-ruby@eae47962baca661befdfd24e4d6c34ade04858f7
Expand Down Expand Up @@ -121,6 +127,12 @@ jobs:
with:
ref: ${{ github.event.pull_request.head.sha || needs.getBranchRef.outputs.REF }}

- name: Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it
run: |
cp .env.staging .env.adhoc
sed -i '' 's/ENVIRONMENT=staging/ENVIRONMENT=adhoc/' .env.adhoc
echo "PULL_REQUEST_NUMBER=$PULL_REQUEST_NUMBER" >> .env.adhoc
- uses: Expensify/App/.github/actions/composite/setupNode@main

- uses: ruby/setup-ruby@eae47962baca661befdfd24e4d6c34ade04858f7
Expand Down Expand Up @@ -178,6 +190,12 @@ jobs:
ref: ${{ github.event.pull_request.head.sha || needs.getBranchRef.outputs.REF }}
fetch-depth: 0

- name: Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it
run: |
cp .env.staging .env.adhoc
sed -i '' 's/ENVIRONMENT=staging/ENVIRONMENT=adhoc/' .env.adhoc
echo "PULL_REQUEST_NUMBER=$PULL_REQUEST_NUMBER" >> .env.adhoc
- uses: Expensify/App/.github/actions/composite/setupNode@main

- name: Decrypt Developer ID Certificate
Expand All @@ -192,7 +210,7 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Build desktop app for testing
run: npm run desktop-build-internal -- --publish always
run: npm run desktop-build-adhoc -- --publish always
env:
CSC_LINK: ${{ secrets.CSC_LINK }}
CSC_KEY_PASSWORD: ${{ secrets.CSC_KEY_PASSWORD }}
Expand All @@ -214,6 +232,12 @@ jobs:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha || needs.getBranchRef.outputs.REF }}

- name: Create .env.adhoc file based on staging and add PULL_REQUEST_NUMBER env to it
run: |
cp .env.staging .env.adhoc
sed -i 's/ENVIRONMENT=staging/ENVIRONMENT=adhoc/' .env.adhoc
echo "PULL_REQUEST_NUMBER=$PULL_REQUEST_NUMBER" >> .env.adhoc
- uses: Expensify/App/.github/actions/composite/setupNode@main

- name: Configure AWS Credentials
Expand All @@ -223,7 +247,7 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Build web for testing
run: npm run build-staging
run: npm run build-adhoc

- name: Build docs
run: npm run storybook-build
Expand Down
50 changes: 50 additions & 0 deletions assets/images/new-expensify-adhoc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions config/electronBuilder.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ const pullRequestNumber = process.env.PULL_REQUEST_NUMBER;
const s3Bucket = {
production: 'expensify-cash',
staging: 'staging-expensify-cash',
internal: 'ad-hoc-expensify-cash',
adhoc: 'ad-hoc-expensify-cash',
};

const s3Path = {
production: '/',
staging: '/',
internal: process.env.PULL_REQUEST_NUMBER
adhoc: process.env.PULL_REQUEST_NUMBER
? `/desktop/${pullRequestNumber}/`
: '/',
};

const macIcon = {
production: './desktop/icon.png',
staging: './desktop/icon-stg.png',
internal: './desktop/icon-stg.png',
adhoc: './desktop/icon-adhoc.png',
};

const isCorrectElectronEnv = ['production', 'staging', 'internal'].includes(
const isCorrectElectronEnv = ['production', 'staging', 'adhoc'].includes(
process.env.ELECTRON_ENV,
);

Expand Down
3 changes: 2 additions & 1 deletion config/webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const envToLogoSuffixMap = {
production: '',
staging: '-stg',
dev: '-dev',
adhoc: '-adhoc',
};

function mapEnvToLogoSuffix(envFile) {
Expand Down Expand Up @@ -120,7 +121,7 @@ const webpackConfig = ({envFile = '.env', platform = 'web'}) => ({
// React Native JavaScript environment requires the global __DEV__ variable to be accessible.
// react-native-render-html uses variable to log exclusively during development.
// See https://reactnative.dev/docs/javascript-environment
__DEV__: /staging|prod/.test(envFile) === false,
__DEV__: /staging|prod|adhoc/.test(envFile) === false,
}),

// This allows us to interactively inspect JS bundle contents
Expand Down
Binary file added desktop/icon-adhoc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion desktop/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const mainWindow = (() => {
if (__DEV__) {
console.debug('CONFIG: ', CONFIG);
app.dock.setIcon(`${__dirname}/../icon-dev.png`);
app.setName('New Expensify');
app.setName('New Expensify Dev');
}

app.on('will-finish-launching', () => {
Expand Down
4 changes: 2 additions & 2 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ platform :android do

desc "Build app for testing"
lane :build_internal do
ENV["ENVFILE"]=".env.staging"
ENV["ENVFILE"]=".env.adhoc"

gradle(
project_dir: './android',
Expand Down Expand Up @@ -118,7 +118,7 @@ platform :ios do
desc "Build app for testing"
lane :build_internal do
require 'securerandom'
ENV["ENVFILE"]=".env.staging"
ENV["ENVFILE"]=".env.adhoc"

keychain_password = SecureRandom.uuid

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
"web-server": "webpack-dev-server --open --config config/webpack/webpack.dev.js",
"build": "webpack --config config/webpack/webpack.common.js --env envFile=.env.production",
"build-staging": "webpack --config config/webpack/webpack.common.js --env envFile=.env.staging",
"build-adhoc": "webpack --config config/webpack/webpack.common.js --env envFile=.env.adhoc",
"desktop": "scripts/set-pusher-suffix.sh && node desktop/start.js",
"desktop-build": "scripts/build-desktop.sh production",
"desktop-build-staging": "scripts/build-desktop.sh staging",
"desktop-build-internal": "scripts/build-desktop.sh internal",
"desktop-build-adhoc": "scripts/build-desktop.sh adhoc",
"ios-build": "fastlane ios build",
"android-build": "fastlane android build",
"android-build-e2e": "bundle exec fastlane android build_e2e",
Expand Down
4 changes: 2 additions & 2 deletions scripts/build-desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export ELECTRON_ENV=${1:-development}

if [[ "$ELECTRON_ENV" == "staging" ]]; then
ENV_FILE=".env.staging"
elif [[ "$ELECTRON_ENV" == "internal" ]]; then
ENV_FILE=".env.staging"
elif [[ "$ELECTRON_ENV" == "adhoc" ]]; then
ENV_FILE=".env.adhoc"
elif [[ "$ELECTRON_ENV" == "production" ]]; then
ENV_FILE=".env.production"
else
Expand Down
4 changes: 4 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const PLATFORM_OS_MACOS = 'Mac OS';
const ANDROID_PACKAGE_NAME = 'com.expensify.chat';
const USA_COUNTRY_NAME = 'United States';
const CURRENT_YEAR = new Date().getFullYear();
const PULL_REQUEST_NUMBER = lodashGet(Config, 'PULL_REQUEST_NUMBER', '');

const CONST = {
ANDROID_PACKAGE_NAME,
Expand Down Expand Up @@ -55,6 +56,8 @@ const CONST = {
RESERVED_FIRST_NAMES: ['Expensify', 'Concierge'],
},

PULL_REQUEST_NUMBER,

CALENDAR_PICKER: {
// Numbers were arbitrarily picked.
MIN_YEAR: CURRENT_YEAR - 100,
Expand Down Expand Up @@ -694,6 +697,7 @@ const CONST = {
DEV: 'development',
STAGING: 'staging',
PRODUCTION: 'production',
ADHOC: 'adhoc',
},

// Used to delay the initial fetching of reportActions when the app first inits or reconnects (e.g. returning
Expand Down
7 changes: 6 additions & 1 deletion src/components/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import styles from '../styles/styles';
import * as StyleUtils from '../styles/StyleUtils';
import Text from './Text';
import CONST from '../CONST';

const propTypes = {
/** Is Success type */
Expand All @@ -18,6 +19,9 @@ const propTypes = {
/** Text to display in the Badge */
text: PropTypes.string.isRequired,

/** Text to display in the Badge */
environment: PropTypes.string,

/** Styles for Badge */
// eslint-disable-next-line react/forbid-prop-types
badgeStyles: PropTypes.arrayOf(PropTypes.object),
Expand All @@ -32,6 +36,7 @@ const defaultProps = {
pressable: false,
badgeStyles: [],
onPress: undefined,
environment: CONST.ENVIRONMENT.DEV,
};

const Badge = (props) => {
Expand All @@ -40,7 +45,7 @@ const Badge = (props) => {
const wrapperStyles = ({pressed}) => ([
styles.badge,
styles.ml2,
StyleUtils.getBadgeColorStyle(props.success, props.error, pressed),
StyleUtils.getBadgeColorStyle(props.success, props.error, pressed, props.environment === CONST.ENVIRONMENT.ADHOC),
...props.badgeStyles,
]);

Expand Down
12 changes: 9 additions & 3 deletions src/components/EnvironmentBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import CONST from '../CONST';
import withEnvironment, {environmentPropTypes} from './withEnvironment';
import Badge from './Badge';
import styles from '../styles/styles';
import * as Environment from '../libs/Environment/Environment';
import pkg from '../../package.json';

const ENVIRONMENT_SHORT_FORM = {
[CONST.ENVIRONMENT.DEV]: 'DEV',
[CONST.ENVIRONMENT.STAGING]: 'STG',
[CONST.ENVIRONMENT.PRODUCTION]: 'PROD',
[CONST.ENVIRONMENT.ADHOC]: 'ADHOC',
};

const EnvironmentBadge = (props) => {
Expand All @@ -16,12 +19,15 @@ const EnvironmentBadge = (props) => {
return null;
}

const text = Environment.isInternalTestBuild() ? `v${pkg.version} PR:${CONST.PULL_REQUEST_NUMBER}` : ENVIRONMENT_SHORT_FORM[props.environment];

return (
<Badge
success={props.environment === CONST.ENVIRONMENT.STAGING}
error={props.environment !== CONST.ENVIRONMENT.STAGING}
text={ENVIRONMENT_SHORT_FORM[props.environment]}
success={props.environment === CONST.ENVIRONMENT.STAGING || props.environment === CONST.ENVIRONMENT.ADHOC}
error={props.environment !== CONST.ENVIRONMENT.STAGING && props.environment !== CONST.ENVIRONMENT.ADHOC}
text={text}
badgeStyles={[styles.alignSelfCenter]}
environment={props.environment}
/>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/ExpensifyCashLogo.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import ProductionLogo from '../../assets/images/new-expensify.svg';
import DevLogo from '../../assets/images/new-expensify-dev.svg';
import StagingLogo from '../../assets/images/new-expensify-stg.svg';
import AdhocLogo from '../../assets/images/new-expensify-adhoc.svg';
import CONST from '../CONST';
import withEnvironment, {environmentPropTypes} from './withEnvironment';

Expand All @@ -20,6 +21,7 @@ const logoComponents = {
[CONST.ENVIRONMENT.DEV]: DevLogo,
[CONST.ENVIRONMENT.STAGING]: StagingLogo,
[CONST.ENVIRONMENT.PRODUCTION]: ProductionLogo,
[CONST.ENVIRONMENT.ADHOC]: AdhocLogo,
};

const ExpensifyCashLogo = (props) => {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ApiUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Environment.getEnvironment()
return;
}

const defaultToggleState = ENV_NAME === CONST.ENVIRONMENT.STAGING;
const defaultToggleState = ENV_NAME === CONST.ENVIRONMENT.STAGING || ENV_NAME === CONST.ENVIRONMENT.ADHOC;
shouldUseStagingServer = lodashGet(val, 'shouldUseStagingServer', defaultToggleState);
},
});
Expand Down
12 changes: 12 additions & 0 deletions src/libs/Environment/Environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ const ENVIRONMENT_URLS = {
[CONST.ENVIRONMENT.DEV]: CONST.DEV_NEW_EXPENSIFY_URL + CONFIG.DEV_PORT,
[CONST.ENVIRONMENT.STAGING]: CONST.STAGING_NEW_EXPENSIFY_URL,
[CONST.ENVIRONMENT.PRODUCTION]: CONST.NEW_EXPENSIFY_URL,
[CONST.ENVIRONMENT.ADHOC]: CONST.STAGING_NEW_EXPENSIFY_URL,
};

const OLDDOT_ENVIRONMENT_URLS = {
[CONST.ENVIRONMENT.DEV]: CONST.INTERNAL_DEV_EXPENSIFY_URL,
[CONST.ENVIRONMENT.STAGING]: CONST.STAGING_EXPENSIFY_URL,
[CONST.ENVIRONMENT.PRODUCTION]: CONST.EXPENSIFY_URL,
[CONST.ENVIRONMENT.ADHOC]: CONST.STAGING_EXPENSIFY_URL,
};

/**
Expand All @@ -25,6 +27,15 @@ function isDevelopment() {
return lodashGet(Config, 'ENVIRONMENT', CONST.ENVIRONMENT.DEV) === CONST.ENVIRONMENT.DEV;
}

/**
* Are we running an internal test build?
*
* @return {boolean}
*/
function isInternalTestBuild() {
return lodashGet(Config, 'ENVIRONMENT', CONST.ENVIRONMENT.DEV) === CONST.ENVIRONMENT.ADHOC && lodashGet(Config, 'PULL_REQUEST_NUMBER', '');
}

/**
* Get the URL based on the environment we are in
*
Expand All @@ -49,6 +60,7 @@ function getOldDotEnvironmentURL() {

export {
getEnvironment,
isInternalTestBuild,
isDevelopment,
getEnvironmentURL,
getOldDotEnvironmentURL,
Expand Down
7 changes: 6 additions & 1 deletion src/libs/Environment/getEnvironment/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ function getEnvironment() {
return resolve(environment);
}

// If we haven't set the environment yet and we aren't on dev, check to see if this is a beta build
if (lodashGet(Config, 'ENVIRONMENT', CONST.ENVIRONMENT.DEV) === CONST.ENVIRONMENT.ADHOC) {
environment = CONST.ENVIRONMENT.ADHOC;
return resolve(environment);
}

// If we haven't set the environment yet and we aren't on dev/adhoc, check to see if this is a beta build
betaChecker.isBetaBuild()
.then((isBeta) => {
environment = isBeta ? CONST.ENVIRONMENT.STAGING : CONST.ENVIRONMENT.PRODUCTION;
Expand Down
Loading

0 comments on commit 1cd304c

Please sign in to comment.