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

feat: Reports #20

Merged
merged 44 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
474fc24
Refactor processing and fix caching and fix tests
sophialittlejohn Nov 20, 2024
c3ab9ad
Clean up processor and add tests and mocks
sophialittlejohn Nov 20, 2024
89cca6f
Clean up types
sophialittlejohn Nov 20, 2024
562e14c
Add cashflow report and tests
sophialittlejohn Nov 21, 2024
8625327
Remove defer and use querywith poolid
sophialittlejohn Nov 21, 2024
710571f
Refactor tests and add comments
sophialittlejohn Nov 21, 2024
0cc968f
Add query for metadata and utils around it
sophialittlejohn Nov 22, 2024
62a6fff
Add data for pool fee snapshots and use in cashflow statments
sophialittlejohn Nov 22, 2024
bd50461
Group tranche data by id to prevent double processing
sophialittlejohn Nov 22, 2024
efc2e37
fix zero case in fromFloat wrapper
sophialittlejohn Nov 22, 2024
2580226
Prevent fees and endCashBalance from being aggregated
sophialittlejohn Nov 23, 2024
3c4b0b6
Add fee snapshot mocks and improve fee testing
sophialittlejohn Nov 23, 2024
a059805
Add a few more fee test
sophialittlejohn Nov 23, 2024
a205c3d
Differentiate public and private credit for cashflows
sophialittlejohn Nov 25, 2024
c4b9997
Remove identifying info
sophialittlejohn Nov 25, 2024
d44e2d8
Fix data aggregation and improve test coverage with real data
sophialittlejohn Nov 25, 2024
fd88d5a
Add code coverage support
sophialittlejohn Nov 25, 2024
2396604
Add coverage summary
sophialittlejohn Nov 26, 2024
452816e
Exclude types from coverage
sophialittlejohn Nov 26, 2024
a44d576
And P&L report and processor tests
sophialittlejohn Nov 26, 2024
cc8926a
Add tests for applyGrouping
sophialittlejohn Nov 26, 2024
9f1c6b5
Add readme for reports
sophialittlejohn Nov 26, 2024
22ee830
Add test to applyGrouping
sophialittlejohn Nov 27, 2024
fabe96e
Fix test
sophialittlejohn Nov 27, 2024
df1c10d
Merge branch 'main' of github.com:centrifuge/centrifuge-sdk into reports
sophialittlejohn Nov 28, 2024
01879fd
Fix BigInt tests
sophialittlejohn Nov 29, 2024
97b6efc
Clean up metadata fetching
sophialittlejohn Nov 29, 2024
db48c58
Remove cache time
sophialittlejohn Nov 29, 2024
3c672d3
Remove filtering in keys
sophialittlejohn Nov 29, 2024
25fa8bf
Fix import so that decimal.js-light works in browser and test env
sophialittlejohn Nov 29, 2024
0a78c08
Update README.md
sophialittlejohn Dec 2, 2024
037fa20
Update README.md
sophialittlejohn Dec 2, 2024
35908e5
Merge branch 'main' of github.com:centrifuge/centrifuge-sdk into reports
sophialittlejohn Dec 2, 2024
d6ca3fe
Use purchases and financings instead of acquisistions
sophialittlejohn Dec 2, 2024
b380c98
Remove coverage in favor of nyc in ci PR
sophialittlejohn Dec 2, 2024
30bb9a4
Remove c8 config
sophialittlejohn Dec 2, 2024
1ce0bbc
Merge branch 'main' of github.com:centrifuge/centrifuge-sdk into reports
sophialittlejohn Dec 2, 2024
bd394c0
Restore sinon stub to fix error
sophialittlejohn Dec 2, 2024
bbe15a8
Add fix to P&L report
sophialittlejohn Dec 2, 2024
6a31f46
Provide access to P&L
sophialittlejohn Dec 2, 2024
47ae92c
fix test (#25)
onnovisser Dec 3, 2024
59aa18c
ci: Release and some fixes (#24)
gpmayorga Dec 3, 2024
20a9c55
chore:Bump version to 0.0.0-alpha.0
actions-user Dec 3, 2024
839a09a
Add check in case the new version is already pushed and no changes ha…
gpmayorga Dec 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
59 changes: 59 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# GitHub Workflows Overview

This repository contains several GitHub Actions workflows that automate various processes, including building, testing, versioning, and releasing your project. Below is an overview of each workflow and how they contribute to the release process.

## Workflows

### 1. `prepare-release.yml`

This workflow is responsible for versioning and preparing releases based on pull request labels.

- **Trigger**: Runs on pull request reviews that are approved.
- **Version Bump**: Determines the version bump type (major, minor, patch) based on PR labels. If an `alpha` label is present, it creates a prerelease version.
- **Versioning**: Uses `yarn version` to update the version in `package.json`.
- **Outputs**: Provides the version type and alpha status for subsequent workflows.

- **Alpha Versioning**: When a PR includes the `alpha` label, versions are created with an `-alpha.N` suffix (e.g., `1.2.3-alpha.1`, `1.2.3-alpha.2`). This continues until the alpha label is removed, at which point the version returns to standard semantic versioning.


### 2. `build-test-report.yml`

This workflow handles building, testing, and reporting.

- **Trigger**: Runs on pull requests and pushes to the `main` branch.
- **Build and Test**: Installs dependencies, builds the project, and runs tests.
- **Reporting**: Uploads test results and coverage reports to Codecov.

### 3. `naming-conventions.yml`

This workflow ensures that pull request titles and labels follow specific conventions.

- **Trigger**: Runs on various pull request events (opened, edited, labeled, etc.).
- **Title Check**: Validates PR titles against the Conventional Commits specification.
- **Label Check**: Ensures PRs have one of the required labels (major, minor, patch, no-release).
- **Comments**: Adds or removes comments on PRs based on title and label validation results.

### 4. `create-release.yml`

This workflow creates a draft release on GitHub when a new version is detected in `package.json` on the `main` branch.

- **Trigger**: Runs on pushes to the `main` branch.
- **Version Check**: Verifies if the version in `package.json` has been updated.
- **Draft Release**: Creates a draft release with the new version tag if the version check is successful.

### 5. `publish-release.yml`

This workflow handles the publishing of releases to NPM.

- **Trigger**: Runs when a release is published on GitHub.
- **Build and Publish**: Checks out the code, installs dependencies, builds the project, and publishes it to NPM.
- **Provenance**: Uses `npm publish` with provenance for security.

## Release Process

1. **Versioning**: The `prepare-release.yml` workflow determines the version bump based on PR labels after a review has been approved. If a PR is labeled with `major`, `minor`, or `patch`, the version is updated accordingly. If labeled with `alpha`, a prerelease version is created.

2. **Draft Release Creation**: The `create-release.yml` workflow creates a draft release if `package.json` contains a new version on the `main` branch.

3. **Publishing**: When a release is published on GitHub (moved from draft to released), the `publish-release.yml` workflow is triggered. It builds the project and publishes it to NPM, ensuring the package is available for public use.

16 changes: 16 additions & 0 deletions .github/ci-scripts/check-version-bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# Get the current version from package.json
current_version=$(node -p "require('./package.json').version")

# Get the previous version from the last commit
previous_version=$(git show HEAD~1:package.json | node -p "JSON.parse(require('fs').readFileSync(0, 'utf-8')).version")

# Compare the versions
if [ "$current_version" != "$previous_version" ]; then
echo "Version has been bumped from $previous_version to $current_version."
exit 0
else
echo "Version has not been bumped."
exit 1
fi
30 changes: 30 additions & 0 deletions .github/ci-scripts/toggle-alpha.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Read the current version from package.json
current_version=$(node -p "require('./package.json').version")

# Check if version contains alpha
if [[ "$current_version" == *"-alpha"* ]]; then
if [[ "$1" != "yes" ]]; then
# Remove alpha if present and "yes" is not passed
new_version="${current_version%%-alpha*}"
else
# Keep the current version if "yes" is passed
new_version="${current_version}"
fi
elif [[ "$1" == "yes" ]]; then
# Add alpha if not present and "yes" was passed
new_version="${current_version}-alpha"
else
# Keep current version if no alpha and no "yes" passed
new_version="${current_version}"
fi

# Update the package.json with the new version
node -e "
let pkg = require('./package.json');
pkg.version = '$new_version';
require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2));
"

