-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
90 lines (88 loc) · 3.21 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Publish Built package to a branch
description: Build each commit and publish to a branch
author: Katie Gengler
inputs:
token:
description: 'A GitHub token with write access to the repository contents'
required: true
working-directory:
description: 'Directory in which to run the pack command'
required: false
default: './'
pack-command:
description: 'Command to generate the package tarball'
required: false
default: 'npm pack'
branch:
description: 'Branch name to push the contents to'
required: false
default: 'dist'
tmp-dir:
description: 'Empty directory in which to unpack the package tarball; will be created if it does not exist'
required: false
default: './tmp/dist-action'
commit-message:
description: 'Commit message to use when pushing to the branch'
required: false
default: 'Publish dist for ${{ github.sha }}'
commit-user:
description: 'Name of the user to use when committing to the branch'
required: false
default: 'github-actions[bot]'
commit-email:
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"
steps:
- name: 'Pack'
shell: 'bash'
run: ${{ inputs.pack-command }}
working-directory: ${{ inputs.working-directory }}
- name: 'Make tmpdir'
shell: 'bash'
run: mkdir -p ${{ inputs.tmp-dir }}
working-directory: ${{ inputs.working-directory }}
- name: 'Unpack'
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: |
cd tmp/dist-action/package
git config --global init.defaultBranch main
git init
git config user.name "${{ inputs.commit-user }}"
git config user.email "${{ inputs.commit-email }}"
git add .
git commit -m "${{ inputs.commit-message }}"
git push --force "https://${{ github.actor }}:${{ inputs.token }}@github.com/${{ github.repository }}" main:${{ inputs.branch }}
working-directory: ${{ inputs.working-directory }}
- name: 'Cleanup'
shell: 'bash'
run: rm -rf ${{ inputs.tmp-dir }}
working-directory: ${{ inputs.working-directory }}