Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customizing package manager #29

Merged
merged 13 commits into from
Mar 7, 2023
30 changes: 15 additions & 15 deletions .github/workflows/build-and-push-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@ name: Build and push assets
on:
workflow_call:
inputs:
NPM_REGISTRY_DOMAIN:
description: Domain of the private npm registry.
default: https://npm.pkg.github.com/
required: false
type: string
NODE_VERSION:
description: Node version with which the assets will be compiled.
default: 16
required: false
type: string
NPM_REGISTRY_DOMAIN:
description: Domain of the private npm registry.
default: "https://npm.pkg.github.com/"
required: false
type: string
PACKAGE_MANAGER:
description: Package manager. Supported are "yarn" and "npm".
description: Package manager with which the dependencies should be installed (`npm` or yarn`).
type: string
default: "auto"
default: 'auto'
required: false
DEPS_INSTALL:
description: Install dependencies before compiling?
type: string
default: "yes"
default: 'yes'
required: false
COMPILE_SCRIPT_PROD:
description: Script added to "npm run" or "yarn" to build production assets.
type: string
default: "encore prod"
default: 'encore prod'
required: false
COMPILE_SCRIPT_DEV:
description: Script added to "npm run" or "yarn" to build development assets.
type: string
default: "encore dev"
default: 'encore dev'
required: false
ASSETS_TARGET_PATHS:
description: Target path(s) for compiled assets.
default: "./assets"
default: './assets'
required: false
type: string
secrets:
Expand Down Expand Up @@ -63,8 +63,8 @@ jobs:
TAG_NAME: '' # we'll override if the push is for tag
TAG_BRANCH_NAME: '' # we'll override if the push is for tag
LOCK_FILE: '' # we'll override after checking files
PACKAGE_MANAGER: "yarn" # we'll override based on env/inputs
NO_CHANGES: "" # we'll override if no changes to commit
PACKAGE_MANAGER: 'yarn' # we'll override based on env/inputs
NO_CHANGES: '' # we'll override if no changes to commit
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -73,7 +73,7 @@ jobs:
# when current push is a tag, we check out the tag's SHA, we'll create a new branch later
ref: ${{ ((github.ref_type == 'tag') && github.sha) || github.ref }}

- name: Set up Node.js
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.NODE_VERSION }}
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
if: ${{ (env.LOCK_FILE == 'npm') || (inputs.PACKAGE_MANAGER == 'npm') }}
run: echo "PACKAGE_MANAGER=npm" >> $GITHUB_ENV

- name: Cache npm/Yarn dependencies
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.deps_cache
Expand Down
19 changes: 12 additions & 7 deletions .github/workflows/static-analysis-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ on:
default: '-o eslint_report.json -f json --ext .js,.jsx,.ts,.tsx ./resources'
required: false
type: string
PACKAGE_MANAGER:
description: Package manager with which the dependencies should be installed (`npm` or yarn`).
default: 'npm'
required: false
type: string
secrets:
NPM_REGISTRY_TOKEN:
description: Authentication for the private npm registry.
Expand All @@ -39,16 +44,16 @@ jobs:
node-version: ${{ inputs.NODE_VERSION }}
registry-url: ${{ inputs.NPM_REGISTRY_DOMAIN }}

- name: Cache npm dependencies
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
path: ~/.deps_cache
shvlv marked this conversation as resolved.
Show resolved Hide resolved
key: ${{ runner.os }}-node-${{ inputs.NODE_VERSION }}-${{ inputs.PACKAGE_MANAGER }}-${{ hashFiles('**/package-lock.json', '**/npm-shrinkwrap.json', '**/yarn.lock') }}

- name: Install npm dependencies
run: npm install
- name: Install dependencies
run: |
${{ ((inputs.PACKAGE_MANAGER == 'yarn') && 'yarn config set cache-folder ~/.deps_cache') || 'npm config set cache ~/.deps_cache --global' }}
tyrann0us marked this conversation as resolved.
Show resolved Hide resolved
${{ ((inputs.PACKAGE_MANAGER == 'yarn') && 'yarn') || 'npm install' }}