echo "Updated version to $new_version"
3 changes: 3 additions & 0 deletions .github/workflows/build-test-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build-n-test:
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release and Versioning
on:
push:
branches:
- main

jobs:
create-release:
runs-on: ubuntu-latest
permissions:
contents: write # Highly security sensitive. Do NOT add third party actions in this job
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # Need at least 2 commits to compare versions

- name: Check if version was bumped
id: version_check
run: |
./.github/ci-scripts/check-version-bump.sh

- name: Create GitHub Release
if: success() && steps.version_check.outcome == 'success'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(node -p "require('./package.json').version")
gh release create "v${VERSION}" \
--title "Release v${VERSION}" \
--generate-notes \
--prerelease \
--draft
18 changes: 10 additions & 8 deletions .github/workflows/naming-conventions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- name: Check PR Title follows conventional commit naming
id: check-pr-naming
uses: amannn/action-semantic-pull-request@v5
continue-on-error: true
# continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
# https://www.conventionalcommits.org/en/v1.0.0/
ignoreLabels: |
skip-ci
requireScope: false
wip: true
validateSingleCommit: false

- uses: docker://agilepathway/pull-request-label-checker:v1.6.56
# continue-on-error: true
# https://github.com/agilepathway/label-checker
id: check-pr-labels
with:
one_of: major,minor,patch,no-release
one_of: major,minor,patch,no-release,alpha
repo_token: ${{ secrets.GITHUB_TOKEN }}

