Add CI #3

Merged
asonix merged 2 commits from asonix/add-ci into kumu 2022-01-03 01:50:57 +00:00
3 changed files with 422 additions and 85 deletions

421
.drone.yml Normal file
View file

@ -0,0 +1,421 @@
kind: pipeline
type: docker
name: clippy
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: clippy
image: asonix/rust-builder:latest-linux-amd64
pull: always
commands:
- rustup component add clippy
- cargo clippy -- -D warnings
trigger:
event:
- push
- pull_request
- tag
---
kind: pipeline
type: docker
name: tests
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: tests
image: asonix/rust-builder:latest-linux-amd64
pull: always
commands:
- cargo test
trigger:
event:
- push
- pull_request
- tag
---
kind: pipeline
type: docker
name: check-amd64
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: check
image: asonix/rust-builder:latest-linux-amd64
pull: always
commands:
- cargo check --target=$TARGET
trigger:
event:
- push
- pull_request
---
kind: pipeline
type: docker
name: build-amd64
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: build
image: asonix/rust-builder:latest-linux-amd64
pull: always
commands:
- cargo build --target=$TARGET --release
- $TOOL-strip target/$TARGET/release/pict-rs-proxy
- cp target/$TARGET/release/pict-rs-proxy .
- cp pict-rs-proxy pict-rs-proxy-linux-amd64
# - name: push
# image: plugins/docker:20
# settings:
# username: asonix
# password:
# from_secret: dockerhub_token
# repo: asonix/chess-server
# dockerfile: docker/drone/Dockerfile
# auto_tag: true
# auto_tag_suffix: linux-amd64
# build_args:
# - REPO_ARCH=amd64
- name: publish
image: plugins/gitea-release:1
settings:
api_key:
from_secret: gitea_token
base_url: https://git.asonix.dog
files:
- pict-rs-proxy-linux-amd64
depends_on:
- clippy
- tests
trigger:
event:
- tag
---
kind: pipeline
type: docker
name: check-arm64v8
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: check
image: asonix/rust-builder:latest-linux-arm64v8
pull: always
commands:
- cargo check --target=$TARGET
trigger:
event:
- push
- pull_request
---
kind: pipeline
type: docker
name: build-arm64v8
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: build
image: asonix/rust-builder:latest-linux-arm64v8
pull: always
commands:
- cargo build --target=$TARGET --release
- $TOOL-strip target/$TARGET/release/pict-rs-proxy
- cp target/$TARGET/release/pict-rs-proxy .
- cp pict-rs-proxy pict-rs-proxy-linux-arm64v8
# - name: push
# image: plugins/docker:20
# settings:
# username: asonix
# password:
# from_secret: dockerhub_token
# repo: asonix/chess-server
# dockerfile: docker/drone/Dockerfile
# auto_tag: true
# auto_tag_suffix: linux-arm64v8
# build_args:
# - REPO_ARCH=arm64v8
- name: publish
image: plugins/gitea-release:1
settings:
api_key:
from_secret: gitea_token
base_url: https://git.asonix.dog
files:
- pict-rs-proxy-linux-arm64v8
depends_on:
- clippy
- tests
trigger:
event:
- tag
---
kind: pipeline
type: docker
name: check-arm32v7
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: check
image: asonix/rust-builder:latest-linux-arm32v7
pull: always
commands:
- cargo check --target=$TARGET
trigger:
event:
- push
- pull_request
---
kind: pipeline
type: docker
name: build-arm32v7
platform:
arch: amd64
clone:
disable: true
steps:
- name: clone
image: alpine/git:latest
user: root
commands:
- git clone $DRONE_GIT_HTTP_URL .
- git checkout $DRONE_COMMIT
- chown -R 991:991 .
- name: build
image: asonix/rust-builder:latest-linux-arm32v7
pull: always
commands:
- cargo build --target=$TARGET --release
- $TOOL-strip target/$TARGET/release/pict-rs-proxy
- cp target/$TARGET/release/pict-rs-proxy .
- cp pict-rs-proxy pict-rs-proxy-linux-arm32v7
# - name: push
# image: plugins/docker:20
# settings:
# username: asonix
# password:
# from_secret: dockerhub_token
# repo: asonix/chess-server
# dockerfile: docker/drone/Dockerfile
# auto_tag: true
# auto_tag_suffix: linux-arm32v7
# build_args:
# - REPO_ARCH=arm32v7
- name: publish
image: plugins/gitea-release:1
settings:
api_key:
from_secret: gitea_token
base_url: https://git.asonix.dog
files:
- pict-rs-proxy-linux-arm32v7
depends_on:
- clippy
- tests
trigger:
event:
- tag
# ---
#
# kind: pipeline
# type: docker
# name: manifest
#
# platform:
# arch: amd64
#
# clone:
# disable: true
#
# steps:
# - name: clone
# image: alpine/git:latest
# user: root
# commands:
# - git clone $DRONE_GIT_HTTP_URL .
# - git checkout $DRONE_COMMIT
# - chown -R 991:991 .
#
# - name: manifest
# image: plugins/manifest:1
# settings:
# username: asonix
# password:
# from_secret: dockerhub_token
# dump: true
# auto_tag: true
# ignore_missing: true
# spec: docker/drone/manifest.tmpl
#
#
# depends_on:
# - build-amd64
# - build-arm64v8
# - build-arm32v7
#
# trigger:
# event:
# - tag
#
# ---
#
# kind: pipeline
# type: docker
# name: publish-crate
#
# platform:
# arch: amd64
#
# clone:
# disable: true
#
# steps:
# - name: clone
# image: alpine/git:latest
# user: root
# commands:
# - git clone $DRONE_GIT_HTTP_URL .
# - git checkout $DRONE_COMMIT
# - chown -R 991:991 .
#
# - name: publish
# image: asonix/rust-builder:latest-linux-amd64
# pull: always
# environment:
# CRATES_IO_TOKEN:
# from_secret: crates_io_token
# commands:
# - cargo publish --token $CRATES_IO_TOKEN
#
# depends_on:
# - build-amd64
# - build-arm64v8
# - build-arm32v7
#
# trigger:
# event:
# - tag