- name: Run ESLint
run: ./node_modules/.bin/eslint ${{ inputs.ESLINT_ARGS }}
Expand Down
19 changes: 12 additions & 7 deletions .github/workflows/static-analysis-sass.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ on:
default: './resources/**/*.scss'
required: false
type: string
PACKAGE_MANAGER:
description: Package manager with which the dependencies should be installed (`npm` or yarn`).
default: 'npm'
required: false
type: string
secrets:
NPM_REGISTRY_TOKEN:
description: Authentication for the private npm registry.
Expand All @@ -42,16 +47,16 @@ jobs:
- name: Set up problem matchers for Stylelint
uses: xt0rted/stylelint-problem-matcher@v1

- name: Cache npm dependencies
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
path: ~/.deps_cache
key: ${{ runner.os }}-node-${{ inputs.NODE_VERSION }}-${{ inputs.PACKAGE_MANAGER }}-${{ hashFiles('**/package-lock.json', '**/npm-shrinkwrap.json', '**/yarn.lock') }}

- name: Install npm dependencies
run: npm install
- name: Install dependencies
run: |
${{ ((inputs.PACKAGE_MANAGER == 'yarn') && 'yarn config set cache-folder ~/.deps_cache') || 'npm config set cache ~/.deps_cache --global' }}
${{ ((inputs.PACKAGE_MANAGER == 'yarn') && 'yarn') || 'npm install' }}

- name: Run Stylelint
run: ./node_modules/.bin/stylelint ${{ inputs.STYLELINT_ARGS }}
19 changes: 12 additions & 7 deletions .github/workflows/tests-unit-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ on:
default: '--reporters=default --reporters=github-actions'
required: false
type: string
PACKAGE_MANAGER:
description: Package manager with which the dependencies should be installed (`npm` or yarn`).
default: 'npm'
required: false
type: string
secrets:
NPM_REGISTRY_TOKEN:
description: Authentication for the private npm registry.
Expand All @@ -39,16 +44,16 @@ jobs:
node-version: ${{ inputs.NODE_VERSION }}
registry-url: ${{ inputs.NPM_REGISTRY_DOMAIN }}

- name: Cache npm dependencies
- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
path: ~/.deps_cache
key: ${{ runner.os }}-node-${{ inputs.NODE_VERSION }}-${{ inputs.PACKAGE_MANAGER }}-${{ hashFiles('**/package-lock.json', '**/npm-shrinkwrap.json', '**/yarn.lock') }}

- name: Install npm dependencies
run: npm install
- name: Install dependencies
run: |
${{ ((inputs.PACKAGE_MANAGER == 'yarn') && 'yarn config set cache-folder ~/.deps_cache') || 'npm config set cache ~/.deps_cache --global' }}
${{ ((inputs.PACKAGE_MANAGER == 'yarn') && 'yarn') || 'npm install' }}

- name: Run Jest
run: ./node_modules/.bin/jest ${{ inputs.JEST_ARGS }}
18 changes: 9 additions & 9 deletions docs/build-and-push-assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ This is not the simplest possible example, but it showcases all the recommendati

### Inputs

