|
| 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