Skip to content

Commit

Permalink
Merge pull request cunymatthieu#12 from tgenv/github-actions
Browse files Browse the repository at this point in the history
Get test running and passing as github actions on pull requests
  • Loading branch information
Fabianoshz authored Jan 16, 2023
2 parents 148c78c + a0d04b9 commit 9eb3d45
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 63 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'Test'

on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
workflow_dispatch:

jobs:

# Only checking latest Linux/UNIX on pulls to save execution times
test-main-pulls:
if: github.event_name == 'pull_request'
runs-on: "${{ matrix.os }}"
strategy:
matrix:
os:
- 'macos-latest'
- 'ubuntu-latest'
steps:
- uses: 'actions/checkout@v2'
with:
fetch-depth: 1
- name: 'Install Dependencies'
run: './test/install_deps.sh'
- name: 'Run all tests'
run: './test/run.sh'
shell: 'bash'

# When we push to main, test everything in order to guarantee releases
test-main-pushes:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: "${{ matrix.os }}"
strategy:
matrix:
os:
- 'macos-11'
- 'macos-10.15'
- 'ubuntu-20.04'
- 'ubuntu-18.04'
- 'windows-2019'
steps:
- uses: 'actions/checkout@v2'
with:
fetch-depth: 1

- name: 'Install Dependencies'
run: './test/install_deps.sh'

- name: 'Run all tests'
run: './test/run.sh'
shell: 'bash'
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
## Mac things
.DS_Store
.DS_Store

version
versions/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# TGENV - Terragrunt Version Manager