| Name | Default | Description |
|-----------------------|---------------------------------|----------------------------------------------------------------------------------------|
| `NODE_VERSION` | `16` | Node version with which the assets will be compiled |
| `NPM_REGISTRY_DOMAIN` | `"https://npm.pkg.github.com/"` | Domain of the private npm registry |
| `PACKAGE_MANAGER` | `"auto"` <sup>**^1**</sup> | Package manager. Supported are "yarn" and "npm". Required if no lock file is available |
| `DEPS_INSTALL` | `"yes"` | Install dependencies before compiling? Options: `"yes"` (default) `"no"` |
| `COMPILE_SCRIPT_PROD` | `"encore prod"` | Script added to `npm run` or `yarn` to build production assets |
| `COMPILE_SCRIPT_DEV` | `"encore dev"` | Script added to `npm run` or `yarn` to build development assets |
| `ASSETS_TARGET_PATHS` | `"./assets"` | Target path(s) for compiled assets |
| Name | Default | Description |
|-----------------------|---------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| `NODE_VERSION` | `16` | Node version with which the assets will be compiled |
| `NPM_REGISTRY_DOMAIN` | `'https://npm.pkg.github.com/'` | Domain of the private npm registry |
| `PACKAGE_MANAGER` | `'auto'` <sup>**^1**</sup> | Package manager with which the dependencies should be installed (`npm` or yarn`). Required if no lock file is available |
| `DEPS_INSTALL` | `'yes'` | Install dependencies before compiling? Options: `'yes'` (default) `'no'` |
| `COMPILE_SCRIPT_PROD` | `'encore prod'` | Script added to `npm run` or `yarn` to build production assets |
| `COMPILE_SCRIPT_DEV` | `'encore dev'` | Script added to `npm run` or `yarn` to build development assets |
| `ASSETS_TARGET_PATHS` | `'./assets'` | Target path(s) for compiled assets |

<sup>**^1**</sup> `PACKAGE_MANAGER` defaults to "auto" because it tries to determine the package
manager by looking at lock file (e.g. presence of `yarn.lock` means _Yarn_, `npm-shrinkwrap.json`
Expand Down
22 changes: 12 additions & 10 deletions docs/js.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ jobs:

#### Inputs

| Name | Default | Description |
|-----------------------|-----------------------------------------------------------------------|-----------------------------------------------------|
| `NPM_REGISTRY_DOMAIN` | `'https://npm.pkg.github.com/'` | Domain of the private npm registry |
| `NODE_VERSION` | 16 | Node version with which the assets will be compiled |
| `ESLINT_ARGS` | `'-o eslint_report.json -f json --ext .js,.jsx,.ts,.tsx ./resources'` | Set of arguments passed to ESLint |
| Name | Default | Description |
|-----------------------|-----------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| `NPM_REGISTRY_DOMAIN` | `'https://npm.pkg.github.com/'` | Domain of the private npm registry |
| `NODE_VERSION` | 16 | Node version with which the assets will be compiled |
| `ESLINT_ARGS` | `'-o eslint_report.json -f json --ext .js,.jsx,.ts,.tsx ./resources'` | Set of arguments passed to ESLint |
| `PACKAGE_MANAGER` | `npm` | Package manager with which the dependencies should be installed (`npm` or yarn`). |

#### Secrets

Expand Down Expand Up @@ -68,11 +69,12 @@ jobs:

#### Inputs

| Name | Default | Description |
|-----------------------|----------------------------------------------------|-----------------------------------------------------------|
| `NPM_REGISTRY_DOMAIN` | `'https://npm.pkg.github.com/'` | Domain of the private npm registry |
| `NODE_VERSION` | 16 | Node version with which the unit tests are to be executed |
| `JEST_ARGS` | `'--reporters=default --reporters=github-actions'` | Set of arguments passed to Jest |
| Name | Default | Description |
|-----------------------|----------------------------------------------------|----------------------------------------------------------------------------------|
| `NPM_REGISTRY_DOMAIN` | `'https://npm.pkg.github.com/'` | Domain of the private npm registry |
| `NODE_VERSION` | 16 | Node version with which the unit tests are to be executed |
| `JEST_ARGS` | `'--reporters=default --reporters=github-actions'` | Set of arguments passed to Jest |
| `PACKAGE_MANAGER` | `npm` | Package manager with which the dependencies should be installed (`npm` or yarn`) |

**Note**: The default `github-actions` reporter requires Jest 28 or higher.

Expand Down
11 changes: 6 additions & 5 deletions docs/sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ jobs:

#### Inputs

| Name | Default | Description |
|-----------------------|---------------------------------|-----------------------------------------------------|
| `NPM_REGISTRY_DOMAIN` | `'https://npm.pkg.github.com/'` | Domain of the private npm registry |
| `NODE_VERSION` | 16 | Node version with which the assets will be compiled |
| `STYLELINT_ARGS` | `'./resources/**/*.scss'` | Set of arguments passed to Stylelint |
| Name | Default | Description |
|-----------------------|---------------------------------|----------------------------------------------------------------------------------|
| `NPM_REGISTRY_DOMAIN` | `'https://npm.pkg.github.com/'` | Domain of the private npm registry |
| `NODE_VERSION` | 16 | Node version with which the assets will be compiled |
| `STYLELINT_ARGS` | `'./resources/**/*.scss'` | Set of arguments passed to Stylelint |
| `PACKAGE_MANAGER` | `npm` | Package manager with which the dependencies should be installed (`npm` or yarn`) |

#### Secrets

Expand Down