View file

@ -138,55 +138,9 @@ impl Color {
Self::Black => Self::White,
}
}
pub(crate) fn is_white(&self) -> bool {
matches!(self, Self::White)
}
pub(crate) fn is_black(&self) -> bool {
matches!(self, Self::Black)
}
}
impl Rank {
pub(crate) fn next(&self) -> Option<Self> {
match self {
Self::One => Some(Self::Two),
Self::Two => Some(Self::Three),
Self::Three => Some(Self::Four),
Self::Four => Some(Self::Five),
Self::Five => Some(Self::Six),
Self::Six => Some(Self::Seven),
Self::Seven => Some(Self::Eight),
Self::Eight => None,
}
}
pub(crate) fn prev(&self) -> Option<Self> {
match self {
Self::One => None,
Self::Two => Some(Self::One),
Self::Three => Some(Self::Two),
Self::Four => Some(Self::Three),
Self::Five => Some(Self::Four),
Self::Six => Some(Self::Five),
Self::Seven => Some(Self::Six),
Self::Eight => Some(Self::Seven),
}
}
pub(crate) fn diff(&self, other: &Self) -> Option<u8> {
if self > other {
Some(self.to_number() - other.to_number())
} else {
None
}
}
pub(crate) fn absolute_diff(&self, other: &Self) -> u8 {
self.diff(other).or_else(|| other.diff(self)).unwrap_or(0)
}
pub(crate) fn to_number(&self) -> u8 {
match self {
Self::One => 0,
@ -216,44 +170,6 @@ impl Rank {
}
impl File {
pub(crate) fn next(&self) -> Option<Self> {
match self {
Self::A => Some(Self::B),
Self::B => Some(Self::C),
Self::C => Some(Self::D),
Self::D => Some(Self::E),
Self::E => Some(Self::F),
Self::F => Some(Self::G),
Self::G => Some(Self::H),
Self::H => None,
}
}
pub(crate) fn prev(&self) -> Option<Self> {
match self {
Self::A => None,
Self::B => Some(Self::A),
Self::C => Some(Self::B),
Self::D => Some(Self::C),
Self::E => Some(Self::D),
Self::F => Some(Self::E),
Self::G => Some(Self::F),
Self::H => Some(Self::G),
}
}
pub(crate) fn diff(&self, other: &Self) -> Option<u8> {
if self > other {
Some(self.to_number() - other.to_number())
} else {
None
}
}
pub(crate) fn absolute_diff(&self, other: &Self) -> u8 {
self.diff(other).or_else(|| other.diff(self)).unwrap_or(0)
}
pub(crate) fn to_number(&self) -> u8 {
match self {
Self::A => 0,

View file

@ -60,7 +60,7 @@ impl Drop for GameDropper {
}
}
async fn start(Json(start): Json<Start>, game_state: Data<GameState>) -> HttpResponse {
async fn start(Json(_start): Json<Start>, game_state: Data<GameState>) -> HttpResponse {
let game_id = GameId::new();
let game_dropper = GameDropper((**game_state).clone(), game_id.clone());