-
Notifications
You must be signed in to change notification settings - Fork 53
Setup GitHub Actions CI Pipeline and Test Automation #115
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
base: main
Are you sure you want to change the base?
Changes from all commits
8b8bc9a
fad75ce
bc7805a
9a2e51f
ef2b311
9ca722d
356c15b
5172a97
ae2cfa1
5a69514
799e448
b0ce076
7337ae5
eab77ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| name: LibraryMan-API CI Pipeline | ||
|
|
||
| # 1. Automated Triggers: Triggers on every push or PR to key branches | ||
| on: | ||
| push: | ||
| branches: [ "main", "Build", "Test", "Deploy", "CI" ] | ||
| pull_request: | ||
| branches: [ "main" ] | ||
|
|
||
| jobs: | ||
| pipeline: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| # 2. Setup Phase | ||
| - name: Checkout Repository Code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up JDK 17 | ||
| uses: actions/setup-java@v4 | ||
| with: | ||
| java-version: '17' | ||
| distribution: 'temurin' | ||
| cache: maven | ||
|
|
||
| # 3. Automation Phase | ||
| - name: Make Maven Wrapper Executable | ||
| run: chmod +x mvnw | ||
|
|
||
| - name: Build and Execute 111 Unit Tests | ||
| # This automates the build and test process within the pipeline | ||
| run: ./mvnw clean test | ||
|
|
||
| - name: Generate JaCoCo Coverage Report | ||
| # This generates the report for the "Accessible Reports" requirement | ||
| run: ./mvnw jacoco:report | ||
|
|
||
| # 4. Reporting Phase (Deliverables) | ||
| - name: Archive Test & Coverage Reports | ||
| if: always() # Ensures reports are uploaded even if tests fail | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: assignment-reports | ||
| path: | | ||
| target/surefire-reports/ | ||
| target/site/jacoco/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Fixes #1 | ||
|
|
||
| Modernize the CI pipeline to produce accessible test and coverage reports as downloadable artifacts. | ||
|
|
||
| ### Workflow (`build-test-lint-format.yml`) | ||
| - Upgrade `actions/checkout`, `actions/setup-java`, to **v4** | ||
| - Replace commented-out `actions/cache@v3` with `setup-java`'s built-in `cache: 'maven'` | ||
| - Switch from `mvn` to `./mvnw` for reproducible builds via the Maven wrapper | ||
| - Add `actions/upload-artifact@v4` (`if: always()`) to archive Surefire + JaCoCo reports | ||
|
|
||
| ### Build (`pom.xml`) | ||
| - Add `jacoco-maven-plugin` 0.8.12 with `prepare-agent` and `report` goals bound to the `test` phase | ||
|
|
||
| After this, every push/PR run will produce a downloadable `test-reports` artifact containing `target/surefire-reports/` and `target/site/jacoco/. | ||
|
Comment on lines
+11
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the PR description aligned with the actual build config. The description says JaCoCo Proposed wording fix- Add `jacoco-maven-plugin` 0.8.12 with `prepare-agent` and `report` goals bound to the `test` phase
+ Add `jacoco-maven-plugin` 0.8.11 with `prepare-agent` and `report` goals bound to the `test` phase
-After this, every push/PR run will produce a downloadable `test-reports` artifact containing `target/surefire-reports/` and `target/site/jacoco/.
+After this, every push/PR run will produce a downloadable `test-reports` artifact containing `target/surefire-reports/` and `target/site/jacoco/`.🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,9 +17,10 @@ | |
| * This controller provides endpoints for performing CRUD operations on books, | ||
| * including retrieving all books, getting a book by its ID, adding a new book, | ||
| * updating an existing book, and deleting a book. | ||
| * * Version: 1.1 | ||
| */ | ||
| @RestController | ||
| @RequestMapping("/api") | ||
| @RequestMapping("/api/v1/books") //Versioning API path -> provide more context | ||
|
Comment on lines
22
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify controller mappings and whether tests cover BookController URLs.
# Expected: either tests/docs updated for /api/v1/books, or compatibility for old book routes.
rg -n -C 3 '@RequestMapping|@GetMapping|@PostMapping|@PutMapping|@DeleteMapping' src/main src/test
rg -n -C 3 '/api/v1/books|/api/.*/book|BookController|MockMvc|WebTestClient' src/test README.mdRepository: ajaynegi45/LibraryMan-API Length of output: 26317 Address API versioning inconsistency and add test coverage for BookController endpoints. The 🤖 Prompt for AI Agents |
||
| public class BookController { | ||
|
|
||
| @Autowired | ||
|
|
@@ -80,7 +81,8 @@ public BookDto addBook(@Valid @RequestBody BookDto bookDto) { | |
|
|
||
| /** | ||
| * Updates an existing book in the library. | ||
| * | ||
| * This operation is restricted to LIBRARIAN and ADMIN roles. | ||
| * | ||
| * @param id the ID of the book to update. | ||
| * @param bookDtoDetails the {@link Book} object containing the updated book details. | ||
| * @return the updated {@link Book} object. | ||
|
|
@@ -93,13 +95,15 @@ public BookDto updateBook(@PathVariable int id, @Valid @RequestBody BookDto book | |
|
|
||
| /** | ||
| * Deletes a book from the library by its ID. | ||
| * Provides confirmation message upon successful deletion. | ||
| * | ||
| * @param id the ID of the book to delete. | ||
| */ | ||
| @DeleteMapping("delete-book/{id}") | ||
| @PreAuthorize("hasRole('LIBRARIAN') or hasRole('ADMIN')") | ||
| public void deleteBook(@PathVariable int id) { | ||
| public ResponseEntity<String> deleteBook(@PathVariable int id) { | ||
| bookService.deleteBook(id); | ||
| return ResponseEntity.ok("Book with ID " + id + " has been successfully deleted from the system."); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| spring.datasource.url=jdbc:h2:mem:testdb | ||
| spring.datasource.driverClassName=org.h2.Driver | ||
| spring.datasource.username=sa | ||
| spring.datasource.password= | ||
|
|
||
| spring.jpa.hibernate.ddl-auto=create-drop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ajaynegi45/LibraryMan-API
Length of output: 286
Move this workflow to
.github/workflows/.The file is currently at
.github/workloads/main.yml, but GitHub Actions only discovers workflows in the.github/workflows/directory. This workflow will not run in its current location.Proposed fix
🤖 Prompt for AI Agents