-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
119 lines (109 loc) · 3.98 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
name: 'Commit To Repo'
description: 'Commits local files specified to a repository.'
author: 'Tensure'
branding:
icon: 'git-commit'
color: 'blue'
inputs:
branch:
description: 'An optional repository branch to checkout and commit to. Will use whatever the default branch of the destination repo is, if not specified.'
required: false
default: ''
files:
description: 'A list of local files to commit. Paths are relative to the root of the base working directory.'
required: true
github-pat:
description: 'A custom token to use.'
required: false
default: ''
github-app-id:
description: 'The app ID of a Github App. Do not provide if github-pat-token is provided.'
required: false
default: ''
github-app-private-key:
description: 'The private key for a Github App. Do not provide if github-pat-token is provided.'
required: false
default: ''
github-owner:
description: 'The Github owner of the repository.'
required: true
github-repository:
description: 'The Github repository to commit to.'
required: true
path:
description: 'An optional path in the destination repository to place the files.'
required: false
default: '.'
runs:
using: "composite"
steps:
- name: Output PAT To Environment
if: ${{ inputs.github-pat != '' }}
shell: bash
run: |
echo "Attempting to use PAT credential...";
echo "GITHUB_TOKEN=${{ inputs.github-pat }}" >> ${GITHUB_ENV}
- name: Get Token From App
if: ${{ inputs.github-app-id != '' && inputs.github-app-private-key != '' }}
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ inputs.github-app-id }}
private-key: ${{ inputs.github-app-private-key }}
owner: ${{ inputs.github-owner }}
repositories: ${{ inputs.github-repository }}
- name: Output App Token To Environment
if: ${{ inputs.github-app-id != '' && inputs.github-app-private-key != '' }}
shell: bash
run: |
echo "Attempting to use Github App credentials..."
echo "GITHUB_TOKEN=${{ steps.app-token.outputs.token }}" >> ${GITHUB_ENV}
- name: Get Short SHA
shell: bash
id: short-sha
run: echo "SHA_VALUE=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Validate Destination Directory Doesn't Exist
shell: bash
run: |
# make sure the destination directory doesn't exist
rm -rf ${{ inputs.github-repository }}
- name: Clone Destination Repo
shell: bash
run: |
# only provide branch if specified
BRANCH=""
if [[ ! -z "${{ inputs.branch }}" ]]; then
BRANCH="-b ${{ inputs.branch }}";
fi
# clone the repo
git clone ${BRANCH} https://x-access-token:${GITHUB_TOKEN}@github.com/${{ inputs.github-owner }}/${{ inputs.github-repository }}.git
- name: Configure Git
shell: bash
working-directory: ${{ inputs.github-repository }}
run: |
git config user.email "commit-to-repo@tensure.io"
git config user.name "CommitBot"
- name: Validate Destination Path Exists
shell: bash
working-directory: ${{ inputs.github-repository }}
run: |
# make sure destination path exists
mkdir -p "${{ inputs.path }}"
- name: Add Files Specified
shell: bash
working-directory: ${{ inputs.github-repository }}
run: |
# loop over files
while IFS= read -r FILE; do
FROM="../${FILE}";
TO="${{ inputs.path }}/$(basename ${FILE})";
echo "Processing '${FROM}' to '${TO}'...";
cp ${FROM} ${TO}
git add ${TO}
done <<< '${{ inputs.files }}';
- name: Commit Changes
shell: bash
working-directory: ${{ inputs.github-repository }}
run: |
REPO_LOWER=$(echo "${{ github.repository }}" | awk '{print tolower($0)}')
git diff-index --quiet HEAD || git commit -m "patched in ${REPO_LOWER}@${GITHUB_SHA::7}" && git push origin