outputs:
Expand All @@ -34,6 +34,7 @@ jobs:

handle-comments:
runs-on: ubuntu-latest
if: always()
needs: title-n-label-check
permissions:
pull-requests: write
Expand All @@ -58,7 +59,7 @@ jobs:
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: PR must have at least one of the following labels
body-includes: PR must have ONLY one of the following labels

- name: Add PR naming error comment
id: pr-title-error
Expand Down Expand Up @@ -100,7 +101,8 @@ jobs:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-label-comment.outputs.comment-id }}
body: |
PR must have at least one of the following labels: major, minor, patch.
PR must have ONLY one of the following labels: major, minor, patch, no-release, alpha.
Check the logs for more details: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
edit-mode: replace
if: needs.title-n-label-check.outputs.labels_valid != 'success'

Expand Down
88 changes: 38 additions & 50 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
name: Release and Versioning
name: Package version bump
on:
pull_request_review:
types: [submitted]
pull_request:
types: [closed]
branches:
- main
paths:
- '.github/workflows/prepare-release.yml'

jobs:
get_version:
if: github.event.pull_request.merged == true
bump-version:
runs-on: ubuntu-latest
if: github.event.review.state == 'approved'
permissions:
contents: write # Highly security sensitive. Do NOT add third party actions in this job
pull-requests: read
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
fetch-depth: 0 # https://yarnpkg.com/features/release-workflow#caveat

- uses: actions/setup-node@v4
- name: Show current branch
run: |
echo "Current branch: $(git branch --show-current)"
echo "Current commit: $(git rev-parse HEAD)"
git log --oneline -5

- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af #@v4
with:
node-version: '20'

Expand All @@ -22,7 +35,7 @@ jobs:
- name: Set Yarn version
run: yarn set version 4.5.0

- name: Get version bump type from labels
- name: Check PR version labels
id: bump
run: |
# Check for version type labels
Expand All @@ -39,6 +52,7 @@ jobs:
# Check for alpha label
if ${{ contains(github.event.pull_request.labels.*.name, 'alpha') }}; then
echo "alpha=true" >> $GITHUB_OUTPUT
echo "type=prerelease" >> $GITHUB_OUTPUT
else
echo "alpha=false" >> $GITHUB_OUTPUT
fi
Expand All @@ -47,55 +61,29 @@ jobs:
id: cancel
if: steps.bump.outputs.type == 'no-release'
run: |
echo "No version bump required. Exiting successfully."
exit 0
continue-on-error: true
echo "::warning::No version bump required. Skipping release steps."

- name: Configure Git
if: steps.cancel.outcome == 'success'
run: |
git config --global user.name 'GitHub Action'
git config --global user.email '[email protected]'

- name: Bump version
if: steps.cancel.outcome == 'success'
- name: Toggle Alpha
if: steps.bump.outputs.type != 'no-release'
run: |
if [ "${{ steps.bump.outputs.alpha }}" == "true" ]; then
yarn version --${{ steps.bump.outputs.type }} --preid alpha
./.github/ci-scripts/toggle-alpha.sh yes
else
yarn version --${{ steps.bump.outputs.type }}
./.github/ci-scripts/toggle-alpha.sh #remove alpha if present
fi

- name: Bump version
if: steps.bump.outputs.type != 'no-release'
run: yarn version ${{ steps.bump.outputs.type }}

- name: Push changes
if: steps.cancel.outcome == 'success'
if: steps.bump.outputs.type != 'no-release'
run: |
VERSION=$(node -p "require('./package.json').version")
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git add package.json
git commit -am "chore:Bump version to ${VERSION}"
git push
git push --tags
outputs:
type: ${{ steps.bump.outputs.type }}
alpha: ${{ steps.bump.outputs.alpha }}

create-release:
needs: get_version
runs-on: ubuntu-latest
permissions:
contents: write
if: needs.get_version.outputs.type != 'no-release'
steps:
- uses: actions/checkout@v4
with:
ref: main

- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(node -p "require('./package.json').version")
if ${{ contains(github.event.pull_request.labels.*.name, 'alpha') }}; then
VERSION="${VERSION}-alpha"
fi
gh release create "v${VERSION}" \
--title "Release v${VERSION}" \
--generate-notes \
--prerelease \
--draft

7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ dist

# Yarn
yarn-error.log
.yarn
.yarn/*
!.yarn/releases
!.yarn/plugins
!.yarn/sdks
!.yarn/versions
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml

.env

# Tests and coverage
coverage/
test-results.xml
.nyc_output
report/
report/
10 changes: 10 additions & 0 deletions .mocharc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extension": [
"ts"
],
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
],
"spec": "src/**/*.test.ts"
}
Loading
Loading