Skip to content

Commit 597f8aa

Browse files
authored
feat: add option to skip install_dependencies for run_script (#36)
The `skip_install_dependencies` flag allows running scripts without installing dependencies first. Intended for jobs with multiple `run_script` commands.
1 parent 2726fe3 commit 597f8aa

File tree

3 files changed

+41
-7
lines changed

3 files changed

+41
-7
lines changed

.circleci/test-deploy.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,28 @@ jobs:
112112
name: Print output file
113113
working_directory: ~/project/sample
114114
command: cat results_pnpm.json
115-
115+
run-script-skip-install-dependencies:
116+
executor: core/node
117+
steps:
118+
- checkout
119+
- core/install_dependencies:
120+
pkg_manager: pnpm
121+
pkg_json_dir: ~/project/sample
122+
- run:
123+
name: Unset CURRENT_PKG_MANAGER env
124+
command: echo "export CURRENT_PKG_MANAGER=''" >> "${BASH_ENV}"
125+
- core/run_script:
126+
pkg_manager: pnpm
127+
pkg_json_dir: ~/project/sample
128+
skip_install_dependencies: true
129+
script: test --json --outputFile=results_pnpm.json
130+
- run:
131+
name: Verfiy install_dependencies was skipped
132+
command: |
133+
if [[ -n "${CURRENT_PKG_MANAGER}" ]]; then
134+
echo "The install_dependencies command was not skipped"
135+
exit 1
136+
fi
116137
workflows:
117138
test-deploy:
118139
jobs:
@@ -132,6 +153,8 @@ workflows:
132153
filters: *filters
133154
- run-script-pnpm:
134155
filters: *filters
156+
- run-script-skip-install-dependencies:
157+
filters: *filters
135158
- orb-tools/pack:
136159
filters: *release-filters
137160
- orb-tools/publish:
@@ -148,5 +171,6 @@ workflows:
148171
- install-dependencies-custom-command
149172
- run-script-npm
150173
- run-script-pnpm
174+
- run-script-skip-install-dependencies
151175
context: orb-publishing
152176
filters: *release-filters

src/commands/run_script.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ parameters:
2727
type: string
2828
default: 'v1'
2929
description: Change the default cache version if the cache needs to be cleared for some reason.
30+
skip_install_dependencies:
31+
type: boolean
32+
default: false
33+
description: |
34+
The flag indicating whether to skip installing dependencies.
35+
Useful in a case of multiple `run_script` commands inside a single job.
3036
script:
3137
type: string
3238
default: ''
@@ -35,15 +41,19 @@ parameters:
3541
manager, meaning it can contain arguments as well.
3642
3743
steps:
38-
- install_dependencies:
39-
pkg_manager: <<parameters.pkg_manager>>
40-
pkg_json_dir: <<parameters.pkg_json_dir>>
41-
install_command: <<parameters.install_command>>
42-
cache_version: <<parameters.cache_version>>
44+
- unless:
45+
condition: <<parameters.skip_install_dependencies>>
46+
steps:
47+
- install_dependencies:
48+
pkg_manager: <<parameters.pkg_manager>>
49+
pkg_json_dir: <<parameters.pkg_json_dir>>
50+
install_command: <<parameters.install_command>>
51+
cache_version: <<parameters.cache_version>>
4352
- run:
4453
name: Run "<<parameters.script>>" with "<<parameters.pkg_manager>>"
4554
working_directory: <<parameters.pkg_json_dir>>
4655
environment:
56+
PARAM_STR_PKG_MANAGER: <<parameters.pkg_manager>>
4757
PARAM_STR_SCRIPT: <<parameters.script>>
4858
command: <<include(scripts/run-script.sh)>>
4959

src/scripts/run-script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
echo "Running custom script from package.json at ${PWD}"
44

55
set -x
6-
eval "${CURRENT_PKG_MANAGER}" run "${PARAM_STR_SCRIPT}"
6+
eval "${PARAM_STR_PKG_MANAGER}" run "${PARAM_STR_SCRIPT}"
77
set +x

0 commit comments

Comments
 (0)