fix(stryker): not authorized error in workflow #790
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
name: 'units-test' | |
on: | |
pull_request: | |
push: | |
branches: | |
- main | |
- 'releases/*' | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
# unit tests | |
units: | |
runs-on: ubuntu-latest | |
env: | |
covGistPrefix: 'https://gist.githubusercontent.com/stenjo/9ce1ad7d8e9db99796e782b244eefa4a/raw/f52cd85b82dd774ba0ce9d052f7ff2be505ea2d0' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
id: setup-node | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: .node-version | |
cache: npm | |
- run: npm ci | |
- name: Run tests | |
run: | | |
npx jest --coverage | tee ./coverage.txt && exit "${PIPESTATUS[0]}" | |
- name: Get branch name | |
id: branch-name | |
uses: tj-actions/branch-names@v8 | |
- name: Jest Coverage Comment | |
id: coverageComment | |
uses: MishaKav/jest-coverage-comment@main | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
summary-title: Jest Coverage (summary) | |
title: Test Coverage | |
coverage-summary-path: coverage/coverage-summary.json | |
coverage-path: ./coverage.txt | |
- name: Check the output coverage | |
run: | | |
echo "Coverage Percentage - ${{ steps.coverageComment.outputs.coverage }}" | |
echo "Coverage Color - ${{ steps.coverageComment.outputs.color }}" | |
echo "Summary HTML - ${{ steps.coverageComment.outputs.summaryHtml }}" | |
mv coverage/coverage-summary.json . | |
- name: Create the Badge | |
uses: schneegans/dynamic-badges-action@v1.7.0 | |
if: steps.branch-name.outputs.current_branch == 'main' | |
with: | |
auth: ${{ secrets.GIST_AUTH_TOKEN }} | |
gistID: 9ce1ad7d8e9db99796e782b244eefa4a | |
filename: devops_metrics__${{ steps.branch-name.outputs.current_branch }}.json | |
label: Test Coverage | |
message: ${{ steps.coverageComment.outputs.coverage }}% | |
color: ${{ steps.coverageComment.outputs.color }} | |
namedLogo: jest | |
- name: Gist Sync File | |
uses: danielmcconville/gist-sync-file-action@v2.0.0 | |
if: steps.branch-name.outputs.current_branch == 'main' | |
with: | |
gistPat: ${{ secrets.GIST_AUTH_TOKEN }} | |
action: update | |
filename: coverage-summary.json | |
gistId: 9ce1ad7d8e9db99796e782b244eefa4a | |
- name: Get coverage Gist | |
if: steps.branch-name.outputs.current_branch != 'main' | |
run: | | |
curl -o main-coverage.json ${{ env.covGistPrefix }}/coverage-summary.json | |
function diff { diff="$(echo "$2" - "$1" | bc -l | sed -e 's/^\./0./' -e 's/^-\./-0./')"; echo "$diff"; } | |
current=$(jq .total.lines.pct coverage-summary.json) | |
main=$(jq .total.lines.pct main-coverage.json) | |
pctLineChange=$(diff "$main" "$current") | |
echo '**Code Coverage change**' > coverage.md | |
echo 'This PR changes coverage by' "$pctLineChange" '%' >> coverage.md | |
echo 'Component coverage will change from ' "$main"'% to ' "$current"'%.' >> coverage.md | |
echo "$(<coverage.md)" | |
- name: Add PR Comment with coverage diff | |
if: steps.branch-name.outputs.current_branch != 'main' | |
uses: mshick/add-pr-comment@v2 | |
with: | |
message-path: coverage.md | |
update-only: false | |
refresh-message-position: true | |
allow-repeats: false | |
message-id: 'add-pr-diff-comment-${{ github.event.pull_request.number }}' | |
# test action works running from the graph | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: ./ | |
id: dora | |
with: | |
owner: stenjo | |
repo: '[dora,Middager]' | |
token: ${{ secrets.GITHUB_TOKEN }} | |
logging: true | |
filtered: true | |
# Use the output from the `dora` step | |
- name: Get the output rate | |
run: | | |
printf "The deploy rate was %s" ${{ steps.dora.outputs.deploy-rate }} # Use the output from the `dora` step | |
printf "The log was:\n%s" ${{ steps.dora.outputs.deploy-rate-log }} # Use the output from the `dora` step | |
printf "${{ steps.dora.outputs.deploy-rate-log }}" > deploy-rate-log.txt | |
echo "The lead time was ${{ steps.dora.outputs.lead-time }}" # Use the output from the `dora` step | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: logs | |
path: ./*-log.txt |