Skip to content

Commit 7fb6489

Browse files
committed
An action to push a npm package contents to a branch
1 parent 18d62a2 commit 7fb6489

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
# put-built-npm-package-contents-on-branch
2-
An action to build an npm package and push it's contents to a branch
2+
3+
An action to build an npm package and push its contents to a branch.
4+
5+
**Note:** This action assumes there is only one tarball in the working-directory
6+
after the `pack` command. It will not work as expected with any others in the
7+
directory.
8+
9+
## Inputs
10+
11+
### `token` (required)
12+
13+
**Description:** A GitHub token with write access to the repository contents.
14+
Either a personal access token or `${{ secrets.GITHUB_TOKEN }}` if write access
15+
for that default token has been enabled in the repository settings.
16+
17+
### `working-directory` (default: `'./'`)
18+
19+
**Description:** The directory to run the pack command in. Should be the directory
20+
that contains the package you want to publish to the branch.
21+
22+
### `pack-command` (default: `npm pack`)
23+
24+
**Description:** The command to generate the package tarball.
25+
26+
### `branch` (default: `dist`)
27+
28+
**Description:** The branch to push the package contents to.
29+
30+
### `tmp-dir` (default: `./tmp/dist-action`)
31+
32+
**Description:** Empty directory where the package tarball will be extracted.
33+
This directory will be created if it does not exist. It will be deleted after
34+
the action is complete.
35+
36+
### `commit-message` (default: `"Publish dist for ${{ github.sha }}"`)
37+
38+
**Description:** The commit message to use when pushing the built package to the branch.
39+
40+
### `commit-author` (default: `github-actions[bot]`)
41+
42+
**Description:** The author to use when pushing the built package to the branch.
43+
44+
### `commit-email` (default: `github-actions[bot]@users.noreply.github.com`)
45+
46+
**Description:** The email to use when pushing the built package to the branch.

action.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Publish Built package to a branch
2+
description: Build each commit and publish to a branch
3+
author: Katie Gengler
4+
inputs:
5+
token:
6+
description: 'A GitHub token with write access to the repository contents'
7+
required: true
8+
working-directory:
9+
description: 'Directory in which to run the pack command'
10+
required: false
11+
default: './'
12+
pack-command:
13+
description: 'Command to generate the package tarball'
14+
required: false
15+
default: 'npm pack'
16+
branch:
17+
description: 'Branch name to push the contents to'
18+
required: false
19+
default: 'dist'
20+
tmp-dir:
21+
description: 'Empty directory in which to unpack the package tarball; will be created if it does not exist'
22+
required: false
23+
default: './tmp/dist-action'
24+
commit-message:
25+
description: 'Commit message to use when pushing to the branch'
26+
required: false
27+
default: 'Publish dist for ${{ github.sha }}'
28+
commit-user:
29+
description: 'Name of the user to use when committing to the branch'
30+
required: false
31+
default: 'github-actions[bot]'
32+
commit-email:
33+
description: 'Email of the user to use when committing to the branch'
34+
required: false
35+
default: 'github-actions[bot]@users.noreply.github.com'
36+
37+
runs:
38+
using: "composite"
39+
steps:
40+
- name: 'Pack'
41+
shell: 'bash'
42+
run: ${{ inputs.pack-command }}
43+
working-directory: ${{ inputs.working-directory }}
44+
- name: 'Make tmpdir'
45+
shell: 'bash'
46+
run: mkdir -p ${{ inputs.tmp-dir }}
47+
working-directory: ${{ inputs.working-directory }}
48+
- name: 'Unpack'
49+
shell: 'bash'
50+
run: tar -xvzf *.tgz -C ${{ inputs.tmp-dir }}
51+
working-directory: ${{ inputs.working-directory }}
52+
- name: 'Upload published package contents to branch'
53+
shell: 'bash'
54+
run: |
55+
cd tmp/dist-action/package
56+
git config --global init.defaultBranch main
57+
git init
58+
git config user.name ${{ inputs.commit-user }}
59+
git config user.email ${{ inputs.commit-email }}
60+
git add .
61+
git commit -m ${{ inputs.commit-message }}
62+
git push --force "https://${{ github.actor }}:${{ inputs.token }}@github.com/${{ github.repository }}" main:${{ inputs.branch }}
63+
working-directory: ${{ inputs.working-directory }}
64+
- name: 'Cleanup'
65+
shell: 'bash'
66+
run: rm -rf ${{ inputs.tmp-dir }}
67+
working-directory: ${{ inputs.working-directory }}

0 commit comments

Comments
 (0)