-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
c993f94
commit 59ff74e
Showing
11 changed files
with
1,955 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,9 @@ yarn-error.log | |
!.yarn/versions | ||
|
||
.env | ||
|
||
# Tests and coverage | ||
coverage/ | ||
test-results.xml | ||
.nyc_output | ||
report/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"reporterEnabled": "spec, mochawesome", | ||
"mochawesomeReporterOptions": { | ||
"reportDir": "report", | ||
"reportFilename": "test-results" | ||
} | ||
} |
Oops, something went wrong.