Skip to content

Commit

Permalink
Merge pull request #2 from chancancode/omit-scripts
Browse files Browse the repository at this point in the history
By default, omit `prepack` and `postpack` scripts
  • Loading branch information
kategengler authored Sep 11, 2023
2 parents e252eed + 4a97cdf commit 5b33924
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,29 @@ the action is complete.
### `commit-email` (default: `github-actions[bot]@users.noreply.github.com`)

**Description:** The email to use when pushing the built package to the branch.

### `omit-scripts` (default: `prepack,postpack`)

**Description:** Comma separated list of scripts to omit from `package.json`
after packing, or "*" to omit everything.

**Why is this needed?** Package managers differ in opinion on what scripts to
run when installing dependencies from Git. Some package managers do nothing at
all, and some choose to run `pack` command and the `prepack`/`postpack` scripts
along with it.

A common reason for using this workflow is to push the already-packed content
to a dist branch in order to support package manages that does not run the
`pack` script when installing a Git dependency.

However, on package managers that runs the `pack` command, they may encounter
issues when installing from the dist branch. For example, the Ember's v2 addons
has `"prepack": "rollup --config"`, but since the rollup config file is omitted
from the packed tarball, the command will fail.
Therefore, by default, we omit the `prepack` and `postpack` scripts from the
resulting `package.json` before pushing, in order to normalize this difference
across package managers. Running these scripts should be entirely unnecessary
when installing from the dist branch.

You can opt-out of this behavior by setting `omit-scripts` to an empty string.
23 changes: 23 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ inputs:
description: 'Email of the user to use when committing to the branch'
required: false
default: 'github-actions[bot]@users.noreply.github.com'
omit-scripts:
description: 'Comma separated list of scripts to omit from package.json after packing, or "*" to omit everything'
required: false
default: 'prepack,postpack'

runs:
using: "composite"
Expand All @@ -49,6 +53,25 @@ runs:
shell: 'bash'
run: tar -xvzf *.tgz -C ${{ inputs.tmp-dir }}
working-directory: ${{ inputs.working-directory }}
- name: 'Omit Scripts'
shell: 'bash'
env:
OMIT_SCRIPTS: ${{ inputs.omit-scripts }}
OUTPUT_DIR: ${{ inputs.tmp-dir }}
run: |
OUTPUT_FILE="$OUTPUT_DIR/package/package.json"
if [[ "$OMIT_SCRIPTS" == "*" ]]; then
jq '. | del(.scripts)' package.json > "$OUTPUT_FILE"
elif [[ ! -z "$OMIT_SCRIPTS" ]]; then
JQ_COMMAND="."
IFS=',' read -ra SCRIPTS <<< "$OMIT_SCRIPTS"
for SCRIPT in "${SCRIPTS[@]}"; do
JQ_COMMAND="$JQ_COMMAND | del(.scripts.\"$SCRIPT\")"
done
jq "$JQ_COMMAND" package.json > "$OUTPUT_FILE"
fi
working-directory: ${{ inputs.working-directory }}
- name: 'Upload published package contents to branch'
shell: 'bash'
run: |
Expand Down

0 comments on commit 5b33924

Please sign in to comment.