Skip to content

Commit

Permalink
add ci
Browse files Browse the repository at this point in the history
  • Loading branch information
jshawl committed Mar 23, 2024
1 parent 7788932 commit 983d7a1
Show file tree
Hide file tree
Showing 8 changed files with 3,493 additions and 65 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ jobs:
runs-on: ubuntu-latest
name: demo
steps:
- uses: cinotify/github-action@main
- run: env
- uses: cinotify/github-action@ci
with:
to: "[email protected]"
subject: "${{ github.event.ref }}"
body: "<a href='https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}'>view build</a>"
subject: "${{ github.event.pull_request.head.sha || github.sha }}"
body: "<a href='https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}'>view build</a> - ${{github.event.head_commit.message}}"
type: "text/html"
38 changes: 2 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
const core = require('@actions/core');
const mime = require('mime');
const {readFileSync} = require('fs');
import { notify } from "./notify.js";

try {
const to = core.getInput('to');
const subject = core.getInput('subject');
const body = core.getInput('body');
const type = core.getInput('type');
const payload = {to, subject, body, type};

const attachmentPath = core.getInput('attachment');
if (attachmentPath) {
const file = readFileSync(attachmentPath);
const attachment = {
filename: attachmentPath,
type: mime.getType(attachmentPath),
content: file.toString('base64')
}
payload.attachments = [attachment];
}

fetch('https://www.cinotify.cc/api/notify', {
body: JSON.stringify(payload),
headers: {
'Content-Type': 'application/json',
'User-Agent': `@cinotify/github-action@${process.env['GITHUB_ACTION_REF']}`
},
method: 'POST'
}).then(() => {
core.setOutput("status", "ok")
}).catch(err => {
core.setFailed(err.message)
})
} catch (error) {
core.setFailed(error.message);
}
notify();
11 changes: 11 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { describe, test, expect, vi } from "vitest";
import { notify } from "./notify.js";
import index from "./index.js";

vi.mock("./notify");

describe("action entrypoint", () => {
test("invokes notify", async () => {
expect(notify).toHaveBeenCalled();
});
});
Loading

0 comments on commit 983d7a1

Please sign in to comment.