Skip to content

Commit

Permalink
💚 Fixing CI
Browse files Browse the repository at this point in the history
  • Loading branch information
i1u5 committed Apr 24, 2020
1 parent 34318e2 commit 01ef2cf
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Auto line endings
* text=auto
* text=auto eol=lf
18 changes: 8 additions & 10 deletions .github/workflows/QA.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name: QA

on:
schedule:
- cron: 0 1 * * *

push:
branches:
- master
jobs:
qa:
name: Quality Assurance
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- name: Checkout Project
uses: actions/checkout@v2
Expand All @@ -21,9 +20,7 @@ jobs:
path: node_modules
key: ${{ runner.os }}-12-${{ hashFiles('**/yarn.lock') }}
- name: Install Deps
run: |
sudo snap install hub --classic
yarn
run: yarn
- name: Compile Script
run: yarn qa:compile
- name: Start QA
Expand All @@ -32,6 +29,7 @@ jobs:
git config --global core.precomposeunicode true
yarn qa
- name: Commit any changes
if: always()
run: |
git add .;
if git diff-index --quiet HEAD --; then
Expand All @@ -45,9 +43,9 @@ jobs:
git config --local user.name "${GITHUB_USER}";
git checkout -b semid/qa/`date +%F-%H-%M`;
git commit -sam "♻️ Refactoring";
hub pull-request -p -m "🤖 Daily QA" -m "*beep boop* I've prettified and refactored some Presences, feel free to fix or remove the ones that break.";
hub pull-request -p -m "🤖 Daily QA" -m "*beep boop* I've prettified and refactored some Presences...";
fi
env:
GITHUB_USER: SeMiD
GITHUB_EMAIL: [email protected]
GITHUB_TOKEN: ${{ secrets.AUTOMERGE }}
GITHUB_TOKEN: ${{ secrets.AUTOMERGE }}
3 changes: 2 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = {
trailingComma: "none",
tabWidth: 2,
useTabs: false,
endOfLine: "auto"
endOfLine: "lf",
proseWrap: "always"
};
80 changes: 45 additions & 35 deletions qualityAssurance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,33 @@ import {
let finalExitCode = 0;

/**
* Helper function to read any file as string
* @param path Path to the file
*/
const readFile = (path: string) => readFileSync(path, { encoding: "utf8" });

/**
* Helper function to write any data to disk
* @param data Data to write
* @param path Path to write the data to
* Helper function to read a JSON file into memory
* @param jsonPath Path to the JSON file
*/
const writeFile = <T>(path: string, data: T) =>
writeFileSync(path, data, { encoding: "utf8" });
const readJson = <T>(jsonPath: string) => {
if (isValidJSON(jsonPath)) {
return JSON.parse(readFileSync(jsonPath, { encoding: "utf8" })) as T;
} else {
console.log(
red(`Unable to parse ${jsonPath ? jsonPath : "an unknown file"}`)
);

finalExitCode = 1;
}
};

/**
* Helper function to read a JSON file into memory
* @param jsonPath Path to the JSON file
* Helper function to validate JSON data
* @param path JSON path
*/
const readJson = <T>(jsonPath: string) => JSON.parse(readFile(jsonPath)) as T;
function isValidJSON(path: string) {
try {
JSON.parse(readFileSync(path, { encoding: "utf8" }));
return true;
} catch {
return false;
}
}

/**
* Helper function to write a JSON file to disk
Expand Down Expand Up @@ -93,10 +102,6 @@ const prettify = async () => {
ignore: ["**/node_modules/**", "**/@types/**"],
absolute: true
});
const jsonFiles = glob("**/{metadata,tsconfig}.json", {
ignore: ["**/node_modules/**", "**/@types/**"],
absolute: true
});

// Analyze which JS files actually should receive prettification
const jsFilesToPrettify = [];
Expand All @@ -121,15 +126,11 @@ const prettify = async () => {
}

// Concatenate all the files to prettify
const filesToPrettify: string[] = [
...tsFiles,
...jsFilesToPrettify,
...jsonFiles
];
const filesToPrettify: string[] = [...tsFiles, ...jsFilesToPrettify];

for (const fileToPrettify of filesToPrettify) {
// Get the raw data from the file
const fileContent = readFile(fileToPrettify);
const fileContent = readFileSync(fileToPrettify, { encoding: "utf8" });

// Format the file using Prettier
const formatted = prettier(fileContent, {
Expand All @@ -140,7 +141,7 @@ const prettify = async () => {
// If the file content isn't the same as the formatted content
if (formatted !== fileContent) {
// Write the file to the system
writeFile(fileToPrettify, formatted);
writeFileSync(fileToPrettify, formatted, { encoding: "utf8" });
// And log the name with a green colour to indicate it did change
console.log(green(relative(__dirname, fileToPrettify)));
}
Expand Down Expand Up @@ -191,6 +192,7 @@ const increaseSemver = async (filesToBump: string[]) => {
console.time("semver_bump_time");

for (const file of filesToBump) {
console.log(file);
// Normalize the path and seperate it on OS specific seperator
const normalizedPath = resolve(normalize(file)).split(sep);

Expand All @@ -199,9 +201,12 @@ const increaseSemver = async (filesToBump: string[]) => {

const metadataPath = join(normalizedPath.join(sep), "metadata.json");
const metadata = readJson<Metadata>(metadataPath);
const newVersion = valid(coerce(inc(metadata.version, "patch")));

writeJson({ ...metadata, version: newVersion }, metadataPath);
if (metadata && metadata.version) {
const newVersion = valid(coerce(inc(metadata.version, "patch")));

writeJson({ ...metadata, version: newVersion }, metadataPath);
}
}

console.timeEnd("semver_bump_time");
Expand Down Expand Up @@ -274,23 +279,28 @@ main();
/** Typings for the Metadata JSON file */
interface Metadata {
author: { name: string; id: string };
contributors: Array<{ name: string; id: string }>;
contributors?: Array<{ name: string; id: string }>;
service: string;
description: Record<string, string>;
url: string;
version: string;
logo: string;
thumbnail: string;
color: string;
tags: Array<string>;
tags: string | Array<string>;
category: string;
button: boolean;
settings: Array<{
iframe?: boolean;
regExp?: RegExp;
iframeRegExp?: RegExp;
button?: boolean;
warning?: boolean;
settings?: Array<{
id: string;
title: string;
icon: string;
placeholder: string;
value: string | number | boolean;
values: Array<string | number | boolean>;
if?: Record<string, string>;
placeholder?: string;
value?: string | number | boolean;
values?: Array<string | number | boolean>;
}>;
}
}

0 comments on commit 01ef2cf

Please sign in to comment.