Skip to content

Commit

Permalink
An action to push a npm package contents to a branch
Browse files Browse the repository at this point in the history
  • Loading branch information
kategengler committed Feb 22, 2023
1 parent 18d62a2 commit 7fb6489
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 1 deletion.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,46 @@
# put-built-npm-package-contents-on-branch
An action to build an npm package and push it's contents to a branch

An action to build an npm package and push its contents to a branch.

**Note:** This action assumes there is only one tarball in the working-directory
after the `pack` command. It will not work as expected with any others in the
directory.

## Inputs

### `token` (required)

**Description:** A GitHub token with write access to the repository contents.
Either a personal access token or `${{ secrets.GITHUB_TOKEN }}` if write access
for that default token has been enabled in the repository settings.

### `working-directory` (default: `'./'`)

**Description:** The directory to run the pack command in. Should be the directory
that contains the package you want to publish to the branch.

### `pack-command` (default: `npm pack`)

**Description:** The command to generate the package tarball.

### `branch` (default: `dist`)

**Description:** The branch to push the package contents to.

### `tmp-dir` (default: `./tmp/dist-action`)

**Description:** Empty directory where the package tarball will be extracted.
This directory will be created if it does not exist. It will be deleted after
the action is complete.

### `commit-message` (default: `"Publish dist for ${{ github.sha }}"`)

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

### `commit-author` (default: `github-actions[bot]`)

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

### `commit-email` (default: `github-actions[bot]@users.noreply.github.com`)

**Description:** The email to use when pushing the built package to the branch.
67 changes: 67 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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'

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: '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 }}

0 comments on commit 7fb6489

Please sign in to comment.