Skip to content

Commit

Permalink
chore(env): GITHUB_WORKSPACE=$(git rev-parse --show-toplevel)
Browse files Browse the repository at this point in the history
  • Loading branch information
unicornware committed Nov 4, 2021
1 parent 981a062 commit fe2f5ac
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 39 deletions.
7 changes: 3 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

DEBUG='*,-babel*,-compression,-eslint:*,-eslintrc:*,-lint-staged:*,-mocha:*,-typescript-eslint*,-yarn'
DEBUG_COLORS=true
GITHUB_WORKSPACE=$PWD
GITHUB_WORKSPACE=$(git rev-parse --show-toplevel)
NODE_ENV=development
# Fixes `YN0000: Strings should avoid referencing the node_modules directory`
# warning during the `yarn check:install` lifecycle
NODE_MODULES=node_modules
NPM_TOKEN=$NPM_TOKEN_FLDV
PAT_GPR=$PAT_GPR_FLDV
PROJECT_CWD=$GITHUB_WORKSPACE
TS_NODE_PROJECT="$PROJECT_CWD/tsconfig.json"
TS_NODE_PROJECT="$GITHUB_WORKSPACE/tsconfig.json"

# NODE_OPTIONS - Use ESM
# See: https://github.com/TypeStrong/ts-node/issues/1007
Expand All @@ -30,7 +29,7 @@ if [ -f "./node_modules/ts-node/esm.mjs" ]; then
SPECIFIER_RESOLUTION='--es-module-specifier-resolution node'

# Use custom ESM loader
LOADER="--loader $PROJECT_CWD/tools/loaders/esm.mjs"
LOADER="--loader $GITHUB_WORKSPACE/tools/loaders/esm.mjs"

# Specify Node options
NODE_OPTIONS="$JSON_MODULES $SPECIFIER_RESOLUTION $LOADER"
Expand Down
2 changes: 1 addition & 1 deletion .mocharc.base.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @see https://mochajs.org/#configuration-format
*/

const PWD = process.env.PROJECT_CWD
const PWD = process.env.GITHUB_WORKSPACE
const TYPES = ['', 'e2e', 'functional', 'integration']

/** @type {Mocha.MochaInstanceOptions} */
Expand Down
54 changes: 33 additions & 21 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,43 @@ People interacting with the `exceptions` project are grouped into 4 categories:
Project environment variables are listed below. Workspace variables are listed
in each workspace-specific Contributing Guide.

| name | required | development | test | production | build, release, deploy (local & ci) |
| -------------------------- | -------- | ------------------ | ------------------ | ---------- | ----------------------------------- |
| `DEBUG` | `false` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `DEBUG_COLORS` | `false` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `GITHUB_WORKSPACE`**\*\*** | `true` | :white_check_mark: | :x: | :x: | :white_check_mark: |
| `NODE_ENV` | `false` | :x: | :x: | :x: | :white_check_mark: |
| `NODE_OPTIONS` | `true` | :white_check_mark: | :x: | :x: | :white_check_mark: |
| `NODE_MODULES` | `true` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `NPM_TOKEN` | `true` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `NPM_TOKEN_FLDV` | `true` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `PAT_GPR` | `true` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `PAT_GPR_FLDV` | `true` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `PROJECT_CWD`**\*** | `true` | :x: | :x: | :x: | :white_check_mark: |
| `PWD`**\*\*\*** | `true` | :white_check_mark: | :x: | :x: | :white_check_mark: |
| `TS_NODE_PROJECT` | `false` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `npm_package_name`**\*** | `true` | :x: | :x: | :x: | :white_check_mark: |

**\*** Environment variable [specific to Yarn 2][2]
**\*\*** Environment variable specific to GitHub Actions
**\*\*\*** Environment variable specific to local machine
| name | required | development | test | production | build, release, deploy (local & ci) |
| ------------------------ | -------- | ------------------ | ------------------ | ---------- | ----------------------------------- |
| `DEBUG` | `false` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `DEBUG_COLORS` | `false` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `GITHUB_WORKSPACE` | `true` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `INIT_CWD`**\*** | `true` | :x: | :x: | :x: | :white_check_mark: |
| `NODE_ENV` | `false` | :x: | :x: | :x: | :white_check_mark: |
| `NODE_OPTIONS` | `true` | :white_check_mark: | :x: | :x: | :white_check_mark: |
| `NPM_TOKEN` | `true` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `NPM_TOKEN_FLDV` | `true` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `PAT_GPR` | `true` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `PAT_GPR_FLDV` | `true` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `TS_NODE_PROJECT` | `false` | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
| `npm_package_name`**\*** | `true` | :x: | :x: | :x: | :white_check_mark: |

