From bdda267a999c97892983ee99788a31fe3c63feb3 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 15 Jul 2024 17:07:55 +0200 Subject: [PATCH] CI: Improve/fix tests, build & publish config --- .forgejo/workflows/release.yaml | 21 +++++++-------- .pre-commit-config.yaml | 19 ++++++++++---- build.sh | 45 +++++++++++++++++---------------- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/.forgejo/workflows/release.yaml b/.forgejo/workflows/release.yaml index f3cb674..be6dc42 100644 --- a/.forgejo/workflows/release.yaml +++ b/.forgejo/workflows/release.yaml @@ -17,26 +17,21 @@ jobs: MAINTAINER_EMAIL: ${{ vars.MAINTAINER_EMAIL }} DEBIAN_CODENAME: ${{ vars.DEBIAN_CODENAME }} run: | - echo "${{ secrets.GPG_KEY }}"|base64 -d|gpg --import + echo "${{ secrets.GPG_KEY }}" | base64 -d | gpg --import ./build.sh - mv check_esphome_devices dist/ - name: Upload Debian package files uses: actions/upload-artifact@v3 with: name: dist path: | - dist/*.buildinfo - dist/*.changes - dist/*.deb - dist/*.dsc - dist/*.tar.gz - dist/release_notes.md - dist/check_esphome_devices + dist publish-forgejo: runs-on: docker container: image: docker.io/brenard/debian-python-deb:latest + needs: + - build steps: - name: Download Debian package files uses: actions/download-artifact@v3 @@ -49,18 +44,18 @@ jobs: run: | mkdir release mv *.deb release/ - mv check_esphome_devices release/ + mv check-*/check_* release/ md5sum release/* > md5sum.txt sha512sum release/* > sha512sum.txt mv md5sum.txt sha512sum.txt release/ { echo 'release_note<> "$GITHUB_OUTPUT" - name: Publish release on Forgejo - uses: actions/forgejo-release@v1 + uses: actions/forgejo-release@v2 with: direction: upload url: https://gitea.zionetrix.net @@ -72,6 +67,8 @@ jobs: runs-on: docker container: image: docker.io/brenard/aptly-publish:latest + needs: + - build steps: - name: "Download Debian package files" uses: actions/download-artifact@v3 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9bab40d..98c95ad 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,16 +38,16 @@ repos: - --ignore-regex=.*codespell-ignore$ # - --write-changes # Uncomment to write changes exclude_types: [csv, json] - - repo: https://github.com/adrienverge/yamllint - rev: v1.32.0 - hooks: - - id: yamllint - ignore: .github/ - repo: https://github.com/pre-commit/mirrors-prettier rev: v2.7.1 hooks: - id: prettier args: ["--print-width", "100"] + - repo: https://github.com/adrienverge/yamllint + rev: v1.32.0 + hooks: + - id: yamllint + ignore: .github/ - repo: local hooks: - id: pylint @@ -61,4 +61,13 @@ repos: hooks: - id: bandit args: [--skip, "B101", --recursive] + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-executables-have-shebangs + stages: [manual] + - repo: https://github.com/shellcheck-py/shellcheck-py + rev: v0.10.0.1 + hooks: + - id: shellcheck minimum_pre_commit_version: 3.2.0 diff --git a/build.sh b/build.sh index aef7266..33b594a 100755 --- a/build.sh +++ b/build.sh @@ -1,10 +1,13 @@ #!/bin/bash QUIET_ARG="" -[ "$1" == "--quiet" ] && QUIET_ARG="--quiet" +[[ "$1" == "--quiet" ]] && QUIET_ARG="--quiet" # Enter source directory -cd $( dirname $0 ) +cd "$( dirname "$0" )" || exit + +CHECK_FILE="$( find "." -name 'check_*' ! -name '*~' -type f -executable | head -n 1 )" +PACKAGE_NAME="$( basename "$CHECK_FILE" | tr '_' '-' )" echo "Clean previous build..." rm -fr dist @@ -13,17 +16,17 @@ echo "Detect version using git describe..." VERSION="$( git describe --tags|sed 's/^[^0-9]*//' )" echo "Create building environemt..." -BDIR=dist/check-esphome-devices-$VERSION -mkdir -p $BDIR -[ -z "$QUIET_ARG" ] && RSYNC_ARG="-v" || RSYNC_ARG="" -rsync -a $RSYNC_ARG debian/ $BDIR/debian/ -cp check_esphome_devices $BDIR/ +BDIR="dist/$PACKAGE_NAME-$VERSION" +mkdir -p "$BDIR" +RSYNC_ARG="" +[[ -z "$QUIET_ARG" ]] && RSYNC_ARG="-v" +rsync -a "$RSYNC_ARG" debian/ "$BDIR/debian/" +cp "$CHECK_FILE" "$BDIR/" echo "Set VERSION=$VERSION in gitdch using sed..." -sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" $BDIR/check_esphome_devices +sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" "$BDIR/$( basename "$CHECK_FILE" )" -if [ -z "$DEBIAN_CODENAME" ] -then +if [[ -z "$DEBIAN_CODENAME" ]]; then echo "Retrieve debian codename using lsb_release..." DEBIAN_CODENAME=$( lsb_release -c -s ) else @@ -32,31 +35,29 @@ fi echo "Generate debian changelog using gitdch..." GITDCH_ARGS=('--verbose') -[ -n "$QUIET_ARG" ] && GITDCH_ARGS=('--warning') -if [ -n "$MAINTAINER_NAME" ] -then +[[ -n "$QUIET_ARG" ]] && GITDCH_ARGS=('--warning') +if [[ -n "$MAINTAINER_NAME" ]]; then echo "Use maintainer name from environment ($MAINTAINER_NAME)" GITDCH_ARGS+=("--maintainer-name" "${MAINTAINER_NAME}") fi -if [ -n "$MAINTAINER_EMAIL" ] -then +if [[ -n "$MAINTAINER_EMAIL" ]]; then echo "Use maintainer email from environment ($MAINTAINER_EMAIL)" GITDCH_ARGS+=("--maintainer-email" "$MAINTAINER_EMAIL") fi gitdch \ - --package-name check-esphome-devices \ + --package-name "$PACKAGE_NAME" \ --version "${VERSION}" \ - --code-name $DEBIAN_CODENAME \ - --output $BDIR/debian/changelog \ + --code-name "$DEBIAN_CODENAME" \ + --output "$BDIR"/debian/changelog \ --release-notes dist/release_notes.md \ "${GITDCH_ARGS[@]}" -if [ -n "$MAINTAINER_NAME" -a -n "$MAINTAINER_EMAIL" ] -then +if [[ -n "$MAINTAINER_NAME" ]] && [[ -n "$MAINTAINER_EMAIL" ]]; then echo "Set Maintainer field in debian control file ($MAINTAINER_NAME <$MAINTAINER_EMAIL>)..." - sed -i "s/^Maintainer: .*$/Maintainer: $MAINTAINER_NAME <$MAINTAINER_EMAIL>/" $BDIR/debian/control + sed -i "s/^Maintainer: .*$/Maintainer: $MAINTAINER_NAME <$MAINTAINER_EMAIL>/" \ + "$BDIR"/debian/control fi echo "Build debian package..." -cd $BDIR +cd "$BDIR" || exit dpkg-buildpackage