2023-07-24 12:12:13 +02:00
|
|
|
---
|
2023-07-24 11:05:38 +02:00
|
|
|
kind: pipeline
|
|
|
|
type: docker
|
|
|
|
name: default
|
|
|
|
|
2023-08-06 10:49:44 +02:00
|
|
|
volumes:
|
|
|
|
- name: docs
|
|
|
|
host:
|
|
|
|
path: /opt/docs/platypush
|
|
|
|
|
2023-07-24 11:05:38 +02:00
|
|
|
steps:
|
2023-07-25 00:00:47 +02:00
|
|
|
- name: github-mirror
|
|
|
|
image: alpine
|
|
|
|
environment:
|
|
|
|
SSH_PUBKEY:
|
|
|
|
from_secret: ssh_pubkey
|
|
|
|
SSH_PRIVKEY:
|
|
|
|
from_secret: ssh_privkey
|
|
|
|
|
|
|
|
commands:
|
|
|
|
- apk add --update --no-cache git openssh
|
|
|
|
- mkdir -p ~/.ssh
|
2023-08-06 00:44:03 +02:00
|
|
|
- echo $SSH_PUBKEY > ~/.ssh/id_rsa.pub
|
2023-07-25 00:00:47 +02:00
|
|
|
- |
|
|
|
|
cat <<EOF > ~/.ssh/id_rsa
|
|
|
|
$SSH_PRIVKEY
|
|
|
|
EOF
|
|
|
|
- chmod 0600 ~/.ssh/id_rsa
|
|
|
|
- ssh-keyscan github.com >> ~/.ssh/known_hosts 2>/dev/null
|
2023-07-25 00:21:56 +02:00
|
|
|
- git config --global --add safe.directory $PWD
|
2023-07-25 00:00:47 +02:00
|
|
|
- git remote add github git@github.com:/BlackLight/platypush.git
|
2023-08-31 02:32:42 +02:00
|
|
|
- git pull --rebase github "$(git branch | head -1 | awk '{print $2}')" || echo "No such branch on Github"
|
2023-08-31 02:23:13 +02:00
|
|
|
- git push --all -v github
|
2023-07-25 00:00:47 +02:00
|
|
|
|
2023-08-06 10:49:44 +02:00
|
|
|
- name: docs
|
2023-08-04 11:18:42 +02:00
|
|
|
image: alpine
|
|
|
|
volumes:
|
|
|
|
- name: docs
|
|
|
|
path: /docs
|
|
|
|
|
|
|
|
commands:
|
|
|
|
- echo "Installing required build dependencies"
|
|
|
|
- apk add --update --no-cache make py3-sphinx py3-pip py3-paho-mqtt
|
|
|
|
- pip install -U hid sphinx-rtd-theme sphinx-book-theme
|
|
|
|
- pip install .
|
|
|
|
- mkdir -p /docs/current
|
|
|
|
- export APPDIR=$PWD
|
|
|
|
- rm -rf "$APPDIR/docs/build"
|
|
|
|
- echo "Building the updated documentation"
|
|
|
|
- cd "$APPDIR/docs"
|
|
|
|
- make html
|
|
|
|
- rm -f config*.yaml
|
|
|
|
- cd "$APPDIR"
|
|
|
|
- echo "Copying the new documentation files to the target folder"
|
|
|
|
- mv -v "$APPDIR/docs/build" /docs/new
|
|
|
|
- cd /docs
|
|
|
|
- mv current old
|
|
|
|
- mv new current
|
|
|
|
- rm -rf old
|
|
|
|
|
2023-08-05 14:43:10 +02:00
|
|
|
when:
|
|
|
|
event:
|
|
|
|
- tag
|
|
|
|
|
2023-08-06 00:44:03 +02:00
|
|
|
- name: tests
|
2023-07-24 11:05:38 +02:00
|
|
|
image: python:3.11-alpine
|
|
|
|
commands:
|
|
|
|
- apk add --update --no-cache redis
|
2023-08-15 11:40:02 +02:00
|
|
|
- apk add --update --no-cache --virtual build-base g++ rust linux-headers
|
2023-07-24 11:05:38 +02:00
|
|
|
- pip install -U pip
|
|
|
|
- pip install .
|
|
|
|
- pip install -r requirements-tests.txt
|
2023-08-15 11:40:02 +02:00
|
|
|
- apk del build-base g++ rust linux-headers
|
2023-07-24 11:05:38 +02:00
|
|
|
- pytest tests
|
2023-08-04 11:18:42 +02:00
|
|
|
|
2023-08-06 22:21:22 +02:00
|
|
|
- name: build-ui
|
|
|
|
image: node:current-alpine3.18
|
|
|
|
|
|
|
|
environment:
|
|
|
|
SSH_PUBKEY:
|
|
|
|
from_secret: ssh_pubkey
|
|
|
|
SSH_PRIVKEY:
|
|
|
|
from_secret: ssh_privkey
|
|
|
|
PGP_KEY:
|
|
|
|
from_secret: pgp_key
|
|
|
|
PGP_KEY_ID:
|
|
|
|
from_secret: pgp_key_id
|
|
|
|
|
|
|
|
when:
|
|
|
|
branch:
|
|
|
|
- master
|
|
|
|
event:
|
|
|
|
- push
|
|
|
|
|
|
|
|
depends_on:
|
|
|
|
- tests
|
|
|
|
|
|
|
|
commands:
|
|
|
|
- apk add --update --no-cache git
|
2023-08-07 00:45:51 +02:00
|
|
|
|
|
|
|
# Backup the original git configuration before changing attributes
|
|
|
|
- export GIT_CONF=$PWD/.git/config
|
|
|
|
- cp $GIT_CONF /tmp/git.config.orig
|
|
|
|
|
2023-08-06 22:21:22 +02:00
|
|
|
- git config --global --add safe.directory $PWD
|
|
|
|
- cd platypush/backend/http/webapp
|
|
|
|
- |
|
|
|
|
if [ $(git log --pretty=oneline $DRONE_COMMIT_AFTER...$DRONE_COMMIT_BEFORE . | wc -l) -eq 0 ]; then
|
|
|
|
echo "No UI changes detected, skipping build"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-08-07 00:10:46 +02:00
|
|
|
- |
|
|
|
|
if [ "$(git log --pretty=format:%s HEAD...HEAD~1)" == "[Automatic] Updated UI files" ]; then
|
|
|
|
echo "UI changes have already been committed, skipping build"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2023-09-17 12:56:54 +02:00
|
|
|
- rm -rf node_modules
|
2023-08-06 22:21:22 +02:00
|
|
|
- npm install
|
|
|
|
- npm run build
|
|
|
|
- |
|
|
|
|
if [ $(git status --porcelain dist | wc -l) -eq 0 ]; then
|
|
|
|
echo "No build files have been changed"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
- apk add --update --no-cache bash gnupg openssh
|
|
|
|
- mkdir -p ~/.ssh
|
|
|
|
- |
|
|
|
|
cat <<EOF | gpg --import --armor
|
|
|
|
$PGP_KEY
|
|
|
|
EOF
|
|
|
|
|
|
|
|
- echo $SSH_PUBKEY > ~/.ssh/id_rsa.pub
|
|
|
|
- |
|
|
|
|
cat <<EOF > ~/.ssh/id_rsa
|
|
|
|
$SSH_PRIVKEY
|
|
|
|
EOF
|
|
|
|
- chmod 0600 ~/.ssh/id_rsa
|
|
|
|
- ssh-keyscan git.platypush.tech >> ~/.ssh/known_hosts 2>/dev/null
|
|
|
|
|
|
|
|
- git config user.name "Platypush CI/CD Automation"
|
|
|
|
- git config user.email "admin@platypush.tech"
|
2023-08-07 00:10:46 +02:00
|
|
|
- git config commit.gpgsign true
|
2023-08-06 22:21:22 +02:00
|
|
|
- git config user.signingkey $PGP_KEY_ID
|
|
|
|
- git add dist
|
|
|
|
- git commit dist -S -m "[Automatic] Updated UI files" --no-verify
|
2023-08-06 23:40:35 +02:00
|
|
|
- git remote rm origin
|
|
|
|
- git remote add origin git@git.platypush.tech:platypush/platypush.git
|
|
|
|
- git push origin master
|
2023-08-06 22:21:22 +02:00
|
|
|
|
2023-08-07 00:19:02 +02:00
|
|
|
# Restore the original git configuration
|
2023-08-07 00:45:51 +02:00
|
|
|
- mv /tmp/git.config.orig $GIT_CONF
|
2023-08-07 00:19:02 +02:00
|
|
|
|
2023-08-06 00:44:03 +02:00
|
|
|
- name: update-arch-packages
|
|
|
|
image: python:3.11-alpine
|
|
|
|
environment:
|
|
|
|
WORKDIR: /tmp/workdir
|
|
|
|
SSH_PUBKEY:
|
|
|
|
from_secret: ssh_pubkey
|
|
|
|
SSH_PRIVKEY:
|
|
|
|
from_secret: ssh_privkey
|
|
|
|
|
|
|
|
when:
|
|
|
|
branch:
|
|
|
|
- master
|
2023-08-06 22:21:22 +02:00
|
|
|
event:
|
|
|
|
- push
|
2023-08-06 00:44:03 +02:00
|
|
|
|
|
|
|
depends_on:
|
2023-08-06 22:21:22 +02:00
|
|
|
- build-ui
|
2023-08-06 00:44:03 +02:00
|
|
|
|
|
|
|
commands:
|
|
|
|
- echo "-- Installing dependencies"
|
|
|
|
- apk add --update --no-cache curl git openssh pacman sudo
|
|
|
|
|
|
|
|
- echo "--- Parsing metadata"
|
|
|
|
- git config --global --add safe.directory $PWD
|
2023-09-04 02:53:20 +02:00
|
|
|
- git pull --rebase origin master --tags
|
2023-08-06 00:44:03 +02:00
|
|
|
- export VERSION=$(python setup.py --version)
|
2023-09-18 11:00:46 +02:00
|
|
|
- export HEAD=$(git log --pretty=format:%h HEAD...HEAD~1)
|
2023-08-06 00:48:20 +02:00
|
|
|
- export GIT_VERSION="$VERSION.r$(git log --pretty=oneline HEAD...v$VERSION | wc -l).$HEAD"
|
2023-08-06 00:44:03 +02:00
|
|
|
- export TAG_URL="https://git.platypush.tech/platypush/platypush/archive/v$VERSION.tar.gz"
|
|
|
|
- export TAG_ARCHIVE="platypush-$VERSION.tar.gz"
|
|
|
|
|
|
|
|
- echo "--- Preparing environment"
|
|
|
|
- mkdir -p ~/.ssh
|
|
|
|
- echo $SSH_PUBKEY > ~/.ssh/id_rsa.pub
|
|
|
|
- |
|
|
|
|
cat <<EOF > ~/.ssh/id_rsa
|
|
|
|
$SSH_PRIVKEY
|
|
|
|
EOF
|
|
|
|
- chmod 0600 ~/.ssh/id_rsa
|
|
|
|
- ssh-keyscan git.platypush.tech >> ~/.ssh/known_hosts 2>/dev/null
|
|
|
|
- ssh-keyscan aur.archlinux.org >> ~/.ssh/known_hosts 2>/dev/null
|
|
|
|
- adduser -u 1000 -D build
|
|
|
|
- mkdir -p $WORKDIR
|
|
|
|
|
|
|
|
- echo "--- Updating Arch git version"
|
|
|
|
- export PKGDIR=$WORKDIR/git
|
|
|
|
- git clone ssh://aur@aur.archlinux.org/platypush-git.git $PKGDIR
|
|
|
|
- git config --global --add safe.directory $PKGDIR
|
|
|
|
- chown -R build $PKGDIR
|
|
|
|
- cd $PKGDIR
|
|
|
|
- |
|
|
|
|
sed -i 'PKGBUILD' -r \
|
|
|
|
-e "s/^pkgver=.*/pkgver=$GIT_VERSION/" \
|
|
|
|
-e "s/^pkgrel=.*/pkgrel=1/" \
|
|
|
|
- sudo -u build makepkg --printsrcinfo > .SRCINFO
|
|
|
|
- export FILES_CHANGED=$(git status --porcelain --untracked-files=no | wc -l)
|
|
|
|
- |
|
|
|
|
if [ $FILES_CHANGED -gt 0 ]; then
|
|
|
|
echo "--- Pushing git package version $GIT_VERSION"
|
|
|
|
git commit -a -m '[Automatic] Package update'
|
|
|
|
git push origin master
|
|
|
|
fi
|
|
|
|
|
|
|
|
- echo "--- Updating Arch stable version"
|
|
|
|
- export PKGDIR=$WORKDIR/stable
|
|
|
|
- git clone ssh://aur@aur.archlinux.org/platypush.git $PKGDIR
|
|
|
|
- git config --global --add safe.directory $PKGDIR
|
|
|
|
- chown -R build $PKGDIR
|
|
|
|
- cd $PKGDIR
|
|
|
|
- export RELEASED_VERSION=$(grep -e '^pkgver=' PKGBUILD | sed -r -e 's/^pkgver=(.*)\s*/\1/')
|
|
|
|
- |
|
|
|
|
if [ "$RELEASED_VERSION" == "$VERSION" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
- export TAG_CHECKSUM=$(curl --silent "$TAG_URL" | sha512sum | awk '{print $1}')
|
|
|
|
- |
|
|
|
|
sed -i 'PKGBUILD' -r \
|
|
|
|
-e "s/^pkgver=.*/pkgver=$VERSION/" \
|
|
|
|
-e "s/^pkgrel=.*/pkgrel=1/" \
|
|
|
|
-e "s/^sha512sums=.*/sha512sums=('$TAG_CHECKSUM')/"
|
|
|
|
|
|
|
|
- sudo -u build makepkg --printsrcinfo > .SRCINFO
|
|
|
|
- export FILES_CHANGED=$(git status --porcelain --untracked-files=no | wc -l)
|
|
|
|
- |
|
|
|
|
if [ $FILES_CHANGED -gt 0 ]; then
|
|
|
|
echo "--- Pushing stable package version $VERSION"
|
|
|
|
git commit -a -m '[Automatic] Package update'
|
|
|
|
git push origin master
|
|
|
|
fi
|
|
|
|
|
2023-09-18 11:00:46 +02:00
|
|
|
- name: update-debian-packages
|
|
|
|
image: python:3.11-bookworm
|
|
|
|
environment:
|
|
|
|
WORKDIR: /tmp/workdir
|
|
|
|
STABLE_PKG_NAME: platypush
|
|
|
|
GIT_PKG_NAME: platypush-git
|
|
|
|
AWS_ENDPOINT_URL: https://s3.nl-ams.scw.cloud
|
|
|
|
AWS_ACCESS_KEY_ID: aws_access_key_id
|
2023-09-18 11:47:36 +02:00
|
|
|
AWS_SECRET_ACCESS_KEY: aws_secret_access_key
|
2023-09-18 11:00:46 +02:00
|
|
|
|
|
|
|
when:
|
|
|
|
branch:
|
|
|
|
- master
|
|
|
|
event:
|
|
|
|
- push
|
|
|
|
|
|
|
|
depends_on:
|
|
|
|
- build-ui
|
|
|
|
|
|
|
|
commands:
|
|
|
|
- echo "-- Installing dependencies"
|
|
|
|
- apt update
|
|
|
|
- apt install -y dpkg-dev gpg
|
|
|
|
- pip install awscli
|
|
|
|
|
|
|
|
- echo "--- Parsing metadata"
|
|
|
|
- git config --global --add safe.directory $PWD
|
|
|
|
- git pull --rebase origin master --tags
|
|
|
|
- export VERSION=$(python setup.py --version)
|
|
|
|
- export HEAD=$(git log --pretty=format:%h HEAD...HEAD~1)
|
|
|
|
- export GIT_VERSION="$VERSION.r$(git log --pretty=oneline HEAD...v$VERSION | wc -l).$HEAD"
|
|
|
|
- export TAG_URL="https://git.platypush.tech/platypush/platypush/archive/v$VERSION.tar.gz"
|
|
|
|
- export TAG_ARCHIVE="platypush-$VERSION.tar.gz"
|
2023-09-18 11:54:32 +02:00
|
|
|
- export GIT_BUILD_DIR="$WORKDIR/$GIT_PKG_NAME_$GIT_VERSION_all"
|
|
|
|
- export PKGNAME="$WORKDIR/$${GIT_PKG_NAME}_$${GIT_VERSION}.deb"
|
2023-09-18 11:00:46 +02:00
|
|
|
|
|
|
|
- echo "--- Building git package"
|
2023-09-18 11:34:00 +02:00
|
|
|
- pip install --prefix="$GIT_BUILD_DIR" --no-cache --no-deps .
|
2023-09-18 11:54:32 +02:00
|
|
|
- mkdir -p "$GIT_BUILD_DIR/__all/DEBIAN"
|
2023-09-18 11:00:46 +02:00
|
|
|
- |
|
2023-09-18 11:54:32 +02:00
|
|
|
cat <<EOF > "$GIT_BUILD_DIR/__all/DEBIAN/control"
|
2023-09-18 11:00:46 +02:00
|
|
|
Package: $GIT_PKG_NAME
|
|
|
|
Version: $GIT_VERSION
|
|
|
|
Maintainer: Fabio Manganiello <fabio@platypush.tech>
|
2023-09-18 11:44:59 +02:00
|
|
|
Depends: $(cat platypush/install/requirements/debian.txt | tr '\n' ',' | sed -re 's/,$//' -e 's/,/, /g')
|
2023-09-18 11:00:46 +02:00
|
|
|
Architecture: all
|
|
|
|
Homepage: https://platypush.tech
|
|
|
|
Description: Universal command executor and automation hub.
|
2023-09-18 11:34:57 +02:00
|
|
|
EOF
|
2023-09-18 11:00:46 +02:00
|
|
|
- dpkg --build "$GIT_BUILD_DIR"
|
|
|
|
- aws s3 cp "$PKGNAME" s3://platypush-static/deb/git/
|
|
|
|
|
2023-08-06 10:49:44 +02:00
|
|
|
- name: update-pip-package
|
|
|
|
image: python:3.11-alpine
|
|
|
|
environment:
|
|
|
|
TWINE_USERNAME:
|
|
|
|
from_secret: pypi_user
|
|
|
|
TWINE_PASSWORD:
|
|
|
|
from_secret: pypi_pass
|
|
|
|
|
|
|
|
when:
|
|
|
|
event:
|
|
|
|
- tag
|
|
|
|
|
|
|
|
depends_on:
|
|
|
|
- tests
|
|
|
|
- docs
|
|
|
|
|
|
|
|
commands:
|
|
|
|
- apk add --update --no-cache py3-twine
|
|
|
|
- python setup.py sdist bdist_wheel
|
|
|
|
- twine upload dist/platypush-$(python setup.py --version).tar.gz
|
2023-08-06 11:08:01 +02:00
|
|
|
|
|
|
|
- name: notify-release
|
|
|
|
image: python:3.11-alpine
|
|
|
|
environment:
|
|
|
|
WORKER_RPC_SECRET:
|
|
|
|
from_secret: worker_rpc_secret
|
|
|
|
|
|
|
|
when:
|
|
|
|
event:
|
|
|
|
- tag
|
|
|
|
|
|
|
|
depends_on:
|
|
|
|
- update-pip-package
|
|
|
|
- update-arch-packages
|
2023-09-18 11:00:46 +02:00
|
|
|
- update-debian-packages
|
2023-08-06 11:08:01 +02:00
|
|
|
|
|
|
|
commands:
|
|
|
|
- apk add --update --no-cache curl
|
|
|
|
- |
|
|
|
|
curl --silent -XPOST \
|
|
|
|
-H "X-Token: $WORKER_RPC_SECRET" \
|
|
|
|
"https://worker.ci-cd.platypush.tech/hook/notify-platypush-release?version=$(python setup.py --version)"
|
2023-08-06 11:14:12 +02:00
|
|
|
|
|
|
|
- name: notify-build-status
|
|
|
|
image: alpine
|
|
|
|
environment:
|
|
|
|
WORKER_RPC_SECRET:
|
|
|
|
from_secret: worker_rpc_secret
|
|
|
|
|
|
|
|
when:
|
|
|
|
branch:
|
|
|
|
- master
|
|
|
|
event:
|
|
|
|
- push
|
2023-08-07 00:05:13 +02:00
|
|
|
status:
|
|
|
|
- success
|
|
|
|
- failure
|
2023-08-06 11:14:12 +02:00
|
|
|
|
|
|
|
depends_on:
|
|
|
|
- update-arch-packages
|
2023-09-18 11:00:46 +02:00
|
|
|
- update-debian-packages
|
2023-08-06 11:14:12 +02:00
|
|
|
|
|
|
|
commands:
|
|
|
|
- apk add --update --no-cache curl
|
|
|
|
- |
|
|
|
|
curl --silent -XPOST \
|
|
|
|
-H "X-Token: $WORKER_RPC_SECRET" \
|
|
|
|
"https://worker.ci-cd.platypush.tech/hook/notify-platypush-build?status=$DRONE_BUILD_STATUS"
|