From 4687769626621ff783eaf5e7e1f0b4be04cacb06 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Mon, 13 Jan 2025 15:37:59 +0700 Subject: [PATCH 1/4] ci: add simple build test workflow as well as a dependabot config to update used actions in workflows. When building from a fork, tags may not exist. Try to obtain latest tag from upstream via GitHub API in this case. Exit early if this fails as well, as DEB packages strictly require their version to start with an integer. For debugging reasons, error output is unmuted. Signed-off-by: MichaIng --- .github/dependabot.yml | 9 +++++++++ .github/workflows/build-test.yml | 19 +++++++++++++++++++ build.sh | 21 +++++++++++++++------ 3 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/build-test.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..fee43d35 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,9 @@ +version: 2 +updates: +- package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + target-branch: "master" + labels: + - "enhancement" diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml new file mode 100644 index 00000000..b1365543 --- /dev/null +++ b/.github/workflows/build-test.yml @@ -0,0 +1,19 @@ +name: Build test +on: [pull_request, push, workflow_dispatch] +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +permissions: + contents: read +jobs: + build: + strategy: + matrix: + arch: [armhf, arm64, amd64, riscv64] + fail-fast: false + name: Build on ${{ matrix.arch }} + if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.owner.login != github.event.pull_request.base.repo.owner.login + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + - run: make ${{ matrix.arch }} diff --git a/build.sh b/build.sh index 4511c94e..80241c82 100755 --- a/build.sh +++ b/build.sh @@ -51,8 +51,9 @@ packages() { cd librespot - LIBRESPOT_VER="$(git describe --tags "$(git rev-list --tags --max-count=1)" 2>/dev/null || echo unknown)" - LIBRESPOT_HASH="$(git rev-parse HEAD | cut -c 1-7 2>/dev/null || echo unknown)" + echo 'Obtaining latest Librespot Git repository tag for DEB package version suffix ...' + LIBRESPOT_VER="$(git describe --tags "$(git rev-list --tags --max-count=1)" || echo unknown)" + LIBRESPOT_HASH="$(git rev-parse HEAD | cut -c 1-7 || echo unknown)" echo "Build Librespot binary..." cargo build --jobs "$(nproc)" --profile release --target "$BUILD_TARGET" --no-default-features --features "alsa-backend pulseaudio-backend with-avahi" @@ -156,9 +157,17 @@ START_BUILDS=$(now) cd /mnt/raspotify -# Get the git rev of raspotify for .deb versioning -RASPOTIFY_GIT_VER="$(git describe --tags "$(git rev-list --tags --max-count=1)" 2>/dev/null || echo unknown)" -RASPOTIFY_HASH="$(git rev-parse HEAD | cut -c 1-7 2>/dev/null || echo unknown)" +echo 'Obtaining latest Git repository tag for DEB package version ...' +RASPOTIFY_GIT_VER="$(git describe --tags "$(git rev-list --tags --max-count=1)" || :)" +if [ -z "$RASPOTIFY_GIT_VER" ]; then + echo 'Could not obtain latest tag from local repository. Obtaining it from upstream: https://api.github.com/repos/dtcooper/raspotify/tags' + RASPOTIFY_GIT_VER="$(curl -sSf "https://api.github.com/repos/dtcooper/raspotify/tags" | awk -F\" '/^ *"name": "/{print $4;exit}' || :)" +fi +if [ -z "$RASPOTIFY_GIT_VER" ]; then + echo 'Could not obtain latest tag from upstream repository either. Exiting ...' + exit 1 +fi +RASPOTIFY_HASH="$(git rev-parse HEAD | cut -c 1-7 || echo unknown)" echo "Build Raspotify $RASPOTIFY_GIT_VER~$RASPOTIFY_HASH..." @@ -181,7 +190,7 @@ case $ARCHITECTURE in esac # Fix broken permissions resulting from running the Docker container as root. -[ $(id -u) -eq 0 ] && chown -R "$PERMFIX_UID:$PERMFIX_GID" /mnt/raspotify 2>/dev/null +[ $(id -u) -eq 0 ] && chown -R "$PERMFIX_UID:$PERMFIX_GID" /mnt/raspotify BUILD_TIME=$(duration_since "$START_BUILDS") From a93457855a6c83ebf8241ff61c35c2a492b62f70 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Fri, 17 Jan 2025 00:19:55 +0700 Subject: [PATCH 2/4] build: do not query GitHub API if origin is upstream If the "origin" remote of the local repository is the upstream repo dtcooper/raspotify, do not query the GitHub API for upstream tags. It is supposed to have tags then, else the local repo is faulty. Signed-off-by: MichaIng --- build.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/build.sh b/build.sh index 80241c82..16b8a5f0 100755 --- a/build.sh +++ b/build.sh @@ -160,12 +160,20 @@ cd /mnt/raspotify echo 'Obtaining latest Git repository tag for DEB package version ...' RASPOTIFY_GIT_VER="$(git describe --tags "$(git rev-list --tags --max-count=1)" || :)" if [ -z "$RASPOTIFY_GIT_VER" ]; then - echo 'Could not obtain latest tag from local repository. Obtaining it from upstream: https://api.github.com/repos/dtcooper/raspotify/tags' - RASPOTIFY_GIT_VER="$(curl -sSf "https://api.github.com/repos/dtcooper/raspotify/tags" | awk -F\" '/^ *"name": "/{print $4;exit}' || :)" -fi -if [ -z "$RASPOTIFY_GIT_VER" ]; then - echo 'Could not obtain latest tag from upstream repository either. Exiting ...' - exit 1 + # Derive from origin URL whether this is dtcooper/raspotify and hence supposed to have tags. + # If so, exit right here, else get tags from dtcooper/raspotify via GitHub API, since forks often do not have any tags. + url="$(git remote get-url origin || :)" + if [ "$url" = 'https://github.com/dtcooper/raspotify' ] || [ "$url" = 'https://github.com/dtcooper/raspotify/' ] || [ "$url" = 'https://github.com/dtcooper/raspotify.git' ]; then + echo 'E: Could not obtain any tag. Exiting ...' + exit 1 + else + echo 'W: Could not obtain latest tag from local repository. Obtaining it from upstream: https://api.github.com/repos/dtcooper/raspotify/tags' + RASPOTIFY_GIT_VER="$(curl -sSf "https://api.github.com/repos/dtcooper/raspotify/tags" | awk -F\" '/^ *"name": "/{print $4;exit}' || :)" + if [ -z "$RASPOTIFY_GIT_VER" ]; then + echo 'E: Could not obtain latest tag from upstream repository either. Exiting ...' + exit 1 + fi + fi fi RASPOTIFY_HASH="$(git rev-parse HEAD | cut -c 1-7 || echo unknown)" From 115fed0a985ed27c777278d604ef4b3832cf6758 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Sun, 19 Jan 2025 12:23:41 +0100 Subject: [PATCH 3/4] Revert "build: do not query GitHub API if origin is upstream" This reverts commit a93457855a6c83ebf8241ff61c35c2a492b62f70. --- build.sh | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/build.sh b/build.sh index 16b8a5f0..80241c82 100755 --- a/build.sh +++ b/build.sh @@ -160,20 +160,12 @@ cd /mnt/raspotify echo 'Obtaining latest Git repository tag for DEB package version ...' RASPOTIFY_GIT_VER="$(git describe --tags "$(git rev-list --tags --max-count=1)" || :)" if [ -z "$RASPOTIFY_GIT_VER" ]; then - # Derive from origin URL whether this is dtcooper/raspotify and hence supposed to have tags. - # If so, exit right here, else get tags from dtcooper/raspotify via GitHub API, since forks often do not have any tags. - url="$(git remote get-url origin || :)" - if [ "$url" = 'https://github.com/dtcooper/raspotify' ] || [ "$url" = 'https://github.com/dtcooper/raspotify/' ] || [ "$url" = 'https://github.com/dtcooper/raspotify.git' ]; then - echo 'E: Could not obtain any tag. Exiting ...' - exit 1 - else - echo 'W: Could not obtain latest tag from local repository. Obtaining it from upstream: https://api.github.com/repos/dtcooper/raspotify/tags' - RASPOTIFY_GIT_VER="$(curl -sSf "https://api.github.com/repos/dtcooper/raspotify/tags" | awk -F\" '/^ *"name": "/{print $4;exit}' || :)" - if [ -z "$RASPOTIFY_GIT_VER" ]; then - echo 'E: Could not obtain latest tag from upstream repository either. Exiting ...' - exit 1 - fi - fi + echo 'Could not obtain latest tag from local repository. Obtaining it from upstream: https://api.github.com/repos/dtcooper/raspotify/tags' + RASPOTIFY_GIT_VER="$(curl -sSf "https://api.github.com/repos/dtcooper/raspotify/tags" | awk -F\" '/^ *"name": "/{print $4;exit}' || :)" +fi +if [ -z "$RASPOTIFY_GIT_VER" ]; then + echo 'Could not obtain latest tag from upstream repository either. Exiting ...' + exit 1 fi RASPOTIFY_HASH="$(git rev-parse HEAD | cut -c 1-7 || echo unknown)" From ce05e397369dd2c6eed715d37d7b320474fcbab3 Mon Sep 17 00:00:00 2001 From: MichaIng Date: Sun, 19 Jan 2025 12:32:08 +0100 Subject: [PATCH 4/4] build: add warning and error indication to messages Signed-off-by: MichaIng --- build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 80241c82..d14a2f20 100755 --- a/build.sh +++ b/build.sh @@ -160,11 +160,11 @@ cd /mnt/raspotify echo 'Obtaining latest Git repository tag for DEB package version ...' RASPOTIFY_GIT_VER="$(git describe --tags "$(git rev-list --tags --max-count=1)" || :)" if [ -z "$RASPOTIFY_GIT_VER" ]; then - echo 'Could not obtain latest tag from local repository. Obtaining it from upstream: https://api.github.com/repos/dtcooper/raspotify/tags' + echo 'W: Could not obtain latest tag from local repository. Obtaining it from upstream: https://api.github.com/repos/dtcooper/raspotify/tags' RASPOTIFY_GIT_VER="$(curl -sSf "https://api.github.com/repos/dtcooper/raspotify/tags" | awk -F\" '/^ *"name": "/{print $4;exit}' || :)" fi if [ -z "$RASPOTIFY_GIT_VER" ]; then - echo 'Could not obtain latest tag from upstream repository either. Exiting ...' + echo 'E: Could not obtain latest tag from upstream repository either. Exiting ...' exit 1 fi RASPOTIFY_HASH="$(git rev-parse HEAD | cut -c 1-7 || echo unknown)"