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

Add workflow to generate API specs and clients with a manual trigger #75

Merged
merged 30 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
615612c
Add workflow to generate API specs and clients with a manual trigger
FelixTJDietrich Sep 2, 2024
9b5f64d
update api
FelixTJDietrich Sep 2, 2024
5c8be43
remove needs
FelixTJDietrich Sep 2, 2024
14d223a
fix workflow
FelixTJDietrich Sep 2, 2024
25bcea5
log event name
FelixTJDietrich Sep 2, 2024
30a69e0
generate api via label
FelixTJDietrich Sep 2, 2024
76b3c35
change label name
FelixTJDietrich Sep 2, 2024
17f5d7a
update workflow
FelixTJDietrich Sep 2, 2024
5ea5947
chore: update API client
github-actions[bot] Sep 2, 2024
bb14fbb
oops
FelixTJDietrich Sep 2, 2024
33d3e3d
update workflow
FelixTJDietrich Sep 2, 2024
ca86005
chore: update API client
github-actions[bot] Sep 2, 2024
a955290
update workflow to rerun checks
FelixTJDietrich Sep 3, 2024
b307295
must not start with GITHUB
FelixTJDietrich Sep 3, 2024
a740e74
small api change
FelixTJDietrich Sep 3, 2024
5b5c045
chore: update API client
github-actions[bot] Sep 3, 2024
1a3d577
update workflow
FelixTJDietrich Sep 3, 2024
189b17f
chore: update API client
github-actions[bot] Sep 3, 2024
001b809
remove label
FelixTJDietrich Sep 3, 2024
8d093a2
update workflow and client
FelixTJDietrich Sep 3, 2024
84b5334
chore: update API specs and client
github-actions[bot] Sep 3, 2024
808ce7f
fix workflow?
FelixTJDietrich Sep 3, 2024
a941332
chore: update API specs and client
github-actions[bot] Sep 3, 2024
36027b3
another one
FelixTJDietrich Sep 3, 2024
a176a1f
chore: update API specs and client
github-actions[bot] Sep 3, 2024
96a62ca
update workflow
FelixTJDietrich Sep 3, 2024
bba18f4
Merge branch 'FelixTJDietrich/issue72' of github.com:ls1intum/Hephaes…
FelixTJDietrich Sep 3, 2024
d1551e5
change api
FelixTJDietrich Sep 3, 2024
8d2958c
fix branch
FelixTJDietrich Sep 3, 2024
c5b6f48
chore: update API specs and client
github-actions[bot] Sep 3, 2024
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
33 changes: 27 additions & 6 deletions .github/workflows/generate-api-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,28 @@ name: OpenAPI

on:
pull_request:
types: [opened, synchronize, labeled, reopened]
paths:
- 'server/application-server/**'
- '.github/workflows/generate-api-client.yml'
push:
paths:
- 'server/application-server/openapi.yaml'
- 'webapp/src/app/core/modules/openapi/**'
branches: [develop]
workflow_dispatch:

concurrency:
group: generate-api-client
cancel-in-progress: true

jobs:
generate-api-client:
name: Verify API Specs and Client
name: Verify API Specs and Client (add autocommit-openapi label to PR to auto-commit changes)
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
fetch-depth: 0

- name: Set up Node.js
Expand Down Expand Up @@ -56,4 +55,26 @@ jobs:
echo "Changes detected in the API client directory."
echo "NO_CHANGES_DETECTED=false" >> $GITHUB_ENV
exit 1
fi
fi

- name: Commit files
if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }}
run: |
echo "Committing and pushing changes..."
git config --local user.name "github-actions[bot]"
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git commit -a -m "chore: update API specs and client"

- name: Push changes
if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }}
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_PAT }}
branch: ${{ github.event.pull_request.head.ref }}

- name: Remove autocommit-openapi label
if: ${{ always() && contains(github.event.pull_request.labels.*.name, 'autocommit-openapi') }}
run: |
echo "Removing the autocommit-openapi label..."
curl --silent --fail-with-body -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels/autocommit-openapi
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"generate:api:clean": "rimraf webapp/src/app/core/modules/openapi",
"generate:api:application-server-specs": "cd server/application-server && mvn verify -DskipTests=true && node ../../scripts/clean-openapi-specs.js",
"generate:api:application-server-client": "npx openapi-generator-cli generate -i server/application-server/openapi.yaml -g typescript-angular -o webapp/src/app/core/modules/openapi --additional-properties fileNaming=kebab-case,withInterfaces=true --generate-alias-as-model",
"generate:api": "npm run generate:api:clean && npm run generate:api:application-server-client && npm run generate:api:application-server-specs"
"generate:api": "npm run generate:api:application-server-specs && npm run generate:api:clean && npm run generate:api:application-server-client"
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "2.13.5",
Expand Down
3 changes: 2 additions & 1 deletion server/application-server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ paths:
operationId: getAllHellos
responses:
"200":
description: A list of all Hello entities
description: A set of all Hello entities
content:
application/json:
schema:
uniqueItems: true
type: array
items:
$ref: "#/components/schemas/Hello"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.tum.in.www1.hephaestus.hello;

import java.util.List;
import java.util.Set;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -20,10 +21,10 @@ public HelloController(HelloService helloService) {
/**
* Retrieves all {@link Hello} entities.
*
* @return A list of all Hello entities
* @return A set of all Hello entities
*/
@GetMapping
public List<Hello> getAllHellos() {
public Set<Hello> getAllHellos() {
return helloService.getAllHellos();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.time.Instant;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -21,12 +23,12 @@ public HelloService(HelloRepository helloRepository) {
/**
* Retrieves all {@link Hello} entities from the repository.
*
* @return A list of all Hello entities
* @return A set of all Hello entities
*/
public List<Hello> getAllHellos() {
public Set<Hello> getAllHellos() {
var hellos = helloRepository.findAll();
logger.info("Getting Hellos: {}", hellos);
return helloRepository.findAll();
return helloRepository.findAll().stream().collect(Collectors.toSet());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/app/core/modules/openapi/api/hello.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ export class HelloService implements HelloServiceInterface {
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
*/
public getAllHellos(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<Array<Hello>>;
public getAllHellos(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<Array<Hello>>>;
public getAllHellos(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<Array<Hello>>>;
public getAllHellos(observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<Set<Hello>>;
public getAllHellos(observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<Set<Hello>>>;
public getAllHellos(observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<Set<Hello>>>;
public getAllHellos(observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {

let localVarHeaders = this.defaultHeaders;
Expand Down Expand Up @@ -204,7 +204,7 @@ export class HelloService implements HelloServiceInterface {
}

let localVarPath = `/hello`;
return this.httpClient.request<Array<Hello>>('get', `${this.configuration.basePath}${localVarPath}`,
return this.httpClient.request<Set<Hello>>('get', `${this.configuration.basePath}${localVarPath}`,
{
context: localVarHttpContext,
responseType: <any>responseType_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ export interface HelloServiceInterface {
* Retrieves all {@link Hello Hello} entities.
* Retrieves all {@link Hello Hello} entities.
*/
getAllHellos(extraHttpRequestParams?: any): Observable<Array<Hello>>;
getAllHellos(extraHttpRequestParams?: any): Observable<Set<Hello>>;

}