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

Support subdirectory #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,36 @@ inputs:
node-version:
description: "Override the default node version, or override what is specified in your project's volta config"
required: false
node-version-file:
node-version-file:
description: "Override where the default node version is read from. By default this reads from package.json, which includes support for volta.node. Specifying node-version will override this"
required: false
default: 'package.json'
node-registry-url:
description: "Optional registry to set up for auth. Will set the registry in a project level .npmrc and .yarnrc file, and set up auth to read in from env.NODE_AUTH_TOKEN."
required: false
default: ''

cache-dependency-path:
description: "Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. It will generate hash from the target file for primary key. It works only If cache is specified. Supports wildcards or a list of file names for caching multiple dependencies."
required: false
default: ''

########################
# For pnpm/setup-action
########################
########################
pnpm-version:
description: 'Override the default pnpm version, which defaults to the latest 8.x'
required: false
args:
description: 'Directly pass args to pnpm'
required: false

########################
# For wyvox/action-setup-pnpm
########################
working-directory:
description: ''
required: false

runs:
using: 'composite'
steps:
Expand All @@ -44,13 +55,13 @@ runs:
# 3. package.json#packageManager
# 4. default pnpm version (^8.0.0)
run: |
if [ ! -f "package.json" ]; then
if [ ! -f "${{inputs.node-version-file}}" ]; then
echo "Could not find package.json. Did actions/checkout run?"
exit 1
fi

forcedVersion=${{inputs.pnpm-version}}
packageJson=$(cat package.json)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will error if node-version-file is not a json file.

node-version-file is meant for setup-node, rather than just the package.json. it can be an .nvmrc, .node-version, etc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe instead, the working-directory should prefix?

packageJson=$(cat ${{inputs.node-version-file}})
# when using jq, we unquote, trim extra invisibles, and then remove "null" from the output
packageManager=$(echo $packageJson | jq -r '.packageManager' | tr -dc '[:print:]' | sed "s/null//g" )
voltaPnpm=$(echo $packageJson | jq -r '.volta.pnpm' | tr -dc '[:print:]' | sed "s/null//g" )
Expand All @@ -69,33 +80,33 @@ runs:
echo "Using inputs.pnpm-version"
__resolved_version__=$forcedVersion
return
else
else
echo "No pnpm-version override detected"
fi

if [ "$voltaPnpm" != "" ]; then
echo "Using package.json#volta.pnpm"
__resolved_version__=$voltaPnpm
return
else
else
echo "package.json#volta.pnpm was not defined"
fi

if [[ "$packageManager" =~ ^"pnpm" ]]; then
version=$(echo $packageManager | cut -d "@" -f2)
if [[ "$version" != "" && "$version" != "$packageManager" ]]; then

if [[ "$version" != "" && "$version" != "$packageManager" ]]; then
echo "Using package.json#packageManager"
__resolved_version__=$version
return
else
else
echo "package.json#packageManager ($packageManager) did not specify a version"
fi
else
echo "package.json#packageManager ($packageManager) did not start with 'pnpm' or was not defined."
fi

# default
# default
__resolved_version__=8
}

Expand All @@ -107,9 +118,9 @@ runs:
echo "version=$__resolved_version__" >> $GITHUB_OUTPUT

# The pnpm action:
# - no support for volta
# - no support for volta
# (or other places the pnpm version can be specified, such as package.json)
# - no support for cache
# - no support for cache
# (that's provided by setup-node)
- name: 'Install pnpm'
uses: pnpm/action-setup@v2
Expand All @@ -118,7 +129,7 @@ runs:
run_install: false

# The Node Action
# - cache is turned off by default
# - cache is turned off by default
# - implements the same cache recommended in the pnpm/action-setup readme
# - support for volta for node only, volta is not actually installed
# We don't want to install volta, as it turns out, because volta, as an action, hasn't been stable
Expand All @@ -139,10 +150,12 @@ runs:
# Default node version read from package.json, but can be changed by passing in inputs.node-version-file
node-version-file: ${{ inputs.node-version-file }}
registry-url: ${{ inputs.node-registry-url }}
cache-dependency-path: ${{ inputs.cache-dependency-path }}

# It's only efficient to install dependencies
# after the cache is set up -- otherwise we don't cache anything.
# (the cache is set up in setup-node@v3+)
- name: 'Install dependencies'
shell: 'bash'
run: pnpm install ${{ inputs.args }}
working-directory: ${{ inputs.working-directory }}