![Tests](https://github.com/tgenv/tgenv/actions/workflows/test.yaml/badge.svg?branch=main)

![tgenvlogo](/assets/tgenv-logo.png)

This project was forked from old project [tgenv](https://github.com/cunymatthieu/tgenv). The intention here it's keep the project alive.
This project was forked from old project [cunymatthieu/tgenv](https://github.com/cunymatthieu/tgenv). The intention here it's keep the project alive.

[Terragrunt](https://github.com/gruntwork-io/terragrunt) version manager inspired by [tfenv](https://github.com/kamatama41/tfenv)

Expand Down
5 changes: 5 additions & 0 deletions libexec/helpers
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#!/usr/bin/env bash

function error_and_proceed() {
errors+=("${1}")
echo -e "tgenv: ${0}: Test Failed: ${1}" >&2
}

function error_and_die() {
echo -e "tgenv: $(basename ${0}): \033[0;31m[ERROR] ${1}\033[0;39m" >&2
exit 1
Expand Down
6 changes: 6 additions & 0 deletions test/install_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -uo pipefail;

if [[ $(uname) == 'Darwin' ]] && [ $(which brew) ]; then
brew install grep;
fi;
3 changes: 2 additions & 1 deletion test/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ if [ -n "${TGENV_DEBUG}" ]; then
export PS4='+ [${BASH_SOURCE##*/}:${LINENO}] '
set -x
fi
TGENV_ROOT=$(cd $(dirname ${0})/.. && pwd)

export TGENV_ROOT=$(cd $(dirname ${0})/.. && pwd)
export PATH="${TGENV_ROOT}/bin:${PATH}"

errors=()
Expand Down
48 changes: 31 additions & 17 deletions test/test_install_and_use.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

declare -a errors

function error_and_proceed() {
errors+=("${1}")
echo -e "tgenv: ${0}: Test Failed: ${1}" >&2
}

function error_and_die() {
echo -e "tgenv: ${0}: ${1}" >&2
exit 1
}
source "${TGENV_ROOT}/libexec/helpers"

[ -n "$TGENV_DEBUG" ] && set -x
source $(dirname $0)/helpers.sh \
|| error_and_die "Failed to load test helpers: $(dirname $0)/helpers.sh"

##################################################
# Test install latest version
##################################################
echo "### Install latest version"
cleanup || error_and_die "Cleanup failed?!"

Expand All @@ -26,54 +21,73 @@ v=$(tgenv list-remote | head -n 1)
check_version ${v} || exit 1
) || error_and_proceed "Installing latest version ${v}"

##################################################
# Test install latest:<regex>
##################################################
echo "### Install latest version with Regex"
cleanup || error_and_die "Cleanup failed?!"

v=$(tgenv list-remote | grep 0.11.1 | head -n 1)
v=$(tgenv list-remote | grep 0.37.4 | head -n 1)
(
tgenv install latest:^0.11 || exit 1
tgenv use latest:^0.11 || exit 1
tgenv install latest:^0.37 || exit 1
tgenv use latest:^0.37 || exit 1
check_version ${v} || exit 1
) || error_and_proceed "Installing latest version ${v} with Regex"

##################################################
# Test install specific version
##################################################
echo "### Install specific version"
cleanup || error_and_die "Cleanup failed?!"

v=0.9.9
v=0.36.3
(
tgenv install ${v} || exit 1
tgenv use ${v} || exit 1
check_version ${v} || exit 1
) || error_and_proceed "Installing specific version ${v}"

##################################################
# Test specific version from .terragrunt-version
##################################################
echo "### Install specific .terragrunt-version"
cleanup || error_and_die "Cleanup failed?!"

v=0.12.3
v=0.36.1
echo ${v} > ./.terragrunt-version
(
tgenv install || exit 1
check_version ${v} || exit 1
) || error_and_proceed "Installing .terragrunt-version ${v}"


##################################################
# Install invalid specific version .terragrunt-version
##################################################
echo "### Install latest:<regex> .terragrunt-version"
cleanup || error_and_die "Cleanup failed?!"

v=$(tgenv list-remote | grep -e '^0.9' | head -n 1)
echo "latest:^0.9" > ./.terragrunt-version
v=$(tgenv list-remote | grep -e '^0.38' | head -n 1)
echo "latest:^0.38" > ./.terragrunt-version
(
tgenv install || exit 1
check_version ${v} || exit 1
) || error_and_proceed "Installing .terragrunt-version ${v}"

echo "### Install invalid specific version"
##################################################
# Install invalid specific version .terragrunt-version
##################################################
echo "### Install invalid specific version .terragrunt-version"
cleanup || error_and_die "Cleanup failed?!"

v=9.9.9
expected_error_message="No versions matching '${v}' found in remote"
[ -z "$(tgenv install ${v} 2>&1 | grep "${expected_error_message}")" ] \
&& error_and_proceed "Installing invalid version ${v}"

##################################################
# Install invalid latest:<regex> version
##################################################
echo "### Install invalid latest:<regex> version"
cleanup || error_and_die "Cleanup failed?!"

Expand Down
36 changes: 19 additions & 17 deletions test/test_list.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
#!/usr/bin/env bash

set -uo pipefail;
declare -a errors

function error_and_proceed() {
errors+=("${1}")
echo -e "tgenv: ${0}: Test Failed: ${1}" >&2
}
source "${TGENV_ROOT}/libexec/helpers"

function error_and_die() {
echo -e "tgenv: ${0}: ${1}" >&2
exit 1
}

[ -n "${TGENV_DEBUG}" ] && set -x
[ "${TGENV_DEBUG:-0}" -gt 0 ] && set -x
source $(dirname $0)/helpers.sh \
|| error_and_die "Failed to load test helpers: $(dirname $0)/helpers.sh"

echo "### List local versions"
cleanup || error_and_die "Cleanup failed?!"

for v in 0.12.15 0.12.9 0.11.1 0.10.0 0.9.3; do
versions=(
0.38.12
0.37.4
0.36.11
0.33.0
0.29.7
)
for v in "${versions[@]}"; do
tgenv install ${v} || error_and_proceed "Install of version ${v} failed"
done
tgenv use 0.38.12

result=$(tgenv list)
result="$(tgenv list)";
expected="$(cat << EOS
0.12.15
0.12.9
0.11.1
0.10.0
0.9.3
* 0.38.12 (set by $(tgenv version-file))
0.37.4
0.36.11
0.33.0
0.29.7
EOS
)"

# Note macos appears to have problems with variable expansion here
if [ "${expected}" != "${result}" ]; then
error_and_proceed "List mismatch.\nExpected:\n${expected}\nGot:\n${result}"
fi
Expand Down
18 changes: 6 additions & 12 deletions test/test_symlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@

declare -a errors

function error_and_proceed() {
errors+=("${1}")
echo -e "tgenv: Test Failed: ${1}" >&2
}

function error_and_die() {
echo -e "tgenv: ${1}" >&2
exit 1
}
source "${TGENV_ROOT}/libexec/helpers"

[ -n "${TGENV_DEBUG}" ] && set -x
source $(dirname $0)/helpers.sh \
Expand All @@ -23,9 +15,11 @@ export PATH="${TGENV_BIN_DIR}:${PATH}"

echo "### Test supporting symlink"
cleanup || error_and_die "Cleanup failed?!"
tgenv install 0.12.15 || error_and_proceed "Install failed"
tgenv use 0.12.15 || error_and_proceed "Use failed"
check_version 0.12.15 || error_and_proceed "Version check failed"

v=0.35.17
tgenv install ${v} || error_and_proceed "Install failed"
tgenv use ${v} || error_and_proceed "Use failed"
check_version ${v} || error_and_proceed "Version check failed"

if [ ${#errors[@]} -gt 0 ]; then
echo -e "\033[0;31m===== The following symlink tests failed =====\033[0;39m" >&2
Expand Down
20 changes: 6 additions & 14 deletions test/test_uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@

declare -a errors

function error_and_proceed() {
errors+=("${1}")
echo -e "tgenv: ${0}: Test Failed: ${1}" >&2
}

function error_and_die() {
echo -e "tgenv: ${0}: ${1}" >&2
exit 1
}
source "${TGENV_ROOT}/libexec/helpers"

[ -n "${TGENV_DEBUG}" ] && set -x
source $(dirname $0)/helpers.sh \
Expand All @@ -19,11 +11,11 @@ source $(dirname $0)/helpers.sh \
echo "### Uninstall local versions"
cleanup || error_and_die "Cleanup failed?!"

v=0.9.9
v=0.35.2
(
tgenv install ${v} || exit 1
tgenv uninstall ${v} || exit 1
tgenv list | grep 0.9.9 && exit 1 || exit 0
tgenv list | grep 0.35.2 && exit 1 || exit 0
) || error_and_proceed "Uninstall of version ${v} failed"

echo "### Uninstall latest version"
Expand All @@ -39,10 +31,10 @@ v=$(tgenv list-remote | head -n 1)
echo "### Uninstall latest version with Regex"
cleanup || error_and_die "Cleanup failed?!"

v=$(tgenv list-remote | grep 0.12.15 | head -n 1)
v=$(tgenv list-remote | grep 0.33.2 | head -n 1)
(
tgenv install latest:^0.12 || exit 1
tgenv uninstall latest:^0.12 || exit 1
tgenv install latest:^0.33 || exit 1
tgenv uninstall latest:^0.33 || exit 1
tgenv list | grep ${v} && exit 1 || exit 0
) || error_and_proceed "Uninstalling latest version ${v} with Regex"

Expand Down

0 comments on commit 9eb3d45

Please sign in to comment.