From 11ea6379cde9e0ba9654547fad15fb2388a86b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20M=C3=A9ausoone?= Date: Wed, 6 Nov 2019 16:42:22 +0100 Subject: [PATCH] test(slug): test 'slug_ref' function --- .github/actions/bats/Dockerfile | 5 +++++ .github/actions/bats/entrypoint.sh | 3 +++ .github/workflows/ci.yml | 17 +++++++++++++++++ Makefile | 9 +++++++++ README.md | 2 +- entrypoint-test.bats | 27 +++++++++++++++++++++++++++ 6 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .github/actions/bats/Dockerfile create mode 100755 .github/actions/bats/entrypoint.sh create mode 100644 .github/workflows/ci.yml create mode 100644 Makefile create mode 100644 entrypoint-test.bats diff --git a/.github/actions/bats/Dockerfile b/.github/actions/bats/Dockerfile new file mode 100644 index 0000000..e8aaa15 --- /dev/null +++ b/.github/actions/bats/Dockerfile @@ -0,0 +1,5 @@ +FROM dduportal/bats:latest + +COPY entrypoint.sh /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/.github/actions/bats/entrypoint.sh b/.github/actions/bats/entrypoint.sh new file mode 100755 index 0000000..b973343 --- /dev/null +++ b/.github/actions/bats/entrypoint.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +/sbin/bats ./ \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..28ef6e0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,17 @@ +name: ci + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + + - name: Check out code + uses: actions/checkout@v1 + + - name: Tests + uses: ./.github/actions/bats + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9626247 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ + + + +help: ## print this message + @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-10s\033[0m %s\n", $$1, $$2}' + +.PHONY: tests +tests: ## Run tests locally + docker run -w /workdir -v $(shell pwd):/workdir dduportal/bats:latest ./ \ No newline at end of file diff --git a/README.md b/README.md index 6cecbd4..7aa0911 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,4 @@ This action slug and expose some github variables. echo ${{ env.GITHUB_REF_SLUG }} echo ${{ env.GITHUB_HEAD_REF_SLUG }} echo ${{ env.GITHUB_BASE_REF_SLUG }} -``` +``` \ No newline at end of file diff --git a/entrypoint-test.bats b/entrypoint-test.bats new file mode 100644 index 0000000..09adc30 --- /dev/null +++ b/entrypoint-test.bats @@ -0,0 +1,27 @@ +#!/usr/bin/env bats + +@test "slug_ref" { + source entrypoint.sh + + i=0 + j=0 + + given[++i]="refs/head/master" + expected[++j]="master" + + given[++i]="refs/head/feat/newFeature" + expected[++j]="newfeature" + + given[++i]="refs/tags/v1.0" + expected[++j]="v1-0" + + given[++i]="refs/head/awesome-Feature-Very-Very-Very-Very-Very-Very-Very-Long-moreThan63Characters" + expected[++j]="awesome-feature-very-very-very-very-very-very-very-long-moretha" + + for i in "${!given[@]}" + do + actual="$(slug_ref \"${given[i]}\")" + echo "expected : [${expected[i]}], actual : [${actual}]" + [ "$actual" == "${expected[i]}" ] + done +}