|
| 1 | +name: Scalingo Install CLI Action |
| 2 | +description: Install and configure the Scalingo CLI so you can deploy and manage your apps on Scalingo. |
| 3 | +inputs: |
| 4 | + api_token: |
| 5 | + description: 'Scalingo API token' |
| 6 | + required: false |
| 7 | + region: |
| 8 | + description: 'Region of the Scalingo app' |
| 9 | + required: true |
| 10 | + version: |
| 11 | + description: 'Scalingo CLI version to install' |
| 12 | + required: false |
| 13 | + default: 'latest' |
| 14 | + app_name: |
| 15 | + description: 'Name of the Scalingo app' |
| 16 | + required: false |
| 17 | + git_remote: |
| 18 | + description: 'Choose the name of Git remote to allow git operations (requires the `region` and `app_name` inputs)' |
| 19 | + required: false |
| 20 | + default: 'scalingo' |
| 21 | + |
| 22 | + # Options for debugging or internal use |
| 23 | + scalingo_api_url: |
| 24 | + description: 'Scalingo API URL' |
| 25 | + required: false |
| 26 | + scalingo_auth_url: |
| 27 | + description: 'Scalingo Auth URL' |
| 28 | + required: false |
| 29 | + unsecure_ssl: |
| 30 | + description: 'Disable SSL verification' |
| 31 | + required: false |
| 32 | + scalingo_db_url: |
| 33 | + description: 'Scalingo DB URL' |
| 34 | + required: false |
| 35 | + scalingo_ssh_host: |
| 36 | + description: 'Scalingo SSH Host' |
| 37 | + required: false |
| 38 | +runs: |
| 39 | + using: "composite" |
| 40 | + steps: |
| 41 | + - name: Install Scalingo CLI |
| 42 | + run: | |
| 43 | + echo "------> Installing Scalingo client..." |
| 44 | +
|
| 45 | + if [ "x$DEBUG" = "xtrue" ] ; then |
| 46 | + set -x |
| 47 | + fi |
| 48 | +
|
| 49 | + os=$(uname -s | tr '[A-Z]' '[a-z]') |
| 50 | + ext='tar.gz' |
| 51 | + if [ "$os" != "linux" ] && [ "$os" != "darwin" ]; then |
| 52 | + echo "Unsupported OS: $(uname -s)" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + echo "------> Platform detected: $os" |
| 57 | +
|
| 58 | + arch=$(uname -m) |
| 59 | + case $arch in |
| 60 | + x86_64) |
| 61 | + arch=amd64 |
| 62 | + ;; |
| 63 | + aarch64) |
| 64 | + arch=arm64 |
| 65 | + ;; |
| 66 | + i686) |
| 67 | + arch=386 |
| 68 | + ;; |
| 69 | + esac |
| 70 | +
|
| 71 | + echo "------> Architecture detected: $arch" |
| 72 | +
|
| 73 | + tmpdir=$(mktemp -d /tmp/scalingo_cli_XXX) |
| 74 | +
|
| 75 | + if [[ "${SCALINGO_CLI_VERSION}" == "latest" ]]; then |
| 76 | + version=$(curl --silent https://cli-dl.scalingo.com/version | tr -d ' \t\n') |
| 77 | + else |
| 78 | + version="${SCALINGO_CLI_VERSION}" |
| 79 | + fi |
| 80 | + |
| 81 | + if [ -z "$version" ]; then |
| 82 | + echo "------> Fail to get the version of the CLI" >&2 |
| 83 | + echo "You should use the 'version' input with the desired version." >&2 |
| 84 | + exit 1 |
| 85 | + fi |
| 86 | +
|
| 87 | + echo "------> Version of the CLI to install: $version" |
| 88 | +
|
| 89 | + dirname="scalingo_${version}_${os}_${arch}" |
| 90 | + archive_name="${dirname}.${ext}" |
| 91 | + url=https://github.com/Scalingo/cli/releases/download/${version}/${archive_name} |
| 92 | +
|
| 93 | + echo "------> Downloading Scalingo client... " |
| 94 | + curl --silent --fail --location --output ${tmpdir}/${archive_name} ${url} |
| 95 | + if [ ! -f ${tmpdir}/${archive_name} ]; then |
| 96 | + echo "" >&2 |
| 97 | + echo "ERROR-> Fail to download the CLI archive" >&2 |
| 98 | + exit 1 |
| 99 | + fi |
| 100 | + echo "------> Scalingo client downloaded" |
| 101 | + echo "------> Extracting... " |
| 102 | + tar -C "${tmpdir}" -x -f "${tmpdir}/${archive_name}" |
| 103 | +
|
| 104 | + exe_path=${tmpdir}/${dirname}/scalingo |
| 105 | + if [ ! -f "$exe_path" ]; then |
| 106 | + echo "" >&2 |
| 107 | + echo "------> Fail to extract the CLI archive" >&2 |
| 108 | + exit 1 |
| 109 | + fi |
| 110 | + echo "Binary extracted" |
| 111 | +
|
| 112 | + target_dir="${{ github.action_path }}/bin" |
| 113 | + mkdir "${target_dir}" |
| 114 | +
|
| 115 | + target="${target_dir}/scalingo" |
| 116 | + |
| 117 | + mv $exe_path "$target" ; rc=$? |
| 118 | +
|
| 119 | + if [ $rc -ne 0 ] ; then |
| 120 | + echo " ! Fail to install Scalingo client (return $rc)" |
| 121 | + else |
| 122 | + echo "------> Installation completed, the command 'scalingo' is available." |
| 123 | + fi |
| 124 | +
|
| 125 | + echo ${{github.action_path}}/bin/ >> ${GITHUB_PATH} |
| 126 | + shell: bash |
| 127 | + env: |
| 128 | + GITHUB_TOKEN: ${{ inputs.github_token }} |
| 129 | + SCALINGO_CLI_VERSION: ${{ inputs.version }} |
| 130 | + - name: Configure Scalingo CLI |
| 131 | + shell: bash |
| 132 | + run: | |
| 133 | + echo "------> Configuring Scalingo CLI" |
| 134 | +
|
| 135 | + echo "LOG_FILE=/dev/stdout" >> $GITHUB_ENV |
| 136 | +
|
| 137 | + # Disable the update checker |
| 138 | + echo "DISABLE_UPDATE_CHECKER=true" >> $GITHUB_ENV |
| 139 | + export DISABLE_UPDATE_CHECKER=true |
| 140 | + echo "DISABLE_INTERACTIVE=true" >> $GITHUB_ENV |
| 141 | + export DISABLE_INTERACTIVE=true |
| 142 | +
|
| 143 | + # Configure development urls for debugging purposes |
| 144 | + [[ -n "${UNSECURE_SSL}" ]] && echo "UNSECURE_SSL=${UNSECURE_SSL}" >> $GITHUB_ENV |
| 145 | + [[ -n "${SCALINGO_API_URL}" ]] && echo "SCALINGO_API_URL=${SCALINGO_API_URL}" >> $GITHUB_ENV |
| 146 | + [[ -n "${SCALINGO_AUTH_URL}" ]] && echo "SCALINGO_AUTH_URL=${SCALINGO_AUTH_URL}" >> $GITHUB_ENV |
| 147 | + [[ -n "${SCALINGO_DB_URL}" ]] && echo "SCALINGO_DB_URL=${SCALINGO_DB_URL}" >> $GITHUB_ENV |
| 148 | + [[ -n "${SCALINGO_SSH_HOST}" ]] && echo "SCALINGO_SSH_HOST=${SCALINGO_SSH_HOST}" >> $GITHUB_ENV |
| 149 | +
|
| 150 | + echo "------> Set the region to ${SCALINGO_REGION}" |
| 151 | + echo "SCALINGO_REGION=${SCALINGO_REGION}" >> $GITHUB_ENV |
| 152 | +
|
| 153 | + if [[ -n "${SCALINGO_API_TOKEN}" ]]; then |
| 154 | + echo "------> Log in to Scalingo with API token" |
| 155 | + scalingo login --api-token ${SCALINGO_API_TOKEN} >&1 2>&1 |
| 156 | + scalingo config --region ${SCALINGO_REGION} >&1 2>&1 |
| 157 | + fi |
| 158 | +
|
| 159 | + if [[ -n "${SCALINGO_APP}" ]]; then |
| 160 | + echo "------> Set the default app to ${SCALINGO_APP}" |
| 161 | + echo "SCALINGO_APP=${SCALINGO_APP}" >> $GITHUB_ENV |
| 162 | + fi |
| 163 | + env: |
| 164 | + SCALINGO_API_TOKEN: ${{ inputs.api_token }} |
| 165 | + SCALINGO_REGION: ${{ inputs.region }} |
| 166 | + SCALINGO_APP: ${{ inputs.app_name }} |
| 167 | + SCALINGO_API_URL: ${{ inputs.scalingo_api_url }} |
| 168 | + SCALINGO_AUTH_URL: ${{ inputs.scalingo_auth_url }} |
| 169 | + SCALINGO_DB_URL: ${{ inputs.scalingo_db_url }} |
| 170 | + SCALINGO_SSH_HOST: ${{ inputs.scalingo_ssh_host }} |
| 171 | + UNSECURE_SSL: ${{ inputs.unsecure_ssl }} |
| 172 | + |
| 173 | + - name: Configure Scalingo Git remote |
| 174 | + shell: bash |
| 175 | + run: | |
| 176 | + echo "------> Configure Scalingo Git remote" |
| 177 | +
|
| 178 | + if [ -z $SCALINGO_APP ]; then |
| 179 | + echo "------> No region. The git remote cannot be configured without a region." |
| 180 | + exit 0 |
| 181 | + fi |
| 182 | +
|
| 183 | + if [ -z $SCALINGO_REGION }}" ]; then |
| 184 | + echo "WARNING: No app name. The git remote cannot be configured without an app name." |
| 185 | + exit 0 |
| 186 | + fi |
| 187 | +
|
| 188 | + # Configure the git remote only if .git directory exists |
| 189 | + if [ ! -d .git ]; then |
| 190 | + echo "------> No .git directory found, skipping git remote configuration" |
| 191 | + fi |
| 192 | +
|
| 193 | + scalingo git-setup --remote ${{ inputs.git_remote }} |
| 194 | + echo "------> Git remote \"${{ inputs.git_remote }}\" configured" |
| 195 | +
|
| 196 | +
|
0 commit comments