From 376596d9f2d2ade076d2cad647d480c7f66d7820 Mon Sep 17 00:00:00 2001 From: Aaron Perez Date: Tue, 11 Feb 2025 17:41:29 -0500 Subject: [PATCH] [DAPS-DEPS] Refactor workflow, add docker build, compile, and update edition --- .github/workflows/compile.yml | 33 ++++++++++++++++++++++++++++++++ .github/workflows/docker.yml | 23 ++++++++++++++++++++++ .github/workflows/push-image.yml | 4 ++-- Cargo.lock | 4 +++- Cargo.toml | 4 ++-- Dockerfile | 12 ++++++------ src/main.rs | 6 ++++-- 7 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/compile.yml create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/compile.yml b/.github/workflows/compile.yml new file mode 100644 index 0000000..f29e33f --- /dev/null +++ b/.github/workflows/compile.yml @@ -0,0 +1,33 @@ +name: Compile and Test +on: + pull_request: + branches: + - '**' + push: + branches: + - master + +jobs: + compile-and-test: + runs-on: ubuntu-20.04 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: 1.84.1 + + - uses: actions/cache@v4 # Add caching + with: + path: ~/.cargo/registry # Cache the Cargo registry + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Install OpenSSL development headers + run: sudo apt install -y libssl-dev + + - run: cargo build --verbose + - run: cargo test --verbose \ No newline at end of file diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..e6c2ccb --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,23 @@ +name: Docker Build and Test + +on: + push: + branches: + - master + pull_request: + branches: + - '**' + +jobs: + build-and-test: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + run: docker build --tag my-app:latest . diff --git a/.github/workflows/push-image.yml b/.github/workflows/push-image.yml index 770cb43..d9bad4c 100644 --- a/.github/workflows/push-image.yml +++ b/.github/workflows/push-image.yml @@ -8,11 +8,11 @@ jobs: name: Cache Image runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 2 - run: git checkout HEAD^ - - uses: whoan/docker-build-with-cache-action@v5 + - uses: whoan/docker-build-with-cache-action@v8 with: image_name: joshuasbrown/cpp-py-formatter image_tag: latest diff --git a/Cargo.lock b/Cargo.lock index 4fbdf4e..be3b13d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 4 + [[package]] name = "autocfg" version = "1.0.1" @@ -83,7 +85,7 @@ checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" [[package]] name = "cpp-py-format" -version = "0.3.2" +version = "0.3.3" dependencies = [ "clap", "glob", diff --git a/Cargo.toml b/Cargo.toml index 6479822..ec0664c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "cpp-py-format" -version = "0.3.2" +version = "0.3.3" authors = ["Andrew Gaspar ","Joshua Brown "] -edition = "2024" +edition = "2018" [dependencies] glob = "0.3.0" diff --git a/Dockerfile b/Dockerfile index c342e15..b557c4c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build the GitHub Action -FROM rust:1.42 as builder +FROM rust:1.84.1 AS builder WORKDIR /usr/src/myapp COPY Cargo.toml . COPY Cargo.lock . @@ -7,12 +7,12 @@ COPY src ./src RUN cargo install --path . # GitHub Action Image -FROM ubuntu:18.04 +FROM ubuntu:22.04 # Install our apt packages -RUN apt-get update -RUN apt-get upgrade -y -RUN apt-get install -y git -RUN apt-get install -y python3-pip +RUN apt update +RUN apt upgrade -y +RUN apt install -y git +RUN apt install -y python3-pip RUN python3 -m pip install --upgrade pip RUN python3 -m pip install black diff --git a/src/main.rs b/src/main.rs index cb850fd..59cd7a5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -388,7 +388,8 @@ FLAGS: .args(&["diff", "--exit-code"]) .output(); - let git_diff_str = String::from_utf8_lossy(&git_diff.stdout); + let git_diff_output = git_diff.unwrap(); + let git_diff_str = String::from_utf8_lossy(&git_diff_output.stdout); if git_diff_str.len() > 0 { if !matches.is_present("amend") { @@ -411,7 +412,7 @@ FLAGS: fn check(&self, _matches: &ArgMatches) -> Result<(), Box> { let payload: GitHubPushEvent = load_payload()?; - let branch = ref_to_branch(&payload.r#ref).ok_or("Invalid reference")?; + let branch = ref_to_branch(&payload.r#ref); self.clone(&payload.repository.full_name, branch, 1)?; self.format_all(); @@ -449,6 +450,7 @@ fn ref_to_branch(r#ref: &str) -> &str{ } else if r#ref.starts_with(tag_prefix) { &r#ref[tag_prefix.len()..] } else { + // Will error out if the ref is neither a branch or tag on clone r#ref } }