Skip to content

Commit

Permalink
ci: pipeline bootstrap (#22)
Browse files Browse the repository at this point in the history
* Add test and build action

* Add checkout step

* Move into workflows

* Refactor

* Add corepack for yarn v4.5.0

* Fix secrets and remove failing test temp

* Fix secrets

* Run in debug mode for reruns and add pr naming conventions

* Add workflow for versioning and publish to npm on closed PRs if they follow naming convention

* Add none option

* Remove comment

* First version of the CICD for SDK. Replaces #21

* add secrets

* Fix permissions and release creation

* fix permisions to comment on PRs

* change trigger to test

* try to fix the naming convention job

* Simplify deleting comments

* More fine grain control of PR comments

* bash fixes to PR comments

* More secure naming convention job

* debug title and label checks

* possibly latest with everything fixed for conventions

* Add reports to CI tests

* Add test coverage reports

* commit yarn.lock

* add badges to README

* review the release prep process

* better reporting test tooling

* fix naming conventions and tag detection

---------

Co-authored-by: sophian <[email protected]>
  • Loading branch information
gpmayorga and sophialittlejohn authored Dec 2, 2024
1 parent c993f94 commit 59ff74e
Show file tree
Hide file tree
Showing 11 changed files with 1,955 additions and 179 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/build-test-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Build, Test, and Report
name: Build, Test, and Report

on:
pull_request:
branches:
- main

jobs:
build-n-test:
permissions:
id-token: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

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

- name: Enable Corepack
run: corepack enable

- name: Set Yarn version
run: yarn set version 4.5.0

- name: Install dependencies
run: yarn install --immutable

- name: Run Build
run: yarn build

- name: Run tests
run: |
yarn test:ci
yarn test:coverage
env:
TENDERLY_ACCESS_KEY: ${{ secrets.TENDERLY_ACCESS_KEY }}
PROJECT_SLUG: ${{ secrets.PROJECT_SLUG }}
ACCOUNT_SLUG: ${{ secrets.ACCOUNT_SLUG }}
DEBUG: ${{ github.run_attempt > 1 }}

- name: Upload test results
if: success() || failure()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
report/
retention-days: 15

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
directory: ./coverage
token: ${{ secrets.CODECOV_TOKEN }}
# flags: unittests
name: sdk-coverage-with-nyc
fail_ci_if_error: true
116 changes: 116 additions & 0 deletions .github/workflows/naming-conventions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: PR Title and Label Check
on:
pull_request:
types: [opened, reopened, edited, labeled, unlabeled, synchronize]
jobs:
title-n-label-check:
runs-on: ubuntu-latest
permissions:
contents: 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
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
# https://github.com/agilepathway/label-checker
id: check-pr-labels
with:
one_of: major,minor,patch,no-release
repo_token: ${{ secrets.GITHUB_TOKEN }}

outputs:
labels_valid: ${{ steps.check-pr-labels.outputs.label_check }} # 'success' or 'failure'
title_error: ${{ steps.check-pr-naming.outputs.error_message }} # null or error message


handle-comments:
runs-on: ubuntu-latest
needs: title-n-label-check
permissions:
pull-requests: write
contents: read
steps:
- name: Debug outputs from title-n-label-check
run: |
echo "Title Error: ${{ needs.title-n-label-check.outputs.title_error }}"
echo "Labels Valid: ${{ needs.title-n-label-check.outputs.labels_valid }}"
- name: Find existing PR title error comment
uses: peter-evans/find-comment@v2
id: find-title-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: We require pull request titles to follow

- name: Find existing PR label error comment
uses: peter-evans/find-comment@v2
id: find-label-comment
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

- name: Add PR naming error comment
id: pr-title-error
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find-title-comment.outputs.comment-id }}
body: |
Hey there and thank you for opening this pull request! 👋🏼
We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.
Details:
```
${{ needs.title-n-label-check.outputs.title_error }}
edit-mode: replace
if: needs.title-n-label-check.outputs.title_error != null

- name: Remove title error comment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_ID: ${{ steps.find-title-comment.outputs.comment-id }}
run: |
curl -X DELETE \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/comments/$COMMENT_ID
if: needs.title-n-label-check.outputs.title_error == null

- name: Add PR label error comment
id: pr-label-error
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
repository: ${{ github.repository }}
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.
edit-mode: replace
if: needs.title-n-label-check.outputs.labels_valid != 'success'

- name: Remove label error comment
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMMENT_ID: ${{ steps.find-label-comment.outputs.comment-id }}
run: |
curl -X DELETE \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/comments/$COMMENT_ID
if: needs.title-n-label-check.outputs.labels_valid == 'success'
101 changes: 101 additions & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Release and Versioning
on:
pull_request:
types: [closed]
branches:
- main

jobs:
get_version:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

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

- name: Enable Corepack
run: corepack enable

- name: Set Yarn version
run: yarn set version 4.5.0

- name: Get version bump type from labels
id: bump
run: |
# Check for version type labels
if ${{ contains(github.event.pull_request.labels.*.name, 'major') }}; then
echo "type=major" >> $GITHUB_OUTPUT
elif ${{ contains(github.event.pull_request.labels.*.name, 'minor') }}; then
echo "type=minor" >> $GITHUB_OUTPUT
elif ${{ contains(github.event.pull_request.labels.*.name, 'patch') }}; then
echo "type=patch" >> $GITHUB_OUTPUT
else
echo "type=no-release" >> $GITHUB_OUTPUT
fi
# Check for alpha label
if ${{ contains(github.event.pull_request.labels.*.name, 'alpha') }}; then
echo "alpha=true" >> $GITHUB_OUTPUT
else
echo "alpha=false" >> $GITHUB_OUTPUT
fi
- name: Exit if no version bump
id: cancel
if: steps.bump.outputs.type == 'no-release'
run: |
echo "No version bump required. Exiting successfully."
exit 0
continue-on-error: true

- 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'
run: |
if [ "${{ steps.bump.outputs.alpha }}" == "true" ]; then
yarn version --${{ steps.bump.outputs.type }} --preid alpha
else
yarn version --${{ steps.bump.outputs.type }}
fi
- name: Push changes
if: steps.cancel.outcome == 'success'
run: |
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
41 changes: 41 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: NPM publish
on:
release:
types: [released]

jobs:
publish:
runs-on: ubuntu-latest
# environment: release
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
ref: main

- uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'

- name: Enable Corepack
run: corepack enable

- name: Set Yarn version
run: yarn set version 4.5.0

- name: Install dependencies
run: yarn install --immutable

- name: Build
run: yarn build

- name: Publish to NPM
run: npm publish --provenance --access public
# run: yarn npm publish --access public
# Note: At this time, yarn is not a supported tool for publishing your packages with provenance.
# https://docs.npmjs.com/generating-provenance-statements#using-third-party-package-publishing-tools
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ yarn-error.log
!.yarn/versions

.env

# Tests and coverage
coverage/
test-results.xml
.nyc_output
report/
7 changes: 7 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"reporter": ["text", "lcov"],
"extension": [".ts"],
"include": ["src/**/*.ts"],
"exclude": ["**/*.test.ts", "src/tests/**", "src/index.ts"],
"all": true
}
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[![Codecov](https://codecov.io/gh/centrifuge/sdk/graph/badge.svg?token=Q2yU8QfefP)](https://codecov.io/gh/centrifuge/sdk)
[![Build CI status](https://github.com/centrifuge/sdk/actions/workflows/build-test-report.yml/badge.svg)](https://github.com/centrifuge/sdk/actions/workflows/build-test-report.yml)
<!-- [![npm version](https://badge.fury.io/js/@centrifuge%2Fsdk.svg)](https://www.npmjs.com/package/@centrifuge/sdk) -->
[![Latest Release](https://img.shields.io/github/v/release/centrifuge/sdk?sort=semver)](https://github.com/centrifuge/sdk/releases/latest)


# Centrifuge JavaScript SDK

CentrifugeSDK provides a JavaScript client to interact with the Centrifuge ecosystem. It provides a comprehensive interface to easily create and manage pools, nfts, loans and metadata.
Expand Down Expand Up @@ -81,3 +87,36 @@ const subscription = pool.closeEpoch().subscribe(
() => console.log('complete')
)
```

## Developer Docs

### Dev server

```bash
yarn dev
```

### Build

```bash
yarn build
```

### Test

```bash
yarn test
yarn test:single <path-to-file>
yarn test:simple:single <path-to-file> # without setup file, faster and without tenderly setup
```

### PR Naming Convention for Semantic Versioning

PR naming convention is used to determine the semantic version bump of the package. It is enforced by a GitHub action in each pull request.

Version bumps:

- `major: breaking changes`
- `minor: new features`
- `patch: bug fixes`
- `none: no version bump, no publish`
7 changes: 7 additions & 0 deletions mocha-reporter-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"reporterEnabled": "spec, mochawesome",
"mochawesomeReporterOptions": {
"reportDir": "report",
"reportFilename": "test-results"
}
}
Loading

0 comments on commit 59ff74e

Please sign in to comment.