Skip to content

Commit

Permalink
Add basic tests to the Github Actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanmaric committed Mar 17, 2021
1 parent 378228f commit 2f7b605
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 3 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,41 @@ jobs:

- name: Lint with shellcheck
run: make lint

test:
name: Test
runs-on: ubuntu-latest
defaults:
run:
shell: bash -i {0}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Mock cURL and wget
run: |
echo "REAL_CURL=$(which curl)" >> $GITHUB_ENV
echo "REAL_WGET=$(which wget)" >> $GITHUB_ENV
echo "$(pwd)/mocks/" >> $GITHUB_PATH
- name: Install g using g-install with default options
run: curl -sSL https://git.io/g-install | sh -s -- -y bash

- name: Verify environment variables
run: test ! -z "${GOROOT?}" && test ! -z "${GOPATH?}"

- name: Verify g installation
run: g --version

- name: Verify go installation
run: go version

- name: Make sure it is the go binary installed by g
run: test "$(which go)" = "$GOPATH/bin/go"

- name: Make sure g can switch versions
run: g install 1.14.15 && go version | grep -1 "go1.14.15"

- name: Make sure g can self-upgrade
run: SHELL="$(which bash)" g self-upgrade
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Upgrade shfmt from v3.0.0 to v3.2.4, no format changes introduced
- Introduce a Github Actions workflow file with lint only for now
- Fix g breaking on missing $TERM var in non-interactive systems
- Add basic tests to the Github Actions workflow

## 0.8.0 - 2019-12-24

Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ prepare: .tmp/shellcheck .tmp/shfmt

.PHONY: lint
lint: prepare
@./.tmp/shellcheck bin/*
@./.tmp/shfmt -d bin/*
@./.tmp/shellcheck bin/* mocks/*
@./.tmp/shfmt -d bin/* mocks/*

.PHONY: format
format: prepare
@./.tmp/shfmt -w bin/*
@./.tmp/shfmt -w bin/* mocks/*

.tmp/shellcheck:
@echo "Downloading shellcheck"
Expand Down
26 changes: 26 additions & 0 deletions mocks/curl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

# POSIX shell doesn't support errtrace nor pipefail.

# Exit on error. Append "|| true" if you expect an error.
set -o errexit
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR.
set -o nounset

BASE_DIR="$(dirname -- "$0")"
G_URL="https://git.io/g-bin"
G_LOCATION="$BASE_DIR/../bin/g"
INSTALL_URL="https://git.io/g-install"
INSTALL_LOCATION="$BASE_DIR/../bin/install"

for item in "$@"; do
if [ "$item" = "$G_URL" ]; then
cat "$G_LOCATION"
return
elif [ "$item" = "$INSTALL_URL" ]; then
cat "$INSTALL_LOCATION"
return
fi
done

command "${REAL_CURL:?}" "$@"
26 changes: 26 additions & 0 deletions mocks/wget
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

# POSIX shell doesn't support errtrace nor pipefail.

# Exit on error. Append "|| true" if you expect an error.
set -o errexit
# Do not allow use of undefined vars. Use ${VAR:-} to use an undefined VAR.
set -o nounset

BASE_DIR="$(dirname -- "$0")"
G_URL="https://git.io/g-bin"
G_LOCATION="$BASE_DIR/../bin/g"
INSTALL_URL="https://git.io/g-install"
INSTALL_LOCATION="$BASE_DIR/../bin/install"

for item in "$@"; do
if [ "$item" = "$G_URL" ]; then
cat "$G_LOCATION"
return
elif [ "$item" = "$INSTALL_URL" ]; then
cat "$INSTALL_LOCATION"
return
fi
done

command "${REAL_WGET:?}" "$@"

0 comments on commit 2f7b605

Please sign in to comment.