Skip to content

Commit

Permalink
ci: setup tests on pr (#2)
Browse files Browse the repository at this point in the history
* ci: setup tests on pr

* ci: add env for tests

* ci: fix invalid characters in artifacts

* ci: use clean branch name for reading artifacts

* ci: added json-summary to coverage reporters

* ci: set coverage thresholds
  • Loading branch information
DaniAkash authored Mar 26, 2024
1 parent f782286 commit ce2bad7
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org

root = true

[*]

indent_style = space
indent_size = 2

end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
63 changes: 63 additions & 0 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: "Test"
on:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
branch:
- ${{ github.head_ref }}
- "main"

permissions:
# Required to checkout the code
contents: read

steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
- name: "Install Node"
uses: actions/setup-node@v4
with:
node-version: "20.11.0"
- name: "Install Deps"
run: npm install
- name: "Test"
run: npx vitest --coverage.enabled true
env:
VITE_CLARIFAI_USER_ID: ${{ secrets.VITE_CLARIFAI_USER_ID }}
VITE_CLARIFAI_PAT: ${{ secrets.VITE_CLARIFAI_PAT }}
- name: Prepare Branch Name
id: prepare
run: |
echo "CLEAN_BRANCH=$(echo '${{ matrix.branch }}' | sed 's/[":<>|*?\r\n\\\/]/-/g')" >> $GITHUB_ENV
- name: "Upload Coverage"
uses: actions/upload-artifact@v4
with:
name: coverage-${{ env.CLEAN_BRANCH }}
path: coverage

report-coverage:
needs: test
runs-on: ubuntu-latest
steps:
- name: Prepare Branch Name
id: prepare
run: |
echo "CLEAN_BRANCH=$(echo '${{ github.head_ref }}' | sed 's/[":<>|*?\r\n\\\/]/-/g')" >> $GITHUB_ENV
- name: "Download Coverage Artifacts"
uses: actions/download-artifact@v4
with:
name: coverage-${{ env.CLEAN_BRANCH }}
path: coverage
- uses: actions/download-artifact@v4
with:
name: coverage-main
path: coverage-main
- name: "Report Coverage"
uses: davelosert/vitest-coverage-report-action@v2
with:
json-summary-compare-path: coverage-main/coverage-summary.json
6 changes: 6 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ export default defineConfig({
test: {
coverage: {
reporter: ["text", "json", "html", "clover", "json-summary"],
thresholds: {
lines: 60,
branches: 60,
functions: 60,
statements: 60,
},
},
},
});

0 comments on commit ce2bad7

Please sign in to comment.