Skip to content

Test Converters

Test Converters #214

name: frameworkTesting
run-name: Test Converters
on:
push:
branches:
- main
paths:
- "src/**"
- "package.json"
pull_request:
branches:
- main
paths:
- "src/**"
- "package.json"
jobs:
run-tests:
name: Run Tests
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '20'
- run: npm install
- run: npm run test
env:
E2G_CACHE_FOLDER: 'tmp/e2g-cache'
- name: Convert code coverage results for summary
uses: irongut/[email protected]
with:
filename: coverage/*.xml
badge: true
format: 'markdown'
output: 'file'
# Source: https://stackoverflow.com/a/70655285
- name: Read coverage report to variable
if: github.event_name == 'pull_request'
id: read_md
run: |
echo 'COV_MD<<EOF' >> $GITHUB_OUTPUT
echo "$(cat code-coverage-results.md)" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Add code coverage PR comment
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${{ steps.read_md.outputs.COV_MD }}`
})
- name: Write to job summary
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
- name: Convert code coverage results for badge
uses: irongut/[email protected]
if: github.event_name != 'pull_request'
with:
filename: coverage/*.xml
hide_branch_rate: true
hide_complexity: true
badge: true
output: 'file'
- name: Extract code coverage badge
if: github.event_name != 'pull_request'
run: |
read -r line < code-coverage-results.txt
coverage=$(echo "$line" | sed -n 's/.*Code%20Coverage-\([0-9]*\)%.*/\1/p')
condition=$(echo "$line" | sed -n 's/.*%25-\([a-z]*\)?.*/\1/p')
[[ $condition == "critical" ]] && color="#e05d44" || color="#44cc11"
cat <<EOF > cov.json
{
"schemaVersion": 1,
"label": "Code Coverage",
"message": "$coverage%",
"style": "for-the-badge",
"color": "$color"
}
- name: Publish code coverage badge
uses: exuanbo/actions-deploy-gist@v1
if: github.event_name != 'pull_request'
with:
token: ${{ secrets.GIST_SECRET }}
gist_id: dd5dc24ffa62de59b3d836f856f48a10
file_path: cov.json