-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yaml
200 lines (169 loc) · 6.43 KB
/
action.yaml
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
name: Scalingo Setup CLI
description: Install and configure the Scalingo CLI so you can deploy and manage your apps on Scalingo.
branding:
icon: terminal
color: blue
inputs:
api_token:
description: 'Scalingo API token'
required: false
region:
description: 'Region of the Scalingo app'
required: true
version:
description: 'Scalingo CLI version to install'
required: false
default: 'latest'
app_name:
description: 'Name of the Scalingo app'
required: false
git_remote:
description: 'Choose the name of Git remote to allow git operations (requires the `region` and `app_name` inputs)'
required: false
default: 'scalingo'
# Options for debugging or internal use
scalingo_api_url:
description: 'Scalingo API URL'
required: false
scalingo_auth_url:
description: 'Scalingo Auth URL'
required: false
unsecure_ssl:
description: 'Disable SSL verification'
required: false
scalingo_db_url:
description: 'Scalingo DB URL'
required: false
scalingo_ssh_host:
description: 'Scalingo SSH Host'
required: false
runs:
using: "composite"
steps:
- name: Install Scalingo CLI
run: |
echo "------> Installing Scalingo client..."
if [ "x$DEBUG" = "xtrue" ] ; then
set -x
fi
os=$(uname -s | tr '[A-Z]' '[a-z]')
ext='tar.gz'
if [ "$os" != "linux" ] && [ "$os" != "darwin" ]; then
echo "Unsupported OS: $(uname -s)"
exit 1
fi
echo "------> Platform detected: $os"
arch=$(uname -m)
case $arch in
x86_64)
arch=amd64
;;
aarch64)
arch=arm64
;;
i686)
arch=386
;;
esac
echo "------> Architecture detected: $arch"
tmpdir=$(mktemp -d /tmp/scalingo_cli_XXX)
if [[ "${SCALINGO_CLI_VERSION}" == "latest" ]]; then
version=$(curl --silent https://cli-dl.scalingo.com/version | tr -d ' \t\n')
else
version="${SCALINGO_CLI_VERSION}"
fi
if [ -z "$version" ]; then
echo "------> Fail to get the version of the CLI" >&2
echo "You should use the 'version' input with the desired version." >&2
exit 1
fi
echo "------> Version of the CLI to install: $version"
dirname="scalingo_${version}_${os}_${arch}"
archive_name="${dirname}.${ext}"
url=https://github.com/Scalingo/cli/releases/download/${version}/${archive_name}
echo "------> Downloading Scalingo client... "
curl --silent --fail --location --output ${tmpdir}/${archive_name} ${url}
if [ ! -f ${tmpdir}/${archive_name} ]; then
echo "" >&2
echo "ERROR-> Fail to download the CLI archive" >&2
exit 1
fi
echo "------> Scalingo client downloaded"
echo "------> Extracting... "
tar -C "${tmpdir}" -x -f "${tmpdir}/${archive_name}"
exe_path=${tmpdir}/${dirname}/scalingo
if [ ! -f "$exe_path" ]; then
echo "" >&2
echo "------> Fail to extract the CLI archive" >&2
exit 1
fi
echo "Binary extracted"
target_dir="${{ github.action_path }}/bin"
mkdir "${target_dir}"
target="${target_dir}/scalingo"
mv $exe_path "$target" ; rc=$?
if [ $rc -ne 0 ] ; then
echo " ! Fail to install Scalingo client (return $rc)"
else
echo "------> Installation completed, the command 'scalingo' is available."
fi
echo ${{github.action_path}}/bin/ >> ${GITHUB_PATH}
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
SCALINGO_CLI_VERSION: ${{ inputs.version }}
- name: Configure Scalingo CLI
shell: bash
run: |
echo "------> Configuring Scalingo CLI"
echo "LOG_FILE=/dev/stdout" >> $GITHUB_ENV
# Disable the update checker
echo "DISABLE_UPDATE_CHECKER=true" >> $GITHUB_ENV
export DISABLE_UPDATE_CHECKER=true
echo "DISABLE_INTERACTIVE=true" >> $GITHUB_ENV
export DISABLE_INTERACTIVE=true
# Configure development urls for debugging purposes
[[ -n "${UNSECURE_SSL}" ]] && echo "UNSECURE_SSL=${UNSECURE_SSL}" >> $GITHUB_ENV
[[ -n "${SCALINGO_API_URL}" ]] && echo "SCALINGO_API_URL=${SCALINGO_API_URL}" >> $GITHUB_ENV
[[ -n "${SCALINGO_AUTH_URL}" ]] && echo "SCALINGO_AUTH_URL=${SCALINGO_AUTH_URL}" >> $GITHUB_ENV
[[ -n "${SCALINGO_DB_URL}" ]] && echo "SCALINGO_DB_URL=${SCALINGO_DB_URL}" >> $GITHUB_ENV
[[ -n "${SCALINGO_SSH_HOST}" ]] && echo "SCALINGO_SSH_HOST=${SCALINGO_SSH_HOST}" >> $GITHUB_ENV
echo "------> Set the region to ${SCALINGO_REGION}"
echo "SCALINGO_REGION=${SCALINGO_REGION}" >> $GITHUB_ENV
if [[ -n "${SCALINGO_API_TOKEN}" ]]; then
echo "------> Log in to Scalingo with API token"
scalingo login --api-token ${SCALINGO_API_TOKEN} >&1 2>&1
scalingo config --region ${SCALINGO_REGION} >&1 2>&1
fi
if [[ -n "${SCALINGO_APP}" ]]; then
echo "------> Set the default app to ${SCALINGO_APP}"
echo "SCALINGO_APP=${SCALINGO_APP}" >> $GITHUB_ENV
fi
env:
SCALINGO_API_TOKEN: ${{ inputs.api_token }}
SCALINGO_REGION: ${{ inputs.region }}
SCALINGO_APP: ${{ inputs.app_name }}
SCALINGO_API_URL: ${{ inputs.scalingo_api_url }}
SCALINGO_AUTH_URL: ${{ inputs.scalingo_auth_url }}
SCALINGO_DB_URL: ${{ inputs.scalingo_db_url }}
SCALINGO_SSH_HOST: ${{ inputs.scalingo_ssh_host }}
UNSECURE_SSL: ${{ inputs.unsecure_ssl }}
- name: Configure Scalingo Git remote
shell: bash
run: |
echo "------> Configure Scalingo Git remote"
if [ -z $SCALINGO_APP ]; then
echo "------> No region. The git remote cannot be configured without a region."
exit 0
fi
if [ -z $SCALINGO_REGION ]; then
echo "WARNING: No app name. The git remote cannot be configured without an app name."
exit 0
fi
# Configure the git remote only if .git directory exists
if [ ! -d .git ]; then
echo "------> No .git directory found, skipping git remote configuration"
exit 0
fi
scalingo git-setup --remote ${{ inputs.git_remote }}
echo "------> Git remote \"${{ inputs.git_remote }}\" configured"