-
Notifications
You must be signed in to change notification settings - Fork 1
/
release-it-entrypoint.sh
executable file
·105 lines (85 loc) · 3.32 KB
/
release-it-entrypoint.sh
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
#!/bin/bash
set -e
GIT_DIRECTORY="${GIT_DIRECTORY:-}"
GIT_EMAIL="${GIT_EMAIL:-}"
GIT_REPOSITORY="${GIT_REPOSITORY:-}"
GIT_USERNAME="${GIT_USERNAME:-}"
GPG_PRIVATE_KEY="${GPG_PRIVATE_KEY:-}"
GPG_PRIVATE_KEY_ID="${GPG_PRIVATE_KEY_ID:-}"
RELEASE_IT_PLUGINS=${RELEASE_IT_PLUGINS:-}
RELEASE_IT_VERSION=${RELEASE_IT_VERSION:-latest}
SSH_PASSPHRASE="${SSH_PASSPHRASE:-}"
SSH_PRIVATE_KEY="${SSH_PRIVATE_KEY:-}"
if [[ -n "${GIT_DIRECTORY}" ]]; then
# Add safe directory to git global configuration
git config --global --add safe.directory "${GIT_DIRECTORY}"
fi
if [[ -n "${GIT_EMAIL}" ]]; then
git config --global user.email "${GIT_EMAIL}"
fi
if [[ -n "${GIT_REPOSITORY}" ]]; then
# Set remote repository URL
git remote set-url origin "${GIT_REPOSITORY}"
fi
if [[ -n "${GIT_USERNAME}" ]]; then
git config --global user.name "${GIT_USERNAME}"
fi
if [[ -n "${GPG_PRIVATE_KEY_ID}" && -n "${GPG_PRIVATE_KEY}" ]]; then
# Enable GPG signing for commits globally
git config --global commit.gpgSign true
# Set the GPG key for signing commits
git config --global user.signingkey "${GPG_PRIVATE_KEY_ID}"
if { gpg --import <(echo "${GPG_PRIVATE_KEY}"); } &>/dev/null; then
echo "GPG private key imported successfully"
else
echo "Error setting up GPG private key"
exit 1
fi
else
echo "GPG_PRIVATE_KEY_ID or GPG_PRIVATE_KEY are not provided. GPG setup skipped."
fi
if [[ -n "${SSH_PRIVATE_KEY}" ]]; then
# Create SSH directory and set permissions
mkdir -p ~/.ssh
chmod 700 ~/.ssh
# Disable strict host key checking for CI Environment
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" >> ~/.ssh/config
# Write the private key to the id_rsa file
echo "${SSH_PRIVATE_KEY}" > ~/.ssh/id_rsa
# Set permissions for the private key
chmod 600 ~/.ssh/id_rsa
# Start SSH agent
if eval "$(ssh-agent -s)" > /dev/null; then
echo "SSH agent started successfully"
else
echo "Error starting SSH agent"
exit 1
fi
# Add private key to SSH agent
if { echo "${SSH_PASSPHRASE}" | ssh-add ~/.ssh/id_rsa; } &>/dev/null; then
echo "SSH private key added to the agent successfully"
else
echo "Error adding SSH private key to the agent"
exit 1
fi
else
echo "SSH_PRIVATE_KEY is not provided. SSH setup skipped"
fi
# Configure NPM global settings
# Adjust the global directory for NPM to a location with full permissions for the node user, set during the image build
NPM_GLOBAL_DIR=/home/node/.npm-global
PATH=${NPM_GLOBAL_DIR}/bin:${PATH}
mkdir -p "${NPM_GLOBAL_DIR}"
export NPM_CONFIG_PREFIX="${NPM_GLOBAL_DIR}"
export NPM_CONFIG_PROGRESS=false
export NPM_CONFIG_UPDATE_NOTIFIER=false
# Split the plugin list into an installable command
IFS=',' read -ra RELEASE_IT_PLUGINS_LIST <<< "${RELEASE_IT_PLUGINS}"
RELEASE_IT_PLUGINS_SEPARATED="${RELEASE_IT_PLUGINS_LIST[*]}"
echo "Installing release-it..."
# To streamline the installation process, globally install release-it along with any required plugins.
# shellcheck disable=SC2086 # The variable RELEASE_IT_PLUGINS_SEPARATED is appropriately split to facilitate the installation of plugins.
npm install --silent --global release-it@${RELEASE_IT_VERSION} ${RELEASE_IT_PLUGINS_SEPARATED}
# Execute the provided command to release-it
echo "Executing release-it..."
exec "$@"