Skip to content

Commit

Permalink
ci: add release stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Aetherinox committed Apr 15, 2024
1 parent 5682844 commit fccfdf9
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 30 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ jobs:
run: |
echo "VERSION: ${{ env.PACKAGE_VERSION }}"
# ---------------------------------------------------------------------------------------
# JOB > PUBLISH > NPMJS
# ---------------------------------------------------------------------------------------

job-publish-npm:
name: >-
Expand All @@ -131,6 +134,17 @@ jobs:
always-auth: true
scope: '@aetherinox'

- name: "📦 NPM Actions"
run: |
npm ci
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

# ---------------------------------------------------------------------------------------
# JOB > PUBLISH > GITHUB PACKAGE
# ---------------------------------------------------------------------------------------

job-publish-gpr:
name: >-
📦 Package › Github
Expand All @@ -150,6 +164,12 @@ jobs:
registry-url: https://npm.pkg.github.com/
scope: '@aetherinox'

- name: "📦 NPM Actions"
run: |
npm ci
npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.SELF_TOKEN_CL }}

# ---------------------------------------------------------------------------------------
# Job > Release > Github
Expand Down
91 changes: 61 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@

<br />

- [About](#about)
- [Installation](#installation)
- [Usage](#usage)
- [`noxenv` \& `noxenv-shell`](#noxenv--noxenv-shell)
- [Windows Issues](#windows-issues)
- [Contributors ✨](#contributors-)

<br />

---

<br />

## About

Most Windows-based command prompts / terminals will have issues when you attempt to set env variables utilizing `NODE_ENV=production`; unless you are using [Bash on Windows][win-bash]. Coupled with the issue that Windows and *NIX have different ways of utilizing env variables such as
Expand All @@ -32,21 +45,7 @@ Most Windows-based command prompts / terminals will have issues when you attempt
<br />

> [!NOTE]
> `noxenv` only supports Node.js v10 and higher.
<br />

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [About](#about)
- [Installation](#installation)
- [Usage](#usage)
- [`noxenv` vs `noxenv-shell`](#noxenv-vs-noxenv-shell)
- [Windows Issues](#windows-issues)
- [Contributors ✨](#contributors-)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
> `noxenv` only supports Node.js v14 and higher.
<br />

Expand All @@ -56,11 +55,20 @@ Most Windows-based command prompts / terminals will have issues when you attempt

## Installation

This module is distributed via [npm][npm] which is bundled with [node][node] and
should be installed as one of your project's `devDependencies`:
This module is distributed via [npm][npm] which is bundled with [node][node]. To utilize this moduke, add it to your project's `package.json` -> `devDependencies`:

```json
"devDependencies": {
"@aetherinox/noxenv": "^1.0.0"
},
```

To install it via the npm command-line as a `devDependency`:

<br />

```
npm install --save-dev @aetherinox/noxenv
npm i --save-dev @aetherinox/noxenv
```

<br />
Expand All @@ -70,31 +78,52 @@ npm install --save-dev @aetherinox/noxenv
<br />

## Usage
Some examples have been provided below to show various ways of using noxenv:

<br />

```json
{
"scripts": {
"build": "noxenv NODE_ENV=production webpack --config build/webpack.config.js"
"build": "noxenv NODE_ENV=production webpack --config build/webpack.config.js",
"build-rollup": "noxenv NODE_ENV=production rollup -c",
"development": "noxenv NODE_ENV=development npm start",
"production": "noxenv NODE_ENV=production SERVER_IP=http://127.0.0.1 npm start",
"test": "noxenv BABEL_ENV=test jest test/app",
"start-dev": "noxenv NODE_ENV=development PORT_ENV=2350 npm run build && node dist/src/main.js",
"openssl-legacy": "noxenv NODE_OPTIONS=\"--openssl-legacy-provider\" tsc -p tsconfig.json"
}
}
```

<br />

The command that is executed (using [`cross-spawn`][cross-spawn]) is:
Inside your module, you can call these env variables with something similar to the below example:

```
webpack --config build/webpack.config.js
```javascript
const TEST = { api: "f4dcc990-f8f7-4343-b852-a2065b4445d5" };
const PROD = { api: "d1ac1eb8-7194-4095-8976-04be09378611" };

let target;
if (process.env.BABEL_ENV === "test") {
target = TEST;
} else if (process.env.BABEL_ENV === "prod") {
target = PROD;
}

console.log(`Your API key is ${target} in ${process.env.BABEL_ENV} mode`);
```

The `NODE_ENV` environment variable will be set by `noxenv`.
<br />

In the above example, variables such as `BABEL_ENV` will be set by `noxenv`.

You can also set multiple environment variables at a time:

```json
{
"scripts": {
"build": "noxenv ENV_ONE=alpha ENV_TWO=bravo ENV_THREE=charlie node ./my-program"
"release-beta": "noxenv RELEASE=beta ENV=dev PORT=7732 npm run release && npm run start",
}
}
```
Expand All @@ -106,24 +135,26 @@ Additionally; you can split the command into several, or separate the env variab
```json
{
"scripts": {
"parentScript": "noxenv USER_NAME=\"Joe\" npm run childScript",
"childScript": "noxenv-shell \"echo Hello $USER_NAME\""
"parentCmd": "noxenv USER_NAME=\"Joe\" npm run childCmd",
"childCmd": "noxenv-shell \"echo Hello $USER_NAME\""
}
}
```

<br />

In the above example, `childScript` stores the actual command to execute, and `parentScript` sets the env variable that is going to be used. In this case, `Joe` is the user we want to say hello to, so we store Joe's name in within the env variable `USER_NAME`, and then at the end of `parentScript`, we call `childScript` which does the actual greeting.
In the above example, `childCmd` stores the actual command to execute, and `parentCmd` sets the env variable that is going to be used. In this case, `Joe` is the user we want to say hello to, so we store Joe's name in within the env variable `USER_NAME`, and then at the end of `parentCmd`, we call `childCmd` which does the actual greeting.

This means that you only need to call `parentScript`, and both will be ran. Additionally, it also means that you can also call the env variable using `$USER_NAME` on Windows, even though the typical Windows syntax is `%USER_NAME%`.
This means that you only need to call `parentCmd`, and both will be ran. Additionally, it also means that you can also call the env variable using `$USER_NAME` on Windows, even though the typical Windows syntax is `%USER_NAME%`.

If you wish to pass a JSON string (such as when using [ts-loader]), you may do the following:

<br />

```json
{
"scripts": {
"test": "noxenv TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} node my_file.test.ts"
"test": "noxenv TS_NODE_COMPILER_OPTIONS={\\\"module\\\":\\\"commonjs\\\"} mocha --config ./test.js"
}
}
```
Expand All @@ -138,7 +169,7 @@ Pay attention to the **triple backslash** `(\\\)` **before** the **double quotes

<br />

## `noxenv` vs `noxenv-shell`
## `noxenv` & `noxenv-shell`

The `noxenv` module exposes two bins: `noxenv` and `noxenv-shell`. The first one executes commands using [`cross-spawn`][cross-spawn], while the second one uses the `shell` option from Node's `spawn`.

Expand Down

0 comments on commit fccfdf9

Please sign in to comment.