Skip to content

Commit

Permalink
11 configure cicd (#13)
Browse files Browse the repository at this point in the history
* add frontend

* update dev. paths for frontend + Update README

* migrate to astro

* Create rust.yml

* clippy

* add gen-openapi script

* Create docker-image.yml

* Update rust.yml

* Update rust.yml

* update Cargo

* fix swagger-ui

* Update rust.yml

* Update rust.yml

* Update API schema

* separate gen from CI

* Update gen-openapi.yml

* Update gen-openapi.yml

* Update gen-openapi.yml

* Create api.yml

* Update gen-openapi.yml

* continue on error

* continue on error

* rebase + restucture

* Update API schema

* fmt + clippy

* fix docker ci

* break down CI to diff jobs

* fix uses repo

* small fixes

* Autogenerate API

* add version tag

* fix docker ci

* change api-gen trigger

* fix docker build

* add changelog workflow

* post rebase fixes

* post rebase fixes

* fix gen_openapi

* check gen_openapi trigger

* Autogenerate API

* gen_openapi tweaking

* gen_openapi tweaking

* Autogenerate API

* gen_openapi tweaking

* gen_openapi tweaking

* gen_openapi tweaking

* fix genapi

* Autogenerate API

* clippy + FMT FIXES fixes

* Autogenerate API

* post rebase fix

* remove json schema

* gen-openapi moved to utils

* update test command

* rebase

* build fix

* build fix

* Autogenerate API

* test fix

* Update gen-openapi.yml

* Update gen-openapi.yml

* Test openAPI generation

* Update gen-openapi.yml

* Autogenerate API

* Update gen-openapi.yml

* Check OpenAPI gen

* Autogenerate API

* Update openapi.yaml

* Update openapi.yaml

* Autogenerate API

* post-review fixes

* fix checks

* fix typo

* Update .github/workflows/docker-image.yml

* Check openapi.yaml generation

* Autogenerate API

* add flags for release's dead code

* fix fmt

* small tweaks

* add frontend ci

* ci fixup

* add release build job

* minor fixes

* Update rust.yml
  • Loading branch information
archeoss committed Dec 20, 2023
1 parent f2f5af5 commit c2b74ef
Show file tree
Hide file tree
Showing 26 changed files with 1,345 additions and 64 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/changelog-updated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: "Changelog checker"
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
# Enforces the update of a changelog file on every pull request
changelog:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dangoslen/changelog-enforcer@v2
with:
changeLogPath: "CHANGELOG.md"
skipLabels: "Skip-Changelog"
25 changes: 25 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: build-docker

on:
push:
branches: [main]
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
build-docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Set Bob GUI version
run: echo "VERSION=$(cargo metadata --format-version=1 --no-deps | jq '.packages[0].version' --raw-output)" >> "$GITHUB_ENV"
- name: Build alpine image
uses: docker/build-push-action@v5
with:
context: .
file: dockerfiles/alpine/Dockerfile
tags: bob-management-gui:${{ env.VERSION }}
build-args: |
GIT_HASH_VAR=${{ github.sha }}
BRANCH_TAG_VAR=${{ github.ref }}
71 changes: 71 additions & 0 deletions .github/workflows/frontend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: CI frontend

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
push:
branches: [main]

jobs:
build-frontend-with-yarn:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Run install
uses: borales/actions-yarn@v4
with:
cmd: install
dir: frontend
- name: Build frontend
uses: borales/actions-yarn@v4
with:
cmd: build
dir: frontend
lint-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Run install
uses: borales/actions-yarn@v4
with:
cmd: install
dir: frontend
- name: Lint frontend
uses: borales/actions-yarn@v4
with:
cmd: lint
dir: frontend
test-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
- name: Run install
uses: borales/actions-yarn@v4
with:
cmd: install
dir: frontend
- name: Install Playwright Browsers
uses: borales/actions-yarn@v4
with:
cmd: playwright install --with-deps
dir: frontend
- name: Run Playwright tests
uses: borales/actions-yarn@v4
with:
cmd: playwright test
dir: frontend
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: frontend/playwright-report/
retention-days: 30
29 changes: 29 additions & 0 deletions .github/workflows/gen-openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: update-api-schema

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
gen-openapi:
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.QOOLLO_BOT_APP_ID }}
private-key: ${{ secrets.QOOLLO_BOT_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
token: ${{ steps.app-token.outputs.token }}
- uses: actions-rs/cargo@v1
with:
command: run
args: -p utils --bin gen-openapi -- -f api/openapi.yaml
- name: "Update API schema"
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_user_name: "qoollo-bot[bot]"
commit_user_email: "151071968+qoollo-bot[bot]@users.noreply.github.com"
commit_message: "Autogenerate API"
54 changes: 54 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI backend

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]
push:
branches: [main]

env:
CARGO_TERM_COLOR: always

jobs:
build-backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo build-backend
build-backend-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo build-backend --profile=release-lto
build-frontend-with-cargo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo build-frontend
build-all:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo build
test-backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo test
fmt-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo fmt --all -- --check
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo clippy
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ Bob Management GUI changelog
- Initial project structure, backend only (#9)
- Initial project stricture, frontend (#10)
- Dockerfile and Docker-Compose to simplify deployment (#5)
- CI/CD configuration (#11)
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license-file = "./LICENSE"
edition = "2021"

[workspace]
members = [ "cli", "frontend", "backend" ]
members = [ "cli", "frontend", "backend", "utils" ]
default-members = [ "frontend", "backend"]
resolver = "2"

Expand Down
Empty file added api/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
openapi: 3.0.3
info:
title: bob-management
description: 'Bob Management GUI: Backend'
contact:
name: Romanov Simeon ArchArcheoss@proton.me
license:
name: ''
version: 0.0.0
paths:
/root:
get:
tags:
- crate
operationId: root
responses:
'200':
description: Hello Bob!
tags:
- name: bob
description: BOB management API
1 change: 1 addition & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ cli = { path = "../cli" }
[features]
default = [ "swagger" ]
swagger = [ "dep:utoipa", "dep:utoipa-swagger-ui" , "dep:utoipa-redoc", "dep:utoipa-rapidoc" ]
gen_api = [ "dep:utoipa" ]
1 change: 0 additions & 1 deletion backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub struct ApiDoc;
pub async fn root() -> &'static str {
"Hello Bob!"
}

/// Generate openapi documentation for the project
#[cfg(all(feature = "swagger", debug_assertions))]
pub fn openapi_doc() -> Router {
Expand Down
1 change: 1 addition & 0 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ fn init_tracer(_log_file: &Option<PathBuf>, trace_level: Level) {
subscriber.init();
}

#[allow(clippy::unwrap_used, clippy::expect_used)]
fn router(cors: CorsLayer) -> Router {
let mut frontend = env::current_exe().expect("Couldn't get current executable path.");
frontend.pop();
Expand Down
5 changes: 4 additions & 1 deletion backend/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use std::convert::Infallible;
use std::marker::PhantomData;
use std::ops::Deref;
use thiserror::Error;
use utoipa::openapi::PathItemType;
use utoipa::OpenApi;

#[cfg(all(feature = "swagger", debug_assertions))]
use utoipa::openapi::PathItemType;

#[derive(Clone, Debug, Error, PartialEq, Eq, PartialOrd, Ord)]
pub enum RouteError {
#[error("No route found in OpenAPI scheme")]
Expand Down Expand Up @@ -209,6 +211,7 @@ where
.attach_printable_lazy(|| format!("route: {route}"))
}

#[cfg(all(feature = "swagger", debug_assertions))]
fn try_convert_path_item_type_from_method(value: &Method) -> Result<PathItemType, RouteError> {
Ok(match *value {
Method::GET => PathItemType::Get,
Expand Down
1 change: 0 additions & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ mod config;
pub use clap::Parser;
pub use cli::Args;
pub use config::{Config, FromFile, LoggerConfig};

14 changes: 9 additions & 5 deletions dockerfiles/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ RUN echo "$(case "$BUILD_PROFILE" in\
(*) echo "$BUILD_PROFILE";;\
esac)" >> ./build_profile_dir

RUN mkdir -p backend/src frontend cli/src
RUN mkdir -p backend/src frontend cli/src utils/src
RUN mkdir target
COPY Cargo.toml Cargo.toml
COPY cli/Cargo.toml cli/Cargo.toml
COPY backend/Cargo.toml backend/Cargo.toml
COPY utils/Cargo.toml utils/Cargo.toml
COPY frontend/Cargo.toml frontend/Cargo.toml
COPY .cargo .cargo
RUN echo "fn main() {println!(\"if you see this, the build broke\")}" > backend/src/lib.rs \
RUN echo "// if you see this, the build broke" > backend/src/lib.rs \
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > backend/src/main.rs \
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > frontend/build.rs \
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > cli/src/lib.rs \
&& echo "fn main() {println!(\"if you see this, the build broke\")}" > build.rs \
&& echo "// if you see this, the build broke" > cli/src/lib.rs \
&& cargo build-backend --profile=$BUILD_PROFILE --target=$BUILD_TARGET

COPY . ./
Expand All @@ -50,7 +50,11 @@ FROM node:20.6 as frontend

COPY ./frontend ./frontend

RUN cd frontend && yarn && yarn build && mkdir /build_output && cp -r ./frontend /build_output/frontend
RUN cd frontend \
&& yarn \
&& yarn build \
&& mkdir /build_output \
&& cp -r ./frontend /build_output/frontend

FROM alpine:3.18
ARG APP=/home/bob-management
Expand Down
4 changes: 4 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ pnpm-debug.log*

# macOS-specific files
.DS_Store
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
16 changes: 9 additions & 7 deletions frontend/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ fn shell(command: impl AsRef<OsStr> + Display) {
.arg(SHELL_ARG)
.arg(&command)
.output()
.expect(format!("Failed to run {cmd}", cmd = command).as_str());
.unwrap_or_else(|_| panic!("Failed to run {cmd}", cmd = command));

// println!("build.rs => {:?}", output.stdout);
let mut file = File::create("build.log").expect("Couldn't create log file...");
file.write(b"build log\n\n\n\nSTDOUT:\n")
let mut file = File::create("build.log").expect("Couldn't create file...");
file.write_all(b"build log\n\n\n\nSTDOUT:\n")
.expect("Couldn't write to build log");
file.write_all(&output.stdout)
.expect("Couldn't write to build log");
file.write(b"\n\n\n\nSTDERR:\n")
file.write_all(b"\n\n\n\nSTDERR:\n")
.expect("Couldn't write to build log");
file.write_all(&output.stderr)
.expect("Couldn't write to build log");
Expand Down Expand Up @@ -89,11 +89,13 @@ pub fn move_frontend() {
.append(true)
.open("build.log")
.expect("Couldn't open log file...");
file.write(format!("PROJECT DIR: {project_dir:?}\n").as_bytes())
file.write_all(format!("PROJECT DIR: {project_dir:?}\n").as_bytes())
.expect("Couldn't write to build log");

file.write(format!("Moving /{FRONTEND_DIR} from {project_dir:?} to: {target:?}\n").as_bytes())
.expect("Couldn't write to build log");
file.write_all(
format!("Moving /{FRONTEND_DIR} from {project_dir:?} to: {target:?}\n").as_bytes(),
)
.expect("Couldn't write to build log");

copy_dir_all(project_dir, target).expect("Couldn't move frontend build artifacts");
}
Expand Down
18 changes: 18 additions & 0 deletions frontend/e2e/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { test, expect } from '@playwright/test';

test('has title', async ({ page }) => {
await page.goto('https://playwright.dev/');

// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);
});

test('get started link', async ({ page }) => {
await page.goto('https://playwright.dev/');

// Click the get started link.
await page.getByRole('link', { name: 'Get started' }).click();

// Expects page to have a heading with the name of Installation.
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
});
1 change: 1 addition & 0 deletions frontend/frontend.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit c2b74ef

Please sign in to comment.