Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds CI & User Updater Setup #35

Merged
merged 11 commits into from
Dec 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[target.x86_64-pc-windows-msvc.pq]
rustc-link-search = ["C:\\Program Files\\PostgreSQL\\16\\lib"]
rustc-link-search = ["C:\\Program Files\\PostgreSQL\\14\\lib"]
rustc-link-lib = ["libpq"]
70 changes: 70 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: CI

on:
push:
branches:
- main
pull_request:

jobs:
lint-and-format:
name: Lint with clippy and check formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: clippy, rustfmt
override: true

- name: Check formatting
run: cargo fmt -- --check

- name: Clippy check
run: cargo clippy -p smithe_backend -p smithe_database -p smithe_lib -p startgg -- -D warnings
build:
needs: lint-and-format
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: macos-latest
target: x86_64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2


- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
target: ${{ matrix.target }}

- if: matrix.os == 'windows-latest'
name: Install PostgreSQL
uses: ikalnytskyi/action-setup-postgres@v4

- name: Build
run: cargo build --release --target ${{ matrix.target }}

- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: my-binary-${{ matrix.target }}
path: target/${{ matrix.target }}/release/my-binary
23 changes: 23 additions & 0 deletions .github/workflows/docker-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Docker Deployment

on:
push:
branches:
- main

jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Download artifact
uses: actions/download-artifact@v2
with:
name: my-binary-x86_64-unknown-linux-gnu

- name: Build Docker image
run: |
docker build -t pidgtm-user-updater:latest -f Dockerfile-UserUpdater .
echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
docker push pidgtm-user-updater:latest
73 changes: 43 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Dockerfile-UserUpdater
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM debian:buster-slim
COPY target/x86_64-unknown-linux-gnu/release/pidgtm /usr/local/bin/pidgtm
ENTRYPOINT ["pidgtm"]
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ SMITHE ?= target/release/smithe
# CARGO
.PHONY: improve
improve:
cargo clippy --all --all-targets --all-features -- -D warnings
cargo clippy --fix -p smithe_backend -p smithe_database -p smithe_lib -p startgg
cargo fmt --all

.PHONY: test
test:
cargo test --workspace -- --show-output 2>&1 | tee test.out
Expand All @@ -19,14 +19,18 @@ build:
# INSTALL
.PHONY: install
install:
install target/release/smithe $(INSTALL_DIR)/bin
install target/release/pidgtm $(INSTALL_DIR)/bin
cargo install --path .

# PIDGTM
.PHONY: pidgtm
pidgtm-map:
$(PIDGTM) map

.PHONY: pidgtm-user-updater
pidgtm-user-updater:
cargo build --release --bin pidgtm --target x86_64-unknown-linux-gnu
docker build -t pidgtm-user-updater -f Dockerfile-UserUpdater .

# BACKEND
.PHONY: build-backend
build-backend:
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ Smithereens is not yet available as a website, only as a command-line tool. With

Currently, the only way to get Smithereens on your computer is to build it from source. To do so, you need to have the Rust toolchain installed on your machine. To install it, follow instructions [here](https://www.rust-lang.org/tools/install).

> Note:
>> Aside from the Rust toolchain, you will also need:
>> - Postgres,
>> - Diesel, and
>> - Trunk.
>
>> Plus, you need the following Rust targets:
>> - wasm32-unknown-unknown, and
>> - x86_64-unknown-linux-gnu

After that, inside of Smithereens' repository root, run: `cargo build --release`. With that, you'll have Smithereens' binary (i.e., `smithe`) built under `target/release`. You can run it, like: `./target/release/smithe`. After that, feel free to move the binary to a more convenient place on your machine (i.e., perhaps to a place included in your `PATH`, so you can run it simply with `smithe`).

> Note: In the future, there will be releases for `smithe`, so this process will be better streamlined.
> Note: In the future, there will be releases for `smithe`, so this process will be better streamlined.
8 changes: 3 additions & 5 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use smithe_lib::{
player::{get_all_like, get_player, get_top_two_characters},
set::{
get_competitor_type, get_set_losses_by_dq, get_set_losses_without_dqs, get_set_wins_by_dq,
get_set_wins_without_dqs, get_winrate, get_sets_per_player_id,
get_set_wins_without_dqs, get_sets_per_player_id, get_winrate,
},
tournament::get_tournaments_from_requester_id,
};
Expand All @@ -31,9 +31,7 @@ pub enum Error {
impl<'r, 'o: 'r> Responder<'r, 'o> for Error {
fn respond_to(self, req: &Request<'_>) -> response::Result<'o> {
// todo: use open telemetry at this point
match self {
_ => Status::InternalServerError.respond_to(req),
}
Status::InternalServerError.respond_to(req)
}
}

Expand Down Expand Up @@ -149,7 +147,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

#[cfg(test)]
mod tests {
use rocket::{local::blocking::Client, http::Status};
use rocket::{http::Status, local::blocking::Client};

use super::rocket;

Expand Down
Loading
Loading