**\*** Environment variable [specific to Yarn 2][2]

If you're using [ZSH][3], you can use the [`dotenv`][4] plugin to autosource the
project [`.env`](.env) file. Otherwise, following the instructions in the
project [`.env`](.env) file. Otherwise, follow the instructions in the
[Clone & Install](#clone--install) section to setup your environment.

##### `GITHUB_WORKSPACE`

`GITHUB_WORKSPACE` is set in our project [`.env`](.env) file, but if you'd like
to use the value in your other projects (and have one less variable to
autosource for this project) update your shell environment:

1. Open a shell startup file

- e.g: `~/.bash_profile` `~/.bashrc`, `~/.profile`, `~/.zprofile`,
`~/.zshenv`, `~/.zshrc`

2. Add `export GITHUB_WORKSPACE=$(git rev-parse --show-toplevel)` to your chosen
shell startup file

3. Save file and re-launch shell

### Git Configuration

The examples in this guide contain references to custom Git aliases.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ error handling solutions found throughout Flex Development projects.
## Usage

This project is organized as a monorepo. For detailed usage instructions, see
one of the project workspaces below:
one of the workspaces below:

- [@flex-development/aggregate-error-ponyfill][1]
- [@flex-development/exceptions][2]
Expand Down
2 changes: 1 addition & 1 deletion tools/cli/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const argv: ReleaseArgv = await args.argv
const options: IGreaseOptions = {
commitAll: true,
gitTagFallback: false,
gitdir: process.env.PROJECT_CWD,
gitdir: process.env.GITHUB_WORKSPACE,
lernaPackage: $WNS,
releaseAssets: ['./*.tgz'],
releaseBranchWhitelist: ['release/*'],
Expand Down
2 changes: 1 addition & 1 deletion tools/helpers/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export type BuildWorflow<O extends BuildOptions = BuildOptions> = {
/** @property {BuildContext} context - Build context */
export const CONTEXT: BuildContext = {
cwd: process.cwd(),
pwd: process.env.PROJECT_CWD as string
pwd: process.env.GITHUB_WORKSPACE as string
}

/** @property {BuildArgs} args - Project working directory */
Expand Down
10 changes: 3 additions & 7 deletions tools/helpers/tsconfig-cascade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ export type TsCascadeConfig = [string, 'json' | `${string}.json`]
* Deep merges TypeScript config files.
*
* @param {TsCascadeConfig[]} [configs=[]] - Array of suffix config items
* @param {boolean} [root_paths=true] - Make aliases relative to `PROJECT_CWD`
* @return {TsConfig} Tsconfig object
*/
const tsconfigCascade = (
configs: TsCascadeConfig[] = [],
root_paths: boolean = true
): TsConfig => {
const tsconfigCascade = (configs: TsCascadeConfig[] = []): TsConfig => {
const $: TsCascadeConfig[] = configs.map(c => [c[0], `tsconfig.${c[1]}`])
const tsconfig = merge(...($.map(arg => load(...arg).config) as [TsConfig]))

if (root_paths && tsconfig.compilerOptions?.paths) {
const root = process.env.PROJECT_CWD
if (tsconfig.compilerOptions?.paths) {
const root = process.env.GITHUB_WORKSPACE
const { paths } = tsconfig.compilerOptions

for (const alias of Object.keys(paths)) {
Expand Down
4 changes: 3 additions & 1 deletion tools/helpers/workspaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { workspaces as GLOBS } from '../../package.json'
const workspaces = (): string[] => {
return GLOBS.map(g => g.split('/')[0]).flatMap((proj?: string): string[] => {
// Get path to Yarn project directory
const dir = path.resolve(process.env.PROJECT_CWD as string, proj as string)
const dir = path.resolve(workspaces.ROOT, proj as string)

// Add subdirectories under Yarn project directory
return readdirSync(dir).filter(workspace => {
Expand All @@ -25,4 +25,6 @@ const workspaces = (): string[] => {
})
}

workspaces.ROOT = process.env.GITHUB_WORKSPACE as string

export default workspaces
4 changes: 2 additions & 2 deletions tools/scripts/mocha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
# - https://mochajs.org/#command-line-usage

# 1. Load default environment variables
. $PROJECT_CWD/.env
. $GITHUB_WORKSPACE/.env

# 2. Set test environment variables
export NODE_ENV=test
export TS_NODE_PROJECT="$PROJECT_CWD/tsconfig.test.json"
export TS_NODE_PROJECT="$GITHUB_WORKSPACE/tsconfig.test.json"

# 3. Run test suites
ts-mocha $@

0 comments on commit fe2f5ac

Please sign in to comment.