Skip to content

Commit 0677976

Browse files
authored
feat(setup-scalingo): add setup-scalingo action (#1)
1 parent 91f332f commit 0677976

File tree

5 files changed

+393
-0
lines changed

5 files changed

+393
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Unix-style newlines with a newline ending every file
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
insert_final_newline = true
9+
10+
[*.{yaml,yml}]
11+
indent_style = space
12+
indent_size = 2

.github/workflows/test-setup.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Tests suite for "setup-scalingo"
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
11+
# Test that the action installs the CLI
12+
# and that the scalingo CLI returns its version number
13+
test-latest-version:
14+
strategy:
15+
matrix:
16+
os: [ubuntu-20.04, ubuntu-22.04, ubuntu-latest, macos-11, macos-12, macos-latest]
17+
runs-on: ${{ matrix.os }}
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
- name: Setup scalingo CLI
23+
uses: ./setup-scalingo
24+
with:
25+
region: 'osc-fr1'
26+
- name: Check version
27+
run: |
28+
# given
29+
latest_version=$(curl -sL https://cli-dl.scalingo.com/version)
30+
# when
31+
installed_version=$(scalingo --version)
32+
# then
33+
echo $latest_version
34+
echo $installed_version
35+
echo "${installed_version}" | grep -q "${latest_version}"
36+
37+
# Test that the action installs a specific version of the CLI
38+
# and that the scalingo CLI returns its version number
39+
test-specific-version:
40+
strategy:
41+
matrix:
42+
os: [ubuntu-20.04, ubuntu-22.04, ubuntu-latest, macos-11, macos-12, macos-latest]
43+
runs-on: ${{ matrix.os }}
44+
45+
steps:
46+
- name: Checkout
47+
uses: actions/checkout@v3
48+
- name: Setup scalingo CLI
49+
uses: ./setup-scalingo
50+
with:
51+
version: 1.28.1
52+
region: 'osc-fr1'
53+
- name: Check version
54+
run: |
55+
# given
56+
wanted_version=1.28.1
57+
# when
58+
installed_version=$(scalingo --version)
59+
# then
60+
echo "${installed_version}" | grep -q "${wanted_version}"
61+
62+
# Test that the installed CLI is logged when the API Token is provided
63+
test-login:
64+
if: ${{ github.repository == 'scalingo-community/scalingo-actions' }}
65+
strategy:
66+
matrix:
67+
os: [ubuntu-20.04, ubuntu-22.04, ubuntu-latest, macos-11, macos-12, macos-latest]
68+
runs-on: ${{ matrix.os }}
69+
70+
steps:
71+
- name: Checkout
72+
uses: actions/checkout@v3
73+
- name: Setup scalingo CLI
74+
uses: ./setup-scalingo
75+
with:
76+
region: 'osc-fr1'
77+
api_token: ${{ secrets.SCALINGO_API_TOKEN }}
78+
- name: Check login
79+
run: |
80+
# given
81+
expected_username="${{ secrets.SCALINGO_USERNAME }}"
82+
# when
83+
logged_user=$(scalingo whoami)
84+
# then
85+
echo "${logged_user}" | grep -q "${expected_username}"

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Github Actions for Scalingo
2+
3+
## Community-powered
4+
These actions are a community initiative of users and are in no way related to or supported by Scalingo.
5+
Your feedbacks and contributions are welcome to correct or improve them.
6+
7+
## Contributions are welcome
8+
9+
_especially for the following topics_:
10+
- rewriting the full setup-scalingo action in TS (instead of a composite "shell" Action, inspired from [hashicorp/setup-terraform](https://github.com/hashicorp/setup-terraform)), this will enable automatic caching thanks to `@actions/tool-cache`
11+
- full-compatibility with Windows runners
12+
- action to run commands in one-off containers
13+
- action to create database backup
14+
- action to create review app (with optional database copy !)

setup-scalingo/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# scalingo-community/setup-scalingo
2+
3+
The `scalingo-community/setup-scalingo` action is a composite action that sets up Scalingo CLI in your GitHub Actions workflow by:
4+
5+
- Downloading the latest or a specific version of Scalingo CLI and adding it to the PATH.
6+
- Configuring the Scalingo CLI configuration file with your region, app name and Scalingo API token.
7+
8+
After you've used the action, subsequent steps in the same job can run arbitrary Scalingo commands using the GitHub Actions `run:` syntax. This allows most Scalingo commands to work exactly like they do on your local command line
9+
10+
## Usage
11+
12+
This action can be run on `ubuntu-latest` and `macos-latest` GitHub Actions runners. Note that the `region` input is always required.
13+
14+
The default configuration installs the latest version of Scalingo CLI:
15+
```
16+
steps:
17+
- uses: scalingo-community/setup-scalingo@v1
18+
with:
19+
region: 'osc-fr1'
20+
```
21+
22+
Subsequent steps can launch command with the configured and authenticated CLI (you can create API Token [in the Scalingo dashboard](https://dashboard.scalingo.com/account/tokens)):
23+
```
24+
steps:
25+
- uses: scalingo-community/setup-scalingo@v1
26+
with:
27+
region: 'osc-fr1'
28+
api_token: '${{ secrets.scalingo_api_token }}
29+
app_name: 'my_app'
30+
31+
- run: scalingo restart # will restart all the processes of the app "my_app" in region "osc-fr1"
32+
```
33+
34+
35+
36+
## Inputs
37+
The action requires the following inputs:
38+
39+
- `region` - The region of your app.
40+
41+
The action also accepts the following optional inputs:
42+
43+
- `api_token` - The Scalingo API token to use. If not provided, the subsequent steps will try to use the `SCALINGO_API_TOKEN` environment variable.
44+
- `version` - The version of Scalingo CLI to install. If not provided, the action will install the latest version.
45+
- `app_name` - The name of the app to use. If not provided, the subsequent steps will try to use the `SCALINGO_APP` environment variable.
46+
- `git_remote` - Choose the name of Git remote to allow git operations (requires the `region` and `app_name` inputs). The default value is `scalingo`.
47+
48+
49+
For testing or debugging purpose, the following inputs can also be used:
50+
51+
- `scalingo_api_url` - The Scalingo API URL to use. If not provided, the action will use the default API URL for the given region.
52+
- `scalingo_auth_url` - The Scalingo Auth URL to use. If not provided, the action will use the default Auth URL for the given region.
53+
- `unsecure_ssl` - Disable SSL verification with APIs.
54+
- `scalingo_db_url` - The Scalingo DB URL to use. If not provided, the action will use the default DB URL for the given region.
55+
- `scalingo_ssh_host` - The Scalingo SSH Host to use. If not provided, the action will use the default SSH Host for the given region.
56+
57+
## Features
58+
59+
### Git remote auto-configuration
60+
61+
If the code you provide the `region` and `app_name` inputs, the action will automatically configure a Git remote named `scalingo` to allow git operations on your app. This is useful if you want to run `git push scalingo master` in your workflow.
62+
63+
```
64+
steps:
65+
- name: Checkout code
66+
uses: actions/checkout@v3
67+
- Configure Scalingo CLI
68+
uses: scalingo-community/setup-scalingo@v1
69+
with:
70+
region: 'osc-fr1'
71+
app_name: 'my_app'
72+
- name: Deploy to Scalingo with Git
73+
run: git push scalingo main
74+
```
75+
76+
### Custom version of Scalingo CLI
77+
78+
You can install a specific version of Scalingo CLI:
79+
```
80+
steps:
81+
- uses: scalingo-community/setup-scalingo@v1
82+
with:
83+
region: 'osc-fr1'
84+
version: 1.28.2
85+
```
86+

setup-scalingo/action.yaml

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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

Comments
 (0)