From 9a7c3e0d212f6a26cbe9769d5f379de05b757d84 Mon Sep 17 00:00:00 2001 From: jo Date: Sat, 11 Sep 2021 04:45:07 +0200 Subject: [PATCH] Replace build.sh with make to manage airtime_mvc --- .github/workflows/test.yml | 12 +++--------- Makefile | 3 +++ airtime_mvc/Makefile | 12 ++++++++++++ build.sh | 32 -------------------------------- install | 5 +++-- tools/version.sh | 24 ++++++++++++++++++++++++ 6 files changed, 45 insertions(+), 43 deletions(-) create mode 100644 airtime_mvc/Makefile delete mode 100755 build.sh create mode 100755 tools/version.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 623d79f5b..a3f98baf0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -84,18 +84,12 @@ jobs: restore-keys: | ${{ runner.os }}-composer- - - name: Install dependencies - run: | - composer install --no-progress --dev - working-directory: airtime_mvc - - - name: Run PHP tests + - name: Run tests run: | sudo mkdir -p "$LIBRETIME_LOG_DIR" sudo chown runner:runner "$LIBRETIME_LOG_DIR" - - php ../vendor/bin/phpunit - working-directory: airtime_mvc/tests + make test + working-directory: airtime_mvc test: runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index c2e69bef5..cd01c8fc3 100644 --- a/Makefile +++ b/Makefile @@ -14,3 +14,6 @@ shell-format: shell-check: shfmt -f . | xargs shfmt -i 2 -ci -sr -kp -d shfmt -f . | xargs shellcheck --color=always --severity=$${SEVERITY:-style} + +VERSION: + tools/version.sh diff --git a/airtime_mvc/Makefile b/airtime_mvc/Makefile new file mode 100644 index 000000000..664e1d9d5 --- /dev/null +++ b/airtime_mvc/Makefile @@ -0,0 +1,12 @@ +.PHONY: build + +SHELL = bash + +vendor: + composer install --no-progress --no-interaction + +test: vendor + cd tests && ../vendor/bin/phpunit + +build: + composer install --no-progress --no-interaction --no-dev diff --git a/build.sh b/build.sh deleted file mode 100755 index 718d8d1eb..000000000 --- a/build.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -set -e # Exit if any of the steps fails. - -pushd airtime_mvc || (echo "could not cd in airtime_mvc!" && exit 1) -composer install --no-dev --no-interaction -popd || exit - -git_build="" -if [ -d .git ]; then - echo " * Building from Git" - git_build="y" -fi - -if [ "${git_build}" = "y" ]; then - git_version=$(git tag --points-at HEAD) - echo " * Version from tag: ${git_version}" - if [ "${git_version}" = "" ]; then - git_version=$(git rev-parse --short HEAD) - echo " * Overriding empty version with sha1 commit-ish: ${git_version}" - fi - echo "${git_version}" > VERSION -else - # if no file was in tarball we create one letting the user know - # if you run in to this you should grab an enriched tarball built - # by travis. It already contains the VERSION file and also bundles - # all the PHP you vendors files making the install much faster on - # your part. - if [ ! -f VERSION ]; then - echo "could not detect version for VERSION file" > VERSION - fi -fi diff --git a/install b/install index dada559c9..9e60dce93 100755 --- a/install +++ b/install @@ -797,8 +797,9 @@ if [[ ! ${commandFound} -eq 0 ]]; then PATH="${PATH}:/usr/local/bin" fi -# Run composer (install PHP dependencies) and create a VERSION file -loudCmd "bash ./build.sh" +make VERSION # Create a VERSION file +make -C airtime_mvc build # Install php dependencies with composer + if [ -f /etc/airtime/airtime.conf ]; then # TODO use VERSION or some other way to check for updates and handle # media-monitor case on it's own diff --git a/tools/version.sh b/tools/version.sh new file mode 100755 index 000000000..e559af385 --- /dev/null +++ b/tools/version.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +set -u + +error() { + echo >&2 "error: $*" + exit 1 +} + +command -v git > /dev/null || error "git command not found!" +command -v tee > /dev/null || error "tee command not found!" + +typeset -r version_file="VERSION" + +if [[ "$(git rev-parse --is-inside-work-tree 2> /dev/null)" == "true" ]]; then + tag=$(git tag --points-at HEAD | tee "$version_file" || error "could not extract tag") + if [[ -z "$tag" ]]; then + git rev-parse --short HEAD > "$version_file" || error "could not extract commit sha" + fi +else + if [[ ! -f "$version_file" ]]; then + echo "could not detect version" > VERSION + fi +fi