-
Notifications
You must be signed in to change notification settings - Fork 6
/
action.yml
99 lines (87 loc) · 3.9 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
name: 'Create Other Repo Branch Action'
description: 'Github Action to create a new branch on another repository 🆕🚀'
inputs:
repository_owner:
description: 'Repository Owner (e.g: octocat)'
required: true
repository_name:
description: 'Repository Name (e.g: my-repo)'
required: false
new_branch_name:
description: 'New branch name created on other repository (e.g: release-*.*.*)'
required: true
new_branch_ref:
description: 'Ref to create the new branch name on other repository (e.g: main)'
required: false
access_token:
description: 'A PAT that has access to the repository (if necessary). Not to be combined with ssh_deploy_key'
required: false
ignore_branch_exists:
description: 'If the branch already exists then do not attempt to create branch'
required: false
ssh_deploy_key:
description: 'Allows cloning of git reposorties via SSH Key. Not to be combined with access_token'
required: false
git_user_name:
description: 'Allows setting user.name in git config'
required: false
default: github-actions
git_user_email:
description: 'Allows setting user.email in git config'
required: false
default: github-actions@github.com
runs:
using: "composite"
steps:
- name: Clone informed repository
run: |
# If access_token and ssh_deploy_key are defined then error out.
if [ ! -z "${{ inputs.access_token }}" ] && [ ! -z "${{ inputs.ssh_deploy_key }}" ]; then
echo "Error: access_token and ssh_deploy_key are defined. Please only use one."
exit 1
fi
if [ ! -z "${{ inputs.access_token }}" ]; then
git clone https://${{ inputs.access_token }}@github.com/${{ inputs.repository_owner }}/${{ inputs.repository_name }}.git
elif [ ! -z "${{ inputs.ssh_deploy_key }}" ]; then
mkdir --parents "$HOME/.ssh"
DEPLOY_KEY_FILE="$HOME/.ssh/deploy_key"
echo "${{ inputs.ssh_deploy_key }}" > "$DEPLOY_KEY_FILE"
chmod 600 "$DEPLOY_KEY_FILE"
SSH_KNOWN_HOSTS_FILE="$HOME/.ssh/known_hosts"
ssh-keyscan -H "github.com" > "$SSH_KNOWN_HOSTS_FILE"
export GIT_SSH_COMMAND="ssh -i "$DEPLOY_KEY_FILE" -o UserKnownHostsFile=$SSH_KNOWN_HOSTS_FILE"
git clone git@github.com:${{ inputs.repository_owner }}/${{ inputs.repository_name }}.git
else
git clone https://github.com/${{ inputs.repository_owner }}/${{ inputs.repository_name }}.git
fi
if [ -d "${{ inputs.repository_name }}" ]; then
echo "Cloned ${{ inputs.repository_name }} repository successfully."
else
echo "Error: Couldn't clone ${{ inputs.repository_name }} repository. Check the inputs or the PAT scope."
exit 1
fi
shell: bash
- name: Create new branch
run: |
cd ${{ inputs.repository_name }}
git init
if [ -n "${{ inputs.new_branch_ref }}" ]; then
git fetch -a
git checkout ${{ inputs.new_branch_ref }}
fi
if [ ! -z "${{ inputs.ignore_branch_exists }}" ] && [ ! -z $(git branch --remotes --list 'origin/${{ inputs.new_branch_name }}') ]; then
echo "[INFO] Branch ${{ inputs.new_branch_ref }} already exists. Skipping branch creation"
exit 0
fi
if [ ! -z $(git branch --remotes --list 'origin/${{ inputs.new_branch_name }}') ]; then
echo "Error: The branch name ${{ inputs.new_branch_name }} is already used."
exit 1
fi
git checkout -b ${{ inputs.new_branch_name }}
git config user.name ${{ inputs.git_user_name }}
git config user.email ${{ inputs.git_user_email }}
git push origin ${{ inputs.new_branch_name }}
shell: bash
branding:
icon: 'git-branch'
color: 'blue'