tmuxido/.drone.yml

91 lines
2.8 KiB
YAML

kind: pipeline
type: docker
name: ci
trigger:
event:
- push
- pull_request
steps:
- name: test
image: rust:latest
commands:
- cargo fmt --check
- cargo clippy -- -D warnings
- cargo test
- name: coverage
image: xd009642/tarpaulin
privileged: true
environment:
GITEA_TOKEN:
from_secret: gitea_token
commands:
- apt-get update -qq && apt-get install -y -qq jq curl
- cargo tarpaulin --out Json 2>/dev/null
- |
PCT=$(jq '(.covered / .coverable * 100) | floor' tarpaulin-report.json)
if [ "$PCT" -ge 80 ]; then COLOR="brightgreen"
elif [ "$PCT" -ge 60 ]; then COLOR="yellow"
else COLOR="red"; fi
curl -sf "https://img.shields.io/badge/coverage-${PCT}%25-${COLOR}.svg" -o coverage.svg
- |
curl -sf -X DELETE \
-H "Authorization: token $GITEA_TOKEN" \
"https://git.cincoeuzebio.com/api/packages/cinco/generic/badges/latest" || true
curl -fsSL -X PUT \
-H "Authorization: token $GITEA_TOKEN" \
-T coverage.svg \
"https://git.cincoeuzebio.com/api/packages/cinco/generic/badges/latest/coverage.svg"
---
kind: pipeline
type: docker
name: release
trigger:
event:
- tag
ref:
- refs/tags/[0-9]*
steps:
- name: build-x86_64
image: messense/rust-musl-cross:x86_64-musl
commands:
- cargo build --release --target x86_64-unknown-linux-musl
- cp target/x86_64-unknown-linux-musl/release/tmuxido tmuxido-x86_64-linux
- name: build-aarch64
image: messense/rust-musl-cross:aarch64-musl
commands:
- cargo build --release --target aarch64-unknown-linux-musl
- cp target/aarch64-unknown-linux-musl/release/tmuxido tmuxido-aarch64-linux
- name: publish
image: alpine
environment:
GITEA_TOKEN:
from_secret: gitea_token
commands:
- apk add --no-cache curl jq
- |
# Extract changelog entry for this tag (content between this and previous ## heading)
BODY=$(awk "/^## \[${DRONE_TAG}\]/{found=1; next} found && /^## \[/{exit} found{print}" CHANGELOG.md)
RELEASE_ID=$(curl -fsSL -X POST \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
"https://git.cincoeuzebio.com/api/v1/repos/cinco/Tmuxido/releases" \
-d "{\"tag_name\":\"$DRONE_TAG\",\"name\":\"$DRONE_TAG\",\"body\":$(echo "$BODY" | jq -Rs .)}" \
| jq -r .id)
for ASSET in tmuxido-x86_64-linux tmuxido-aarch64-linux; do
curl -fsSL -X POST \
-H "Authorization: token $GITEA_TOKEN" \
"https://git.cincoeuzebio.com/api/v1/repos/cinco/Tmuxido/releases/$RELEASE_ID/assets" \
-F "attachment=@$ASSET"
done
depends_on:
- build-x86_64
- build-aarch64