2019-11-25 02:48:12 +01:00
---
2021-05-30 17:52:25 +02:00
image : s3lph/spaceapi-server-ci:20210530-01
2019-11-25 02:48:12 +01:00
stages :
2019-11-26 14:24:53 +01:00
- test
- build
2019-11-26 16:07:17 +01:00
- release
2019-11-25 02:48:12 +01:00
before_script :
2019-11-26 14:24:53 +01:00
- export SPACEAPI_SERVER_VERSION=$(python -c 'import spaceapi_server; print(spaceapi_server.__version__)')
2019-11-25 02:48:12 +01:00
test :
stage : test
script :
2019-11-26 14:24:53 +01:00
- pip3 install -e .
- python3 -m coverage run --rcfile=setup.cfg -m unittest discover spaceapi_server
- python3 -m coverage combine
- python3 -m coverage report --rcfile=setup.cfg
2019-11-25 02:48:12 +01:00
codestyle :
stage : test
script :
2019-11-26 14:24:53 +01:00
- pip3 install -e .
- pycodestyle spaceapi_server
2019-11-25 02:48:12 +01:00
build_wheel :
stage : build
script :
- python3 setup.py egg_info bdist_wheel
- cd dist
- sha256sum *.whl > SHA256SUMS
artifacts :
paths :
- "dist/*.whl"
- dist/SHA256SUMS
only :
- tags
2019-11-26 14:24:53 +01:00
build_debian :
stage : build
script :
- find package/debian -name .gitkeep -delete
# Copy example plugin
- install -m0644 examples/plugins/example.py package/debian/spaceapi-server/etc/spaceapi-server/plugins/example.py
# Create control
- |
cat > package/debian/spaceapi-server/DEBIAN/control <<EOF
Package : spaceapi-server
Version : ${SPACEAPI_SERVER_VERSION}
Maintainer : s3lph <account-gitlab-ideynizv@kernelpanic.lol>
Section : web
Priority : optional
Architecture : all
2021-05-30 17:52:25 +02:00
Depends : python3 (>= 3.9), python3-yaml, python3-bottle
2019-11-26 14:24:53 +01:00
Description : Lightweight SpaceAPI endpoint server
Lightweight server for SpaceAPI endpoints. Includes support for pluggable
templating, so dynamic content, like sensor values, can be added.
EOF
- chmod 0644 package/debian/spaceapi-server/DEBIAN/control
# Create changelog
- |
for version in "$(cat CHANGELOG.md | grep '<!-- BEGIN CHANGES' | cut -d ' ' -f 4)"; do
echo "spaceapi-server (${version}-1); urgency=medium\n" >> package/debian/spaceapi-server/usr/share/doc/spaceapi-server/changelog
cat CHANGELOG.md | grep -A 1000 "<"'!'"-- BEGIN CHANGES ${version} -->" | grep -B 1000 "<"'!'"-- END CHANGES ${version} -->" | tail -n +2 | head -n -1 | sed -re 's/^-/ */g' >> package/debian/spaceapi-server/usr/share/doc/spaceapi-server/changelog
echo "\n -- s3lph <account-gitlab-ideynizv@kernelpanic.lol> $(date -R)\n" >> package/debian/spaceapi-server/usr/share/doc/spaceapi-server/changelog
done
- gzip -9n package/debian/spaceapi-server/usr/share/doc/spaceapi-server/changelog
# Copy license
- install -m0644 LICENSE package/debian/spaceapi-server/usr/share/doc/spaceapi-server/copyright
# Install spaceapi-server into package root
- python3 setup.py egg_info install --root=package/debian/spaceapi-server/ --prefix=/usr --optimize=1
- cd package/debian/spaceapi-server
- mkdir -p usr/lib/python3/dist-packages/
2021-05-30 17:52:25 +02:00
- cp -r usr/lib/python3.9/site-packages/spaceapi_server* usr/lib/python3/dist-packages/
- rm -rf usr/lib/python3.9/
2019-11-26 14:24:53 +01:00
# Remove compiled Python files
- find usr/lib/python3/dist-packages -name __pycache__ -exec rm -r {} \; 2>/dev/null || true
- find usr/lib/python3/dist-packages -name '*.pyc' -exec rm {} \;
2019-11-26 16:07:17 +01:00
# Remove spaceapi-server script
- rm usr/bin/spaceapi-server
2019-11-26 14:24:53 +01:00
# Fix file permissions
- find . -type f -exec chmod 0644 {} \;
- find . -type d -exec chmod 755 {} \;
2019-11-26 16:48:34 +01:00
- chmod 0755 DEBIAN/postinst DEBIAN/prerm DEBIAN/postrm
2019-11-26 14:24:53 +01:00
# Build the package
- cd ..
- dpkg-deb --build spaceapi-server
- mv spaceapi-server.deb "spaceapi-server_${SPACEAPI_SERVER_VERSION}-1_all.deb"
# Run lintian
- sudo -u nobody lintian --fail-on-warnings "spaceapi-server_${SPACEAPI_SERVER_VERSION}-1_all.deb"
# Generate checksum
- sha256sum *.deb > SHA256SUMS
artifacts :
paths :
- "package/debian/*.deb"
- package/debian/SHA256SUMS
only :
- tags
2019-11-26 16:07:17 +01:00
build_archlinux :
stage : build
2021-05-30 18:09:03 +02:00
image : archlinux:latest # Use an archlinux image instead of the customized debian image.
2019-11-26 16:07:17 +01:00
script :
- find package/archlinux -name .gitkeep -delete
# Install dependencies
2021-05-30 17:52:25 +02:00
- pacman -Sy --noconfirm namcap python python-setuptools python-pip python-wheel python-yaml python-bottle base-devel
2019-11-26 16:07:17 +01:00
- export SPACEAPI_SERVER_VERSION=$(python -c 'import spaceapi_server; print(spaceapi_server.__version__)')
# Copy example plugin
- install -m0644 examples/plugins/example.py package/archlinux/spaceapi-server/etc/spaceapi-server/plugins/example.py
# Create changelog
- |
for version in "$(cat CHANGELOG.md | grep '<!-- BEGIN CHANGES' | cut -d ' ' -f 4)"; do
echo "$(date +%Y-%m-%d) s3lph <account-gitlab-ideynizv@kernelpanic.lol>" >> package/archlinux/spaceapi-server.changelog
cat CHANGELOG.md | grep -A 1000 "<"'!'"-- BEGIN CHANGES ${version} -->" | grep -B 1000 "<"'!'"-- END CHANGES ${version} -->" | tail -n +2 | head -n -1 | sed -re 's/^-/\t*/g' >> package/archlinux/spaceapi-server.changelog
echo >> package/archlinux/spaceapi-server.changelog
done
# Copy license
- install -m0644 LICENSE package/archlinux/spaceapi-server/usr/share/licenses/spaceapi-server/LICENSE
# Install spaceapi-server into pkgdir
- python setup.py egg_info -d -b +master install --root=package/archlinux/spaceapi-server/ --prefix=/usr --optimize=1
- cd package/archlinux
# Remove spaceapi-server script
- rm -rf spaceapi-server/usr/bin
# Build the package
- sed -re "s/__VERSION__/${SPACEAPI_SERVER_VERSION}/g" -i PKGBUILD
- sudo -u nobody makepkg -c
# Run namcap
2021-05-30 18:09:03 +02:00
- sudo -u nobody namcap *.pkg.tar.*
2019-11-26 16:07:17 +01:00
# Generate checksum
2021-05-30 18:09:03 +02:00
- sha256sum *.pkg.tar.* > SHA256SUMS
2019-11-26 16:07:17 +01:00
artifacts :
paths :
2021-05-30 18:09:03 +02:00
- "package/archlinux/*.pkg.tar.*"
2019-11-26 16:07:17 +01:00
- package/archlinux/SHA256SUMS
only :
- tags
2020-06-20 03:42:14 +02:00
build_docker :
stage : build
script :
- docker build -t "registry.gitlab.com/s3lph/spaceapi-server:$CI_COMMIT_SHA" -f package/docker/Dockerfile .
- docker tag "registry.gitlab.com/s3lph/spaceapi-server:$CI_COMMIT_SHA" "registry.gitlab.com/s3lph/spaceapi-server:$CI_COMMIT_REF_NAME"
- if [[ -n "$CI_COMMIT_TAG" ]]; then docker tag "registry.gitlab.com/s3lph/spaceapi-server:$CI_COMMIT_SHA" "registry.gitlab.com/s3lph/spaceapi-server:$CI_COMMIT_TAG"; fi
2020-06-20 04:29:06 +02:00
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_TOKEN registry.gitlab.com
2020-06-20 03:42:14 +02:00
- docker push "registry.gitlab.com/s3lph/spaceapi-server:$CI_COMMIT_SHA"
- docker push "registry.gitlab.com/s3lph/spaceapi-server:$CI_COMMIT_REF_NAME"
- if [[ -n "$CI_COMMIT_TAG" ]]; then docker push "registry.gitlab.com/s3lph/spaceapi-server:$CI_COMMIT_TAG"; fi
only :
- tags
2019-11-26 16:07:17 +01:00
release :
stage : release
script :
- python3 package/release.py
only :
2020-06-20 03:42:14 +02:00
- tags