Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: run on pull requests #2

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions .github/workflows/test.yaml → .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
on: [push]
name: CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
name: Test
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
contents: write
steps:
Expand All @@ -16,9 +21,12 @@ jobs:
with:
go-version: '1.22'

- name: Test
run: make cover.html
- name: Generate Coverage Files
run: |
make cover.txt
make cover.html
- uses: './'
- name: Upload Coverage
uses: './'
with:
branch: 'cover'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode
cover.out
cover.txt
cover.html
30 changes: 19 additions & 11 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ inputs:
default: ${{ github.repository }}
branch:
default: cover
description: >
The branch to checkout and push coverage to.
description: The branch to checkout and push coverage to.
token:
description: The token to use for pushing to the repository.
default: ${{ github.token }}
outputs:
random-number:
description: "Random number"
Expand All @@ -18,7 +20,9 @@ runs:
- name: Checkout Coverage Branch
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository }}
path: go-cover
token: ${{ inputs.token }}

- name: Checkout Coverage Branch
shell: bash
Expand All @@ -33,29 +37,33 @@ runs:
rm .git/index
git clean -fdx
touch index.html
git add index.html
git config user.email "[email protected]"
git config user.name "GHA"
cp ../nord.css .
git add index.html nord.css
git config user.email "[email protected]"
git config user.name "go-coverage-action"
git commit -m "chore: initial commit"
git push origin ${{ inputs.branch }}
fi

- name: Push Coverage
shell: bash
run: |
export REVISION=${{ github.event.pull_request.head.sha || github.sha }}
export REVISION="${{ github.event.pull_request.head.sha || github.sha }}"
cd go-cover
mv ../cover.html ${REVISION}.html
ex -sc '%s/<style>/<style>@import url("nord.css");/' -c 'x' ${REVISION}.html
git add -f ${REVISION}.html
git config user.email "gha@github.com"
git config user.name "GHA"
git commit -m "chore: add cover for ${REVISION}"
git config user.email "go-coverage-action@github.com"
git config user.name "go-coverage-action"
git commit -m "chore: add cover for ${REVISION}" || true
git push origin ${{ inputs.branch }}

- name: Post Code Coverage Comment
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v6
with:
github-token: ${{ inputs.token }}
script: |
const script = require('${{ github.workspace }}/src/update-code-coverage-comment.js')
await script({ context, github })
const script = require('${{ github.workspace }}/update-code-coverage-comment.js')
const revision = '${{ github.event.pull_request.head.sha || github.sha }}'
await script({ context, github }, revision)
70 changes: 70 additions & 0 deletions nord.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
:root {
--nord-deep-dark: #242931;
--nord0: #2e3440;
--nord0-pale: rgba(46, 52, 64, 0.3);
--nord1: #3b4252;
--nord1-pale: rgba(59, 66, 82, 0.3);
--nord2: #434c5e;
--nord2-pale: rgba(67, 76, 94, 0.3);
--nord3: #4c566a;
--nord3-pale: rgba(76, 86, 106, 0.3);
--nord4: #d8dee9;
--nord4-pale: rgba(216, 222, 232, 0.3);
--nord5: #e5e9f0;
--nord5-pale: rgba(229, 233, 240, 0.3);
--nord6: #eceff4;
--nord6-pale: rgba(236, 239, 244, 0.3);
--nord7: #8fbcbb;
--nord7-pale: rgba(143, 188, 187, 0.3);
--nord8: #88c0d0;
--nord9: #81a1c1;
--nord10: #5e81ac;
--nord10-pale: rgba(94, 129, 172, 0.3);
--nord11: #bf616a;
--nord11-pale: rgba(191, 97, 106, 0.3);
--nord12: #d08770;
--nord12-pale: rgba(208, 135, 112, 0.3);
--nord13: #ebcb8b;
--nord13-pale: rgba(235, 203, 139, 0.3);
--nord14: #a3be8c;
--nord14-pale: rgba(163, 190, 140, 0.3);
--nord15: #b48ead;
--nord15-pale: rgba(180, 140, 173, 0.3);
}

* {
font-family: Menlo, Monaco, source-code-pro, "Ubuntu Mono", "DejaVu sans mono", Consolas, monospace, Menlo, Monaco, "Courier New", monospace;
font-weight: normal !important;
font-size: 14px;
}

body {
background: var(--nord0) !important;
color: var(--nord4) !important;
padding: 10px;
}

#topbar {
background: var(--nord1) !important;
border-color: var(--nord3) !important;
}

select {
background-color: var(--nord-deep-dark);
color: var(--nord9);
border: 1px solid var(--nord3);
border-radius: 3px;
padding: 2px;
}

.cov0 { color: var(--nord11) !important; }
.cov1 { color: var(--nord13) !important; }
.cov2 { color: var(--nord14) !important; }
.cov3 { color: var(--nord14) !important; }
.cov4 { color: var(--nord14) !important; }
.cov5 { color: var(--nord14) !important; }
.cov6 { color: var(--nord14) !important; }
.cov7 { color: var(--nord14) !important; }
.cov8 { color: var(--nord14) !important; }
.cov9 { color: var(--nord14) !important; }
.cov10 { color: var(--nord14) !important; }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs')

const updateCodeCoverageComment = module.exports = async ({ context, github }) => {
const updateCodeCoverageComment = module.exports = async ({ context, github }, revision) => {
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -14,8 +14,8 @@ const updateCodeCoverageComment = module.exports = async ({ context, github }) =

const commentBody = [
'<!-- coverage -->',
`### [Code Coverage Report 🔗](https://kilianc.github.io/base-golang-cli/${process.env.REVISION}.html#file0) for ${process.env.REVISION}`,
].join('\n')
`### [Code Coverage Report 🔗](https://${context.repo.owner}.github.io/${context.repo.repo}/${revision}.html#file0) for ${revision}`,
]

if (fs.existsSync('cover.txt') === true) {
const coverageText = fs.readFileSync('cover.txt', 'utf8').split('\n').slice(0, -1)
Expand All @@ -40,7 +40,7 @@ const updateCodeCoverageComment = module.exports = async ({ context, github }) =
repo: context.repo.repo,
issue_number: context.issue.number,
comment_id: coverageComment.id,
body: commentBody
body: commentBody.join('\n')
}

if (coverageComment.id) {
Expand Down
Loading