-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(setup-scalingo): add setup-scalingo action (#1)
- Loading branch information
1 parent
91f332f
commit 0677976
Showing
5 changed files
with
393 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
|
||
[*.{yaml,yml}] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
name: Tests suite for "setup-scalingo" | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
|
||
# Test that the action installs the CLI | ||
# and that the scalingo CLI returns its version number | ||
test-latest-version: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-20.04, ubuntu-22.04, ubuntu-latest, macos-11, macos-12, macos-latest] | ||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup scalingo CLI | ||
uses: ./setup-scalingo | ||
with: | ||
region: 'osc-fr1' | ||
- name: Check version | ||
run: | | ||
# given | ||
latest_version=$(curl -sL https://cli-dl.scalingo.com/version) | ||
# when | ||
installed_version=$(scalingo --version) | ||
# then | ||
echo $latest_version | ||
echo $installed_version | ||
echo "${installed_version}" | grep -q "${latest_version}" | ||
# Test that the action installs a specific version of the CLI | ||
# and that the scalingo CLI returns its version number | ||
test-specific-version: | ||
strategy: | ||
matrix: | ||
os: [ubuntu-20.04, ubuntu-22.04, ubuntu-latest, macos-11, macos-12, macos-latest] | ||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup scalingo CLI | ||
uses: ./setup-scalingo | ||
with: | ||
version: 1.28.1 | ||
region: 'osc-fr1' | ||
- name: Check version | ||
run: | | ||
# given | ||
wanted_version=1.28.1 | ||
# when | ||
installed_version=$(scalingo --version) | ||
# then | ||
echo "${installed_version}" | grep -q "${wanted_version}" | ||
# Test that the installed CLI is logged when the API Token is provided | ||
test-login: | ||
if: ${{ github.repository == 'scalingo-community/scalingo-actions' }} | ||
strategy: | ||
matrix: | ||
os: [ubuntu-20.04, ubuntu-22.04, ubuntu-latest, macos-11, macos-12, macos-latest] | ||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Setup scalingo CLI | ||
uses: ./setup-scalingo | ||
with: | ||
region: 'osc-fr1' | ||
api_token: ${{ secrets.SCALINGO_API_TOKEN }} | ||
- name: Check login | ||
run: | | ||
# given | ||
expected_username="${{ secrets.SCALINGO_USERNAME }}" | ||
# when | ||
logged_user=$(scalingo whoami) | ||
# then | ||
echo "${logged_user}" | grep -q "${expected_username}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## Github Actions for Scalingo | ||
|
||
## Community-powered | ||
These actions are a community initiative of users and are in no way related to or supported by Scalingo. | ||
Your feedbacks and contributions are welcome to correct or improve them. | ||
|
||
## Contributions are welcome | ||
|
||
_especially for the following topics_: | ||
- 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` | ||
- full-compatibility with Windows runners | ||
- action to run commands in one-off containers | ||
- action to create database backup | ||
- action to create review app (with optional database copy !) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# scalingo-community/setup-scalingo | ||
|
||
The `scalingo-community/setup-scalingo` action is a composite action that sets up Scalingo CLI in your GitHub Actions workflow by: | ||
|
||
- Downloading the latest or a specific version of Scalingo CLI and adding it to the PATH. | ||
- Configuring the Scalingo CLI configuration file with your region, app name and Scalingo API token. | ||
|
||
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 | ||
|
||
## Usage | ||
|
||
This action can be run on `ubuntu-latest` and `macos-latest` GitHub Actions runners. Note that the `region` input is always required. | ||
|
||
The default configuration installs the latest version of Scalingo CLI: | ||
``` | ||
steps: | ||
- uses: scalingo-community/setup-scalingo@v1 | ||
with: | ||
region: 'osc-fr1' | ||
``` | ||
|
||
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)): | ||
``` | ||
steps: | ||
- uses: scalingo-community/setup-scalingo@v1 | ||
with: | ||
region: 'osc-fr1' | ||
api_token: '${{ secrets.scalingo_api_token }} | ||
app_name: 'my_app' | ||
- run: scalingo restart # will restart all the processes of the app "my_app" in region "osc-fr1" | ||
``` | ||
|
||
|
||
|
||
## Inputs | ||
The action requires the following inputs: | ||
|
||
- `region` - The region of your app. | ||
|
||
The action also accepts the following optional inputs: | ||
|
||
- `api_token` - The Scalingo API token to use. If not provided, the subsequent steps will try to use the `SCALINGO_API_TOKEN` environment variable. | ||
- `version` - The version of Scalingo CLI to install. If not provided, the action will install the latest version. | ||
- `app_name` - The name of the app to use. If not provided, the subsequent steps will try to use the `SCALINGO_APP` environment variable. | ||
- `git_remote` - Choose the name of Git remote to allow git operations (requires the `region` and `app_name` inputs). The default value is `scalingo`. | ||
|
||
|
||
For testing or debugging purpose, the following inputs can also be used: | ||
|
||
- `scalingo_api_url` - The Scalingo API URL to use. If not provided, the action will use the default API URL for the given region. | ||
- `scalingo_auth_url` - The Scalingo Auth URL to use. If not provided, the action will use the default Auth URL for the given region. | ||
- `unsecure_ssl` - Disable SSL verification with APIs. | ||
- `scalingo_db_url` - The Scalingo DB URL to use. If not provided, the action will use the default DB URL for the given region. | ||
- `scalingo_ssh_host` - The Scalingo SSH Host to use. If not provided, the action will use the default SSH Host for the given region. | ||
|
||
## Features | ||
|
||
### Git remote auto-configuration | ||
|
||
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. | ||
|
||
``` | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- Configure Scalingo CLI | ||
uses: scalingo-community/setup-scalingo@v1 | ||
with: | ||
region: 'osc-fr1' | ||
app_name: 'my_app' | ||
- name: Deploy to Scalingo with Git | ||
run: git push scalingo main | ||
``` | ||
|
||
### Custom version of Scalingo CLI | ||
|
||
You can install a specific version of Scalingo CLI: | ||
``` | ||
steps: | ||
- uses: scalingo-community/setup-scalingo@v1 | ||
with: | ||
region: 'osc-fr1' | ||
version: 1.28.2 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
name: Scalingo Install CLI Action | ||
description: Install and configure the Scalingo CLI so you can deploy and manage your apps on Scalingo. | ||
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" | ||
fi | ||
scalingo git-setup --remote ${{ inputs.git_remote }} | ||
echo "------> Git remote \"${{ inputs.git_remote }}\" configured" | ||