Skip to content
This repository has been archived by the owner on Jun 5, 2021. It is now read-only.

Commit

Permalink
Prepare v0.0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
floric committed Jul 31, 2020
1 parent e6faa78 commit 9f17151
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update-monitor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
UpdateMonitor:
runs-on: ubuntu-latest
steps:
- uses: floric/[email protected].10
- uses: floric/[email protected].11
with:
key: bundle-size
value: 1
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ inputs:
required: true
runs:
using: "node12"
main: "index.js"
main: "dist/index.js"
56 changes: 56 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core = require("@actions/core");
const github = require("@actions/github");
async function run() {
try {
const key = core.getInput("key");
const value = core.getInput("value");
const token = core.getInput("token");
const octokit = github.getOctokit(token);
const { owner, repo } = github.context.repo;
const path = `docs/data/${key}.json`;
let res = await octokit.repos.getContent({
owner,
repo,
path,
});
let data = null;
const isUpdate = res.status == 200;
if (res.status == 404) {
core.info(`Found new key "${key}", will create new file.`);
data = { key, type: "scalar", values: [] };
}
else if (isUpdate) {
core.info(`Extending existing metrics for "${key}"`);
data = JSON.parse(fromBase64(res.data.content));
}
if (data == null) {
throw new Error(`Loading or updating data for "${key}" has failed`);
}
data.values.push({
value: Number.parseFloat(value),
isoDate: new Date().toISOString(),
});
const content = toBase64(JSON.stringify(data));
const updateRes = await octokit.repos.createOrUpdateFileContents({
owner,
repo,
path,
content,
sha: isUpdate ? res.data.sha : undefined,
message: isUpdate ? "Updated metrics" : "Created metrics",
});
core.info("Finished processing new metrics");
}
catch (error) {
core.setFailed(error.message);
}
}
function fromBase64(content) {
return Buffer.from(content, "base64").toString("ascii");
}
function toBase64(content) {
return Buffer.from(content).toString("base64");
}
run();
40 changes: 0 additions & 40 deletions index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Florian Richter <[email protected]>",
"license": "MIT",
"scripts": {
"build": "tsc ./index.ts"
"build": "tsc"
},
"dependencies": {
"@actions/core": "^1.2.4",
Expand Down
71 changes: 71 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import * as core from "@actions/core";
import * as github from "@actions/github";

type MetricsValue<T> = {
value: T;
isoDate: string;
};

type MetricsData = {
key: string;
type: "scalar";
values: Array<MetricsValue<number>>;
};

async function run() {
try {
const key = core.getInput("key");
const value = core.getInput("value");
const token = core.getInput("token");
const octokit = github.getOctokit(token);
const { owner, repo } = github.context.repo;
const path = `docs/data/${key}.json`;

let res = await octokit.repos.getContent({
owner,
repo,
path,
});
let data: MetricsData | null = null;
const isUpdate = res.status == 200;
if (res.status == 404) {
core.info(`Found new key "${key}", will create new file.`);
data = { key, type: "scalar", values: [] };
} else if (isUpdate) {
core.info(`Extending existing metrics for "${key}"`);
data = JSON.parse(fromBase64(res.data.content));
}

if (data == null) {
throw new Error(`Loading or updating data for "${key}" has failed`);
}

data.values.push({
value: Number.parseFloat(value),
isoDate: new Date().toISOString(),
});

const content = toBase64(JSON.stringify(data));

const updateRes = await octokit.repos.createOrUpdateFileContents({
owner,
repo,
path,
content,
sha: isUpdate ? res.data.sha : undefined,
message: isUpdate ? "Updated metrics" : "Created metrics",
});
core.info("Finished processing new metrics");
} catch (error) {
core.setFailed(error.message);
}
}

function fromBase64(content: string) {
return Buffer.from(content, "base64").toString("ascii");
}

function toBase64(content: string) {
return Buffer.from(content).toString("base64");
}
run();
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"outDir": "./dist",
"lib": ["es2020"],
"module": "commonjs",
"target": "es2019"
Expand Down

0 comments on commit 9f17151

Please sign in to comment.