Skip to content
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
328 changes: 164 additions & 164 deletions .github/workflows/golang-test.yaml
Original file line number Diff line number Diff line change
@@ -1,171 +1,171 @@
---
name: Golang CI
# ---
# name: Golang CI

on:
push:
branches: ["main"]
pull_request:
# on:
# push:
# branches: ["main"]
# pull_request:

jobs:
golang_format_check:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Check user-service formatting
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "The following files are not formatted:"
echo "$unformatted"
exit 1
fi
working-directory: ./user-service
- name: Check observability-service formatting
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "The following files are not formatted:"
echo "$unformatted"
exit 1
fi
working-directory: ./observability-service
# jobs:
# golang_format_check:
# runs-on: ubuntu-latest
# timeout-minutes: 5
# steps:
# - uses: actions/checkout@v4
# - name: Set up Go
# uses: actions/setup-go@v5
# with:
# go-version: '1.22'
# - name: Check user-service formatting
# run: |
# unformatted=$(gofmt -l .)
# if [ -n "$unformatted" ]; then
# echo "The following files are not formatted:"
# echo "$unformatted"
# exit 1
# fi
# working-directory: ./user-service
# - name: Check observability-service formatting
# run: |
# unformatted=$(gofmt -l .)
# if [ -n "$unformatted" ]; then
# echo "The following files are not formatted:"
# echo "$unformatted"
# exit 1
# fi
# working-directory: ./observability-service

golang_lint:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Lint user-service
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: ./user-service
args: --timeout=5m
- name: Lint observability-service
uses: golangci/golangci-lint-action@v6
with:
version: latest
working-directory: ./observability-service
args: --timeout=5m
# golang_lint:
# runs-on: ubuntu-latest
# timeout-minutes: 10
# steps:
# - uses: actions/checkout@v4
# - name: Set up Go
# uses: actions/setup-go@v5
# with:
# go-version: '1.22'
# - name: Lint user-service
# uses: golangci/golangci-lint-action@v6
# with:
# version: latest
# working-directory: ./user-service
# args: --timeout=5m
# - name: Lint observability-service
# uses: golangci/golangci-lint-action@v6
# with:
# version: latest
# working-directory: ./observability-service
# args: --timeout=5m

user_service_test:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: >-
${{ runner.os }}-go-${{
hashFiles('**/user-service/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Go mod tidy
run: go mod tidy
working-directory: ./user-service
- name: Run tests
run: go test -v ./...
working-directory: ./user-service
- name: Generate coverage report
run: go test -coverprofile=coverage.out ./...
working-directory: ./user-service
- name: Convert coverage to HTML
run: go tool cover -html=coverage.out -o coverage.html
working-directory: ./user-service
- name: Upload coverage reports
uses: actions/upload-artifact@v4
with:
name: coverage-reports-user-service
path: ./user-service/coverage.html
retention-days: 30
if: always()
# user_service_test:
# runs-on: ubuntu-latest
# timeout-minutes: 15
# steps:
# - uses: actions/checkout@v4
# - name: Set up Go
# uses: actions/setup-go@v5
# with:
# go-version: '1.22'
# - name: Cache Go modules
# uses: actions/cache@v3
# with:
# path: ~/go/pkg/mod
# key: >-
# ${{ runner.os }}-go-${{
# hashFiles('**/user-service/go.sum') }}
# restore-keys: |
# ${{ runner.os }}-go-
# - name: Go mod tidy
# run: go mod tidy
# working-directory: ./user-service
# - name: Run tests
# run: go test -v ./...
# working-directory: ./user-service
# - name: Generate coverage report
# run: go test -coverprofile=coverage.out ./...
# working-directory: ./user-service
# - name: Convert coverage to HTML
# run: go tool cover -html=coverage.out -o coverage.html
# working-directory: ./user-service
# - name: Upload coverage reports
# uses: actions/upload-artifact@v4
# with:
# name: coverage-reports-user-service
# path: ./user-service/coverage.html
# retention-days: 30
# if: always()

observability_service_test:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: >-
${{ runner.os }}-go-${{
hashFiles('**/observability-service/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Go mod tidy
run: go mod tidy
working-directory: ./observability-service
- name: Run tests
run: go test -v ./...
working-directory: ./observability-service
- name: Generate coverage report
run: go test -coverprofile=coverage.out ./...
working-directory: ./observability-service
- name: Convert coverage to HTML
run: go tool cover -html=coverage.out -o coverage.html
working-directory: ./observability-service
- name: Upload coverage reports
uses: actions/upload-artifact@v4
with:
name: coverage-reports-observability-service
path: ./observability-service/coverage.html
retention-days: 30
if: always()
# observability_service_test:
# runs-on: ubuntu-latest
# timeout-minutes: 15
# steps:
# - uses: actions/checkout@v4
# - name: Set up Go
# uses: actions/setup-go@v5
# with:
# go-version: '1.21'
# - name: Cache Go modules
# uses: actions/cache@v3
# with:
# path: ~/go/pkg/mod
# key: >-
# ${{ runner.os }}-go-${{
# hashFiles('**/observability-service/go.sum') }}
# restore-keys: |
# ${{ runner.os }}-go-
# - name: Go mod tidy
# run: go mod tidy
# working-directory: ./observability-service
# - name: Run tests
# run: go test -v ./...
# working-directory: ./observability-service
# - name: Generate coverage report
# run: go test -coverprofile=coverage.out ./...
# working-directory: ./observability-service
# - name: Convert coverage to HTML
# run: go tool cover -html=coverage.out -o coverage.html
# working-directory: ./observability-service
# - name: Upload coverage reports
# uses: actions/upload-artifact@v4
# with:
# name: coverage-reports-observability-service
# path: ./observability-service/coverage.html
# retention-days: 30
# if: always()

golang_coverage_summary:
runs-on: ubuntu-latest
needs: [user_service_test, observability_service_test]
if: >-
always() && (github.event_name == 'pull_request' ||
(github.event_name == 'push' &&
github.ref == 'refs/heads/main'))
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Download all coverage reports
uses: actions/download-artifact@v4
with:
path: golang-coverage-reports
- name: Generate coverage summary
run: |
summary="## Golang Code Coverage Summary"
echo "$summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Coverage reports generated for Golang microservices." \
>> $GITHUB_STEP_SUMMARY
echo "### Coverage Results" >> $GITHUB_STEP_SUMMARY
# golang_coverage_summary:
# runs-on: ubuntu-latest
# needs: [user_service_test, observability_service_test]
# if: >-
# always() && (github.event_name == 'pull_request' ||
# (github.event_name == 'push' &&
# github.ref == 'refs/heads/main'))
# steps:
# - name: Checkout sources
# uses: actions/checkout@v4
# - name: Download all coverage reports
# uses: actions/download-artifact@v4
# with:
# path: golang-coverage-reports
# - name: Generate coverage summary
# run: |
# summary="## Golang Code Coverage Summary"
# echo "$summary" >> $GITHUB_STEP_SUMMARY
# echo "" >> $GITHUB_STEP_SUMMARY
# echo "Coverage reports generated for Golang microservices." \
# >> $GITHUB_STEP_SUMMARY
# echo "### Coverage Results" >> $GITHUB_STEP_SUMMARY

for report_file in golang-coverage-reports/*/*.html; do
if [ -f "$report_file" ]; then
service_name=$(basename "$(dirname "$report_file")" | \
sed 's/coverage-reports-//')
# Extract coverage percentage from HTML (basic extraction)
coverage=$(grep -o '[0-9]\+\.[0-9]\+%' "$report_file" | \
head -1)
if [ -z "$coverage" ]; then
coverage="No coverage data"
fi
echo "- $service_name: $coverage" >> $GITHUB_STEP_SUMMARY
fi
done
# for report_file in golang-coverage-reports/*/*.html; do
# if [ -f "$report_file" ]; then
# service_name=$(basename "$(dirname "$report_file")" | \
# sed 's/coverage-reports-//')
# # Extract coverage percentage from HTML (basic extraction)
# coverage=$(grep -o '[0-9]\+\.[0-9]\+%' "$report_file" | \
# head -1)
# if [ -z "$coverage" ]; then
# coverage="No coverage data"
# fi
# echo "- $service_name: $coverage" >> $GITHUB_STEP_SUMMARY
# fi
# done
1 change: 1 addition & 0 deletions .github/workflows/push-to-acr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Build and Push to ACR
"on":
push:
branches: [main]

jobs:
changes:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,39 @@
@Service
public class ApiService {

@Value("${vite.backend.url}")
private String backendUrl;

private final RestClient restClient;

public ApiService(RestClient.Builder restClientBuilder) {
public ApiService(
RestClient.Builder restClientBuilder,
@Value("${vite.backend.url}") String backendUrl
) {
this.restClient = restClientBuilder
.baseUrl(backendUrl)
.build();
}

public List<String> getListOfProjectIds() {
return restClient.get()
.uri("api/v1/projects/ListID")
.uri("/api/v1/projects/listID")
.retrieve()
.body(new ParameterizedTypeReference<List<String>>() {});
}

// GET request that returns a single JSON object
public UsageMonth usageRecordForLastMonth(String id, int days) {
return restClient.get()
.uri("api/v1/systems/projects/{id}/{days}", id, days)
return usageRecordForLastMonth(id, days, null);
}

public UsageMonth usageRecordForLastMonth(String id, int days, String authHeader) {
RestClient.RequestHeadersSpec<?> request = restClient.get()
.uri("/api/v1/systems/projects/{id}/usage/{days}", id, days);

if (authHeader != null && !authHeader.isBlank()) {
request = request.header("Authorization", authHeader);
}

return request
.retrieve()
.body(UsageMonth.class);
}
}
}
Loading
Loading