/
action.yml
58 lines (51 loc) · 1.62 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
name: 'Deploy specified directory as a branch'
description: 'This action deploys directory as branch.'
inputs:
src_dir:
required: true
target_branch:
required: true
runs:
using: 'composite'
steps:
- name: Creating temporary directory to clone the branch
shell: bash
run: |
BRANCH_DIR=$(mktemp -d "`pwd`/$BRANCH_DIR_TEMPLATE")
echo "BRANCH_DIR=$BRANCH_DIR" >> $GITHUB_ENV
env:
BRANCH_DIR_TEMPLATE: 'cloned_${{ inputs.target_branch }}_XXXXXX'
- name: Checkout `${{ inputs.target_branch }}` branch
uses: actions/checkout@v2
with:
ref: ${{ inputs.target_branch }}
path: ${{ env.BRANCH_DIR }}
- name: Publish `${{ inputs.target_branch }}` branch
working-directory: ${{ env.BRANCH_DIR }}
shell: bash
run: |
echo '::echo::on'
echo '::group::Remove existing files first'
git rm -r .
echo '::endgroup::'
echo '::group::Move necessary files'
cp -vnR "$SRC_DIR/." .
echo '::endgroup::'
git add -A
if git diff --staged --quiet; then
echo 'Nothing to publish'
else
git config user.name 'GitHub Action Script'
git config user.email 'please@open.issue'
git commit -a -m "Deploy $SHA to '$TARGET_BRANCH' branch"
git push
echo 'Pushed'
fi
env:
SRC_DIR: '${{ github.workspace }}/${{ inputs.src_dir }}'
SHA: ${{ github.sha }}
TARGET_BRANCH: ${{ inputs.target_branch }}
- name: Remove cloned branch
if: ${{ always() }}
shell: bash
run: 'rm -rf "$BRANCH_DIR"'