ffsend/.gitlab-ci.yml

322 lines
9.8 KiB
YAML

# GitLab CI configuration for ffsend builds, tests and releases
#
# To add a new release:
# - configure a new 'build-*' job with the proper target
# - export a build artifact from the new job
# - manually upload artifact to GitHub in the 'github-release' job
image: "rust:slim"
stages:
- check
- build
- test
- release
- package
variables:
RUST_VERSION: stable
# Cache rust/cargo/build artifacts
cache:
key: "$CI_PIPELINE_ID-$RUST_VERSION"
paths:
- /usr/local/cargo/registry/
- /usr/local/rustup/toolchains/
- /usr/local/rustup/update-hashes/
- target/
# Install compiler and OpenSSL dependencies
before_script:
- apt-get update
- apt-get install -y --no-install-recommends build-essential pkg-config libssl-dev
- |
rustup install $RUST_VERSION
rustup default $RUST_VERSION
- |
rustc --version
cargo --version
# Variable defaults
variables:
RUST_VERSION: stable
RUST_TARGET: x86_64-unknown-linux-gnu
# Check on stable, beta and nightly
.check-base: &check-base
stage: check
script:
- cargo check --verbose
- cargo check --no-default-features --features send2 --verbose
- cargo check --no-default-features --features send3 --verbose
- cargo check --no-default-features --features send2,send3 --verbose
- cargo check --no-default-features --features send2,send3,archive --verbose
- cargo check --no-default-features --features send2,send3,history --verbose
- cargo check --no-default-features --features send2,send3,qrcode --verbose
- cargo check --no-default-features --features send2,send3,urlshorten --verbose
- cargo check --no-default-features --features send2,send3,infer-command --verbose
- cargo check --features no-color --verbose
check-stable:
<<: *check-base
check-beta:
<<: *check-base
variables:
RUST_VERSION: beta
check-nightly:
<<: *check-base
variables:
RUST_VERSION: nightly
check-old:
<<: *check-base
variables:
RUST_VERSION: "1.32.0"
# Build using Rust stable
build-x86_64-linux-gnu:
stage: build
script:
- cargo build --target=$RUST_TARGET --release --verbose
- mv target/$RUST_TARGET/release/ffsend ./ffsend-$RUST_TARGET
- strip -g ./ffsend-$RUST_TARGET
artifacts:
name: ffsend-x86_64-linux-gnu
paths:
- ffsend-$RUST_TARGET
expire_in: 1 month
# Build a static version
build-x86_64-linux-musl:
stage: build
variables:
RUST_TARGET: x86_64-unknown-linux-musl
script:
# Install the static target
- rustup target add $RUST_TARGET
# Build OpenSSL statically
- apt install -y build-essential wget musl-tools
- wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz
- tar xzvf openssl-1.0.2o.tar.gz
- cd openssl-1.0.2o
- ./config -fPIC --openssldir=/usr/local/ssl --prefix=/usr/local
- make
- make install
- cd ..
# Statically build ffsend
- export OPENSSL_STATIC=1
- export OPENSSL_LIB_DIR=/usr/local/lib
- export OPENSSL_INCLUDE_DIR=/usr/local/include
- cargo build --target=$RUST_TARGET --release --verbose
# Prepare the release artifact, strip it
- find . -name ffsend -exec ls -lah {} \;
- mv target/$RUST_TARGET/release/ffsend ./ffsend-$RUST_TARGET
- strip -g ./ffsend-$RUST_TARGET
artifacts:
name: ffsend-x86_64-linux-musl
paths:
- ffsend-$RUST_TARGET
expire_in: 1 month
# Run the unit tests through Cargo
test-cargo:
stage: test
dependencies: []
script:
- cargo test --verbose
# Run integration test with the public Send service
test-public:
image: alpine:latest
stage: test
dependencies:
- build-x86_64-linux-musl
variables:
GIT_STRATEGY: none
RUST_TARGET: x86_64-unknown-linux-musl
before_script: []
script:
# Prepare ffsend binary, create random file
- mv ./ffsend-$RUST_TARGET ./ffsend
- chmod a+x ./ffsend
- head -c1m </dev/urandom >test.txt
# Generate random file, upload/download and assert equality
- ./ffsend upload test.txt -I
- ./ffsend download $(./ffsend history -q) -I -o=download.txt
- "cmp -s ./test.txt ./download.txt || (echo ERROR: Downloaded file is different than original; exit 1)"
- rm ./download.txt
# Cargo crate release
release-crate:
stage: release
dependencies: []
only:
- /^v(\d+\.)*\d+$/
script:
- echo "Creating release crate to publish on crates.io..."
- echo $CARGO_TOKEN | cargo login
- echo "Publishing crate to crates.io..."
- cargo publish --verbose --allow-dirty
# Snap release
release-snap:
image: snapcore/snapcraft:edge
stage: release
dependencies: []
only:
- /^v(\d+\.)*\d+$/
before_script: []
script:
# Prepare the environment
- apt-get update -y
- cd pkg/snap
# Update version number in snapcraft.yaml
- VERSION=$(echo $CI_COMMIT_REF_NAME | cut -c 2-)
- echo "Determined binary version number 'v$VERSION', updating snapcraft.yaml..."
- 'sed "s/^version:.*\$/version: $VERSION/" -i snapcraft.yaml'
- 'sed "s/^pkgver=.*\$/pkgver=$VERSION/" -i snapcraft.yaml'
# Build the package
- echo "Building snap package..."
- snapcraft
# Publish snap package
- echo "Publishing snap package..."
- echo "$SNAPCRAFT_LOGIN" | base64 -d > snapcraft.login
- snapcraft login --with snapcraft.login
- snapcraft push --release=stable ffsend_*_amd64.snap
artifacts:
name: ffsend-snap-x86_64
paths:
- pkg/snap/ffsend_*_amd64.snap
expire_in: 1 month
# Publish release binaries to as GitHub release
release-github:
stage: release
only:
- /^v(\d+\.)*\d+$/
dependencies:
- build-x86_64-linux-gnu
- build-x86_64-linux-musl
before_script: []
script:
# Install dependencies
- apt-get update
- apt-get install -y curl wget gzip netbase
# Download github-release binary
- wget $(curl -s https://api.github.com/repos/tfausak/github-release/releases/latest | grep 'browser_' | cut -d\" -f4 | grep 'linux') -O github-release.gz
- gunzip github-release.gz
- chmod a+x ./github-release
# Create the release, upload binaries
- ./github-release release --token "$GITHUB_TOKEN" --owner timvisee --repo ffsend --tag "$CI_COMMIT_REF_NAME" --title "ffsend $CI_COMMIT_REF_NAME"
- ./github-release upload --token "$GITHUB_TOKEN" --owner timvisee --repo ffsend --tag "$CI_COMMIT_REF_NAME" --file ./ffsend-x86_64-unknown-linux-gnu --name ffsend-$CI_COMMIT_REF_NAME-linux-x64
- ./github-release upload --token "$GITHUB_TOKEN" --owner timvisee --repo ffsend --tag "$CI_COMMIT_REF_NAME" --file ./ffsend-x86_64-unknown-linux-musl --name ffsend-$CI_COMMIT_REF_NAME-linux-x64-static
# Publish a Docker image
release-docker:
image: docker:git
stage: release
only:
- /^v(\d+\.)*\d+$/
dependencies:
- build-x86_64-linux-musl
services:
- docker:dind
variables:
RUST_TARGET: x86_64-unknown-linux-musl
DOCKER_HOST: tcp://docker:2375
# DOCKER_DRIVER: overlay2
before_script: []
script:
# Place binary in Docker directory, change to it
- mv ./ffsend-$RUST_TARGET ./pkg/docker/ffsend
- cd ./pkg/docker
# Build the Docker image, run it once to test
- docker build -t timvisee/ffsend:latest ./
- docker run --rm timvisee/ffsend:latest
# Retag version
- VERSION=$(echo $CI_COMMIT_REF_NAME | cut -c 2-)
- echo "Determined Docker image version number 'v$VERSION', retagging image..."
- docker tag timvisee/ffsend:latest timvisee/ffsend:$VERSION
# Authenticate and push the Docker images
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USER" --password-stdin
- docker push timvisee/ffsend:$VERSION
- docker push timvisee/ffsend:latest
# AUR packages release
package-aur:
image: archlinux/base
stage: package
dependencies: []
only:
- /^v(\d+\.)*\d+$/
before_script: []
script:
- cd ./pkg/aur
# Update version number in PKGBUILD
- VERSION=$(echo $CI_COMMIT_REF_NAME | cut -c 2-)
- echo "Determined binary version number 'v$VERSION', updating PKGBUILDs..."
- sed "s/^pkgver=.*\$/pkgver=$VERSION/" -i bin/PKGBUILD
- sed "s/^pkgver=.*\$/pkgver=$VERSION/" -i git/PKGBUILD
# Install dependencies
- echo "Installing required build packages..."
- pacman -Syu --noconfirm sudo base-devel binutils openssh rust cargo cmake git openssl
# Make AUR package
- echo "Making AUR package..."
- mkdir -p /.cargo
- chmod -R 777 /.cargo
- cd bin/
- echo "Making binary package..."
- sudo -u nobody makepkg -c
- sudo -u nobody makepkg --printsrcinfo > .SRCINFO
- cd ../git
- echo "Making git source package..."
- sudo -u nobody makepkg -c
- sudo -u nobody makepkg --printsrcinfo > .SRCINFO
- cd ..
# Set up SSH for publishing
- mkdir -p /root/.ssh
- cp ./aur.pub /root/.ssh/id_rsa.pub
- echo "$AUR_SSH_PRIVATE" > /root/.ssh/id_rsa
- echo "Host aur.archlinux.org" >> /root/.ssh/config
- echo " IdentityFile /root/.ssh/aur" >> /root/.ssh/config
- echo " User aur" >> /root/.ssh/config
- chmod 600 /root/.ssh/{id_rsa*,config}
- eval `ssh-agent -s`
- ssh-add /root/.ssh/id_rsa
- ssh-keyscan -H aur.archlinux.org >> /root/.ssh/known_hosts
- git config --global user.name "timvisee"
- git config --global user.email "tim@visee.me"
# Publish binary package: clone AUR repo, commit update and push
- git clone ssh://aur@aur.archlinux.org/ffsend.git aur-ffsend-bin
- cd aur-ffsend-bin
- cp ../bin/{PKGBUILD,.SRCINFO} ./
- git add PKGBUILD .SRCINFO
- git commit -m "Release v$VERSION"
- git push
- cd ..
# Publish git package: clone AUR repo, commit update and push
- git clone ssh://aur@aur.archlinux.org/ffsend-git.git aur-ffsend-git
- cd aur-ffsend-git
- cp ../git/{PKGBUILD,.SRCINFO} ./
- git add PKGBUILD .SRCINFO
- git commit -m "Release v$VERSION"
- git push
- cd ..
# TODO: add job to test ffsend{-git} AUR packages