From 951dfd0da3eea05f7a3e56adebf433243d15f37f Mon Sep 17 00:00:00 2001 From: Edward Skrod Date: Fri, 1 May 2020 06:56:47 -0400 Subject: [PATCH 01/14] Update the description with the proper case Update the "Wpf" in the description to "WPF" to reflect the proper case. --- ci/properties/wpf-dotnet-core.properties.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/properties/wpf-dotnet-core.properties.json b/ci/properties/wpf-dotnet-core.properties.json index f43ea35..c083d71 100644 --- a/ci/properties/wpf-dotnet-core.properties.json +++ b/ci/properties/wpf-dotnet-core.properties.json @@ -1,6 +1,6 @@ { "name": "WPF .NET Core", - "description": "Build, test and publish a Wpf application built on .NET Core.", + "description": "Build, test and publish a WPF application built on .NET Core.", "iconName": "dotnetcore", "categories": ["C#", "Visual Basic", "WPF", ".NET"] -} \ No newline at end of file +} From f543db49dbe97d4ae5d508a05dfb9f6e630227a7 Mon Sep 17 00:00:00 2001 From: Tim Dorr Date: Fri, 1 May 2020 18:53:57 -0400 Subject: [PATCH 02/14] Fix source image name on docker tag This resolves an issue created by #472 --- ci/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/docker-publish.yml b/ci/docker-publish.yml index 1a1805f..9e80e76 100644 --- a/ci/docker-publish.yml +++ b/ci/docker-publish.yml @@ -72,5 +72,5 @@ jobs: echo IMAGE_ID=$IMAGE_ID echo VERSION=$VERSION - docker tag image $IMAGE_ID:$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION docker push $IMAGE_ID:$VERSION From 5802cb730239f3f1da75deb599a9ab0f178e479a Mon Sep 17 00:00:00 2001 From: Christopher Schleiden Date: Fri, 15 May 2020 16:49:20 -0700 Subject: [PATCH 03/14] Add script and workflow to sync the set of starter-workflows for GHES --- .github/workflows/sync_ghes.yaml | 26 ++++++ .gitignore | 1 + .vscode/launch.json | 21 +++++ script/exec.ts | 42 +++++++++ script/index.ts | 144 +++++++++++++++++++++++++++++++ script/package-lock.json | 112 ++++++++++++++++++++++++ script/package.json | 19 ++++ script/settings.json | 20 +++++ script/tsconfig.json | 5 ++ 9 files changed, 390 insertions(+) create mode 100644 .github/workflows/sync_ghes.yaml create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 script/exec.ts create mode 100755 script/index.ts create mode 100644 script/package-lock.json create mode 100644 script/package.json create mode 100644 script/settings.json create mode 100644 script/tsconfig.json diff --git a/.github/workflows/sync_ghes.yaml b/.github/workflows/sync_ghes.yaml new file mode 100644 index 0000000..6a0be1b --- /dev/null +++ b/.github/workflows/sync_ghes.yaml @@ -0,0 +1,26 @@ +on: + push: + branches: + - master + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - run: | + git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/* + git config user.email "cschleiden@github.com" + git config user.name "GitHub Actions" + - uses: actions/setup-node@v1 + with: + node-version: '12' + - name: Check starter workflows for GHES compat + run: | + npm ci + npx ts-node-script ./index.ts + working-directory: ./script + - run: | + git add -A + git commit -m "Updating GHES workflows" + - run: git push \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d844aa1 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +script/node_modules \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..a5cc146 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "args": ["${workspaceRoot}/script/index.ts"], + "runtimeArgs": ["-r", "ts-node/register"], + "cwd": "${workspaceRoot}/script", + "protocol": "inspector", + "internalConsoleOptions": "openOnSessionStart", + "env": { + "TS_NODE_IGNORE": "false" + } + } + ] +} \ No newline at end of file diff --git a/script/exec.ts b/script/exec.ts new file mode 100644 index 0000000..e529324 --- /dev/null +++ b/script/exec.ts @@ -0,0 +1,42 @@ +import { spawn } from "child_process"; + +export class ExecResult { + stdout = ""; + exitCode = 0; +} + +/** + * Executes a process + */ +export async function exec( + command: string, + args: string[] = [], + allowAllExitCodes: boolean = false +): Promise { + process.stdout.write(`EXEC: ${command} ${args.join(" ")}\n`); + return new Promise((resolve, reject) => { + const execResult = new ExecResult(); + const cp = spawn(command, args, {}); + + // STDOUT + cp.stdout.on("data", (data) => { + process.stdout.write(data); + execResult.stdout += data.toString(); + }); + + // STDERR + cp.stderr.on("data", (data) => { + process.stderr.write(data); + }); + + // Close + cp.on("close", (code) => { + execResult.exitCode = code; + if (code === 0 || allowAllExitCodes) { + resolve(execResult); + } else { + reject(new Error(`Command exited with code ${code}`)); + } + }); + }); +} diff --git a/script/index.ts b/script/index.ts new file mode 100755 index 0000000..943ffc3 --- /dev/null +++ b/script/index.ts @@ -0,0 +1,144 @@ +#!/usr/bin/env npx ts-node +import { promises as fs } from "fs"; +import { safeLoad } from "js-yaml"; +import { basename, extname, join } from "path"; +import { exec } from "./exec"; + +interface WorkflowDesc { + folder: string; + id: string; +} + +interface WorkflowsCheckResult { + compatibleWorkflows: WorkflowDesc[]; + incompatibleWorkflows: WorkflowDesc[]; +} + +async function checkWorkflows( + folders: string[], + enabledActions: string[] +): Promise { + const result: WorkflowsCheckResult = { + compatibleWorkflows: [], + incompatibleWorkflows: [], + }; + + for (const folder of folders) { + const dir = await fs.readdir(folder, { + withFileTypes: true, + }); + + for (const e of dir) { + if (e.isFile()) { + const workflowFilePath = join(folder, e.name); + const enabled = await checkWorkflow(workflowFilePath, enabledActions); + + const workflowDesc: WorkflowDesc = { + folder, + id: basename(e.name, extname(e.name)), + }; + + if (!enabled) { + result.incompatibleWorkflows.push(workflowDesc); + } else { + result.compatibleWorkflows.push(workflowDesc); + } + } + } + } + + return result; +} + +/** + * Check if a workflow only the given set of actions. + * + * @param workflowPath Path to workflow yaml file + * @param enabledActions List of enabled actions + */ +async function checkWorkflow( + workflowPath: string, + enabledActions: string[] +): Promise { + // Create set with lowercase action names for easier, case-insensitive lookup + const enabledActionsSet = new Set(enabledActions.map((x) => x.toLowerCase())); + + try { + const workflowFileContent = await fs.readFile(workflowPath, "utf8"); + const workflow = safeLoad(workflowFileContent); + + for (const job of Object.keys(workflow.jobs || {}).map( + (k) => workflow.jobs[k] + )) { + for (const step of job.steps || []) { + if (!!step.uses) { + // Check if allowed action + const [actionName, _] = step.uses.split("@"); + if (!enabledActionsSet.has(actionName.toLowerCase())) { + return false; + } + } + } + } + + // All used actions are enabled 🎉 + return true; + } catch (e) { + console.error("Error while checking workflow", e); + throw e; + } +} + +(async function main() { + try { + const settings = require("./settings.json"); + + const result = await checkWorkflows( + settings.folders, + settings.enabledActions + ); + + console.group( + `Found ${result.compatibleWorkflows.length} starter workflows compatible with GHES:` + ); + console.log( + result.compatibleWorkflows.map((x) => `${x.folder}/${x.id}`).join("\n") + ); + console.groupEnd(); + + console.group( + `Ignored ${result.incompatibleWorkflows.length} starter-workflows incompatible with GHES:` + ); + console.log( + result.incompatibleWorkflows.map((x) => `${x.folder}/${x.id}`).join("\n") + ); + console.groupEnd(); + + console.log("Switch to GHES branch"); + await exec("git", ["checkout", "ghes"]); + + // In order to sync from master, we might need to remove some workflows, add some + // and modify others. The lazy approach is to delete all workflows first, and then + // just bring the compatible ones over from the master branch. We let git figure out + // whether it's a deletion, add, or modify and commit the new state. + console.log("Remove all workflows"); + await exec("rm", ["-fr", ...settings.folders]); + + console.log("Sync changes from master for compatible workflows"); + await exec("git", [ + "checkout", + "master", + "--", + ...Array.prototype.concat.apply( + [], + result.compatibleWorkflows.map((x) => [ + join(x.folder, `${x.id}.yml`), + join(x.folder, "properties", `${x.id}.properties.json`), + ]) + ), + ]); + } catch (e) { + console.error("Unhandled error while syncing workflows", e); + process.exitCode = 1; + } +})(); diff --git a/script/package-lock.json b/script/package-lock.json new file mode 100644 index 0000000..ebcd318 --- /dev/null +++ b/script/package-lock.json @@ -0,0 +1,112 @@ +{ + "name": "sync-ghes-actions", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/js-yaml": { + "version": "3.12.4", + "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-3.12.4.tgz", + "integrity": "sha512-fYMgzN+9e28R81weVN49inn/u798ruU91En1ZnGvSZzCRc5jXx9B2EDhlRaWmcO1RIxFHL8AajRXzxDuJu93+A==", + "dev": true + }, + "@types/node": { + "version": "14.0.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.1.tgz", + "integrity": "sha512-FAYBGwC+W6F9+huFIDtn43cpy7+SzG+atzRiTfdp3inUKL2hXnd4rG8hylJLIh4+hqrQy1P17kvJByE/z825hA==", + "dev": true + }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "requires": { + "sprintf-js": "~1.0.2" + } + }, + "buffer-from": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "dev": true + }, + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" + }, + "js-yaml": { + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", + "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, + "source-map-support": { + "version": "0.5.19", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", + "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" + }, + "ts-node": { + "version": "8.10.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.10.1.tgz", + "integrity": "sha512-bdNz1L4ekHiJul6SHtZWs1ujEKERJnHs4HxN7rjTyyVOFf3HaJ6sLqe6aPG62XTzAB/63pKRh5jTSWL0D7bsvw==", + "dev": true, + "requires": { + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.17", + "yn": "3.1.1" + } + }, + "typescript": { + "version": "3.9.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.2.tgz", + "integrity": "sha512-q2ktq4n/uLuNNShyayit+DTobV2ApPEo/6so68JaD5ojvc/6GClBipedB9zNWYxRSAlZXAe405Rlijzl6qDiSw==", + "dev": true + }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true + } + } +} diff --git a/script/package.json b/script/package.json new file mode 100644 index 0000000..c3c9872 --- /dev/null +++ b/script/package.json @@ -0,0 +1,19 @@ +{ + "name": "sync-ghes-actions", + "version": "1.0.0", + "main": "index.ts", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "github/c2c-actions-experience", + "license": "MIT", + "devDependencies": { + "@types/js-yaml": "^3.12.4", + "@types/node": "^14.0.1", + "ts-node": "^8.10.1", + "typescript": "^3.9.2" + }, + "dependencies": { + "js-yaml": "^3.13.1" + } +} diff --git a/script/settings.json b/script/settings.json new file mode 100644 index 0000000..977c6f5 --- /dev/null +++ b/script/settings.json @@ -0,0 +1,20 @@ +{ + "folders": [ + "../ci", + "../automation" + ], + "enabledActions": [ + "actions/checkout", + "actions/create-release", + "actions/delete-package-versions", + "actions/download-artifact", + "actions/setup-dotnet", + "actions/setup-go", + "actions/setup-java", + "actions/setup-node", + "actions/stale", + "actions/starter-workflows", + "actions/upload-artifact", + "actions/upload-release-asset" + ] +} diff --git a/script/tsconfig.json b/script/tsconfig.json new file mode 100644 index 0000000..7c50a20 --- /dev/null +++ b/script/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + }, + "include": ["*.ts"] +} \ No newline at end of file From 62f6872b4ea8dd11b34ded263418d156067e6d15 Mon Sep 17 00:00:00 2001 From: Christopher Schleiden Date: Wed, 20 May 2020 10:00:39 -0700 Subject: [PATCH 04/14] Move ghes-sync into subfolder --- .github/workflows/sync_ghes.yaml | 2 +- .gitignore | 2 +- script/{ => sync-ghes}/exec.ts | 0 script/{ => sync-ghes}/index.ts | 5 ++++- script/{ => sync-ghes}/package-lock.json | 0 script/{ => sync-ghes}/package.json | 0 script/{ => sync-ghes}/settings.json | 0 script/{ => sync-ghes}/tsconfig.json | 0 8 files changed, 6 insertions(+), 3 deletions(-) rename script/{ => sync-ghes}/exec.ts (100%) rename script/{ => sync-ghes}/index.ts (95%) rename script/{ => sync-ghes}/package-lock.json (100%) rename script/{ => sync-ghes}/package.json (100%) rename script/{ => sync-ghes}/settings.json (100%) rename script/{ => sync-ghes}/tsconfig.json (100%) diff --git a/.github/workflows/sync_ghes.yaml b/.github/workflows/sync_ghes.yaml index 6a0be1b..0b1d289 100644 --- a/.github/workflows/sync_ghes.yaml +++ b/.github/workflows/sync_ghes.yaml @@ -19,7 +19,7 @@ jobs: run: | npm ci npx ts-node-script ./index.ts - working-directory: ./script + working-directory: ./script/sync-ghes - run: | git add -A git commit -m "Updating GHES workflows" diff --git a/.gitignore b/.gitignore index d844aa1..c5364f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -script/node_modules \ No newline at end of file +script/**/node_modules \ No newline at end of file diff --git a/script/exec.ts b/script/sync-ghes/exec.ts similarity index 100% rename from script/exec.ts rename to script/sync-ghes/exec.ts diff --git a/script/index.ts b/script/sync-ghes/index.ts similarity index 95% rename from script/index.ts rename to script/sync-ghes/index.ts index 943ffc3..c5633c2 100755 --- a/script/index.ts +++ b/script/sync-ghes/index.ts @@ -51,7 +51,7 @@ async function checkWorkflows( } /** - * Check if a workflow only the given set of actions. + * Check if a workflow uses only the given set of actions. * * @param workflowPath Path to workflow yaml file * @param enabledActions List of enabled actions @@ -75,6 +75,9 @@ async function checkWorkflow( // Check if allowed action const [actionName, _] = step.uses.split("@"); if (!enabledActionsSet.has(actionName.toLowerCase())) { + console.info( + `Workflow ${workflowPath} uses '${actionName}' which is not supported for GHES.` + ); return false; } } diff --git a/script/package-lock.json b/script/sync-ghes/package-lock.json similarity index 100% rename from script/package-lock.json rename to script/sync-ghes/package-lock.json diff --git a/script/package.json b/script/sync-ghes/package.json similarity index 100% rename from script/package.json rename to script/sync-ghes/package.json diff --git a/script/settings.json b/script/sync-ghes/settings.json similarity index 100% rename from script/settings.json rename to script/sync-ghes/settings.json diff --git a/script/tsconfig.json b/script/sync-ghes/tsconfig.json similarity index 100% rename from script/tsconfig.json rename to script/sync-ghes/tsconfig.json From 88d425bbe7b0a404065b83ddf3c08ae3b2d4581d Mon Sep 17 00:00:00 2001 From: Christopher Schleiden Date: Wed, 20 May 2020 10:40:26 -0700 Subject: [PATCH 05/14] Sync icons only for supported workflows --- script/sync-ghes/index.ts | 14 +++++++++++++- script/sync-ghes/settings.json | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/script/sync-ghes/index.ts b/script/sync-ghes/index.ts index c5633c2..b63c124 100755 --- a/script/sync-ghes/index.ts +++ b/script/sync-ghes/index.ts @@ -7,6 +7,7 @@ import { exec } from "./exec"; interface WorkflowDesc { folder: string; id: string; + iconName: string; } interface WorkflowsCheckResult { @@ -33,9 +34,18 @@ async function checkWorkflows( const workflowFilePath = join(folder, e.name); const enabled = await checkWorkflow(workflowFilePath, enabledActions); + const workflowId = basename(e.name, extname(e.name)); + const workflowProperties = require(join( + folder, + "properties", + `${workflowId}.properties.json` + )); + const iconName = workflowProperties["iconName"]; + const workflowDesc: WorkflowDesc = { folder, - id: basename(e.name, extname(e.name)), + id: workflowId, + iconName, }; if (!enabled) { @@ -126,6 +136,7 @@ async function checkWorkflow( // whether it's a deletion, add, or modify and commit the new state. console.log("Remove all workflows"); await exec("rm", ["-fr", ...settings.folders]); + await exec("rm", ["-fr", "../../icons"]); console.log("Sync changes from master for compatible workflows"); await exec("git", [ @@ -137,6 +148,7 @@ async function checkWorkflow( result.compatibleWorkflows.map((x) => [ join(x.folder, `${x.id}.yml`), join(x.folder, "properties", `${x.id}.properties.json`), + join("../../icons", `${x.iconName}.svg`), ]) ), ]); diff --git a/script/sync-ghes/settings.json b/script/sync-ghes/settings.json index 977c6f5..050ea0a 100644 --- a/script/sync-ghes/settings.json +++ b/script/sync-ghes/settings.json @@ -1,7 +1,7 @@ { "folders": [ - "../ci", - "../automation" + "../../ci", + "../../automation" ], "enabledActions": [ "actions/checkout", From af4b66354beeefe58f5bba80e01cade27afcc9bd Mon Sep 17 00:00:00 2001 From: Christopher Schleiden Date: Wed, 20 May 2020 10:54:19 -0700 Subject: [PATCH 06/14] Only sync svg icons --- script/sync-ghes/index.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/script/sync-ghes/index.ts b/script/sync-ghes/index.ts index b63c124..5390664 100755 --- a/script/sync-ghes/index.ts +++ b/script/sync-ghes/index.ts @@ -7,7 +7,8 @@ import { exec } from "./exec"; interface WorkflowDesc { folder: string; id: string; - iconName: string; + iconName?: string; + iconType?: "svg" | "octicon"; } interface WorkflowsCheckResult { @@ -40,12 +41,14 @@ async function checkWorkflows( "properties", `${workflowId}.properties.json` )); - const iconName = workflowProperties["iconName"]; + const iconName: string | undefined = workflowProperties["iconName"]; const workflowDesc: WorkflowDesc = { folder, id: workflowId, iconName, + iconType: + iconName && iconName.startsWith("octicon") ? "octicon" : "svg", }; if (!enabled) { @@ -145,11 +148,18 @@ async function checkWorkflow( "--", ...Array.prototype.concat.apply( [], - result.compatibleWorkflows.map((x) => [ - join(x.folder, `${x.id}.yml`), - join(x.folder, "properties", `${x.id}.properties.json`), - join("../../icons", `${x.iconName}.svg`), - ]) + result.compatibleWorkflows.map((x) => { + const r = [ + join(x.folder, `${x.id}.yml`), + join(x.folder, "properties", `${x.id}.properties.json`), + ]; + + if (x.iconType === "svg") { + r.push(join("../../icons", `${x.iconName}.svg`)); + } + + return r; + }) ), ]); } catch (e) { From 70c22e93a371758a899200e87f865d0df7ed3b6a Mon Sep 17 00:00:00 2001 From: Christopher Schleiden Date: Wed, 20 May 2020 11:39:30 -0700 Subject: [PATCH 07/14] Name GHES sync workflow --- .github/workflows/sync_ghes.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync_ghes.yaml b/.github/workflows/sync_ghes.yaml index 0b1d289..397c173 100644 --- a/.github/workflows/sync_ghes.yaml +++ b/.github/workflows/sync_ghes.yaml @@ -1,3 +1,5 @@ +name: Sync workflows for GHES + on: push: branches: @@ -23,4 +25,4 @@ jobs: - run: | git add -A git commit -m "Updating GHES workflows" - - run: git push \ No newline at end of file + - run: git push From a83abcc8723c99e08ff18aa6efc3a5691d908918 Mon Sep 17 00:00:00 2001 From: Cameron Booth Date: Tue, 19 May 2020 09:51:39 -0700 Subject: [PATCH 08/14] Script to validate the main parts of workflow data --- .github/workflows/validate-data.yaml | 19 ++++ script/validate-data/index.ts | 116 +++++++++++++++++++++++ script/validate-data/package-lock.json | 122 +++++++++++++++++++++++++ script/validate-data/package.json | 21 +++++ script/validate-data/settings.json | 6 ++ script/validate-data/tsconfig.json | 5 + 6 files changed, 289 insertions(+) create mode 100644 .github/workflows/validate-data.yaml create mode 100755 script/validate-data/index.ts create mode 100644 script/validate-data/package-lock.json create mode 100644 script/validate-data/package.json create mode 100644 script/validate-data/settings.json create mode 100644 script/validate-data/tsconfig.json diff --git a/.github/workflows/validate-data.yaml b/.github/workflows/validate-data.yaml new file mode 100644 index 0000000..3abd612 --- /dev/null +++ b/.github/workflows/validate-data.yaml @@ -0,0 +1,19 @@ +on: + push: + pull_request: + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - uses: actions/setup-node@v1 + with: + node-version: "12" + + - name: Validate workflows + run: | + npm ci + npx ts-node-script ./index.ts + working-directory: ./script/validate-data diff --git a/script/validate-data/index.ts b/script/validate-data/index.ts new file mode 100755 index 0000000..0809372 --- /dev/null +++ b/script/validate-data/index.ts @@ -0,0 +1,116 @@ +#!/usr/bin/env npx ts-node +import { promises as fs } from "fs"; +import { safeLoad } from "js-yaml"; +import { basename, extname, join } from "path"; +import { Validator as validator } from "jsonschema"; +import { endGroup, error, setFailed, startGroup } from '@actions/core'; + +interface WorkflowWithErrors { + id: string; + errors: string[]; +} + +interface WorkflowProperties { + name: string; + description: string; + iconName: string; + categories: string[]; +} + +const propertiesSchema = { + type: "object", + properties: { + name: { type: "string", required: true }, + description: { type: "string", required: true }, + iconName: { type: "string", required: true }, + categories: { + anyOf: [ + { + type: "array", + items: { type: "string" } + }, + { + type: "null", + } + ], + required: true + }, + } +} + +async function checkWorkflows(folders: string[]): Promise { + const result: WorkflowWithErrors[] = [] + + for (const folder of folders) { + const dir = await fs.readdir(folder, { + withFileTypes: true, + }); + + for (const e of dir) { + if (e.isFile()) { + const fileType = basename(e.name, extname(e.name)) + + const workflowFilePath = join(folder, e.name); + const propertiesFilePath = join(folder, "properties", `${fileType}.properties.json`) + + const errors = await checkWorkflow(workflowFilePath, propertiesFilePath); + if (errors.errors.length > 0) { + result.push(errors) + } + } + } + } + + return result; +} + +async function checkWorkflow(workflowPath: string, propertiesPath: string): Promise { + let workflowErrors: WorkflowWithErrors = { + id: workflowPath, + errors: [] + } + + try { + const workflowFileContent = await fs.readFile(workflowPath, "utf8"); + safeLoad(workflowFileContent); // Validate yaml parses without error + + const propertiesFileContent = await fs.readFile(propertiesPath, "utf8") + const properties: WorkflowProperties = JSON.parse(propertiesFileContent) + + let v = new validator(); + const res = v.validate(properties, propertiesSchema) + workflowErrors.errors = res.errors.map(e => e.toString()) + + if (properties.iconName && !properties.iconName.startsWith("octicon")) { + try { + await fs.access(`../../icons/${properties.iconName}.svg`) + } catch (e) { + workflowErrors.errors.push(`No icon named ${properties.iconName} found`) + } + } + } catch (e) { + workflowErrors.errors.push(e.toString()) + } + return workflowErrors; +} + +(async function main() { + try { + const settings = require("./settings.json"); + const erroredWorkflows = await checkWorkflows( + settings.folders + ) + + if (erroredWorkflows.length > 0) { + startGroup(`Found ${erroredWorkflows.length} workflows with errors:`); + erroredWorkflows.forEach(erroredWorkflow => { + error(`Errors in ${erroredWorkflow.id} - ${erroredWorkflow.errors.map(e => e.toString()).join(", ")}`) + }) + endGroup(); + setFailed(`Found ${erroredWorkflows.length} workflows with errors`); + } + } catch (e) { + error(`Unhandled error while syncing workflows: ${e}`); + setFailed(`Unhandled error`) + } +})(); diff --git a/script/validate-data/package-lock.json b/script/validate-data/package-lock.json new file mode 100644 index 0000000..110d23f --- /dev/null +++ b/script/validate-data/package-lock.json @@ -0,0 +1,122 @@ +{ + "name": "sync-ghes-actions", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@actions/core": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.4.tgz", + "integrity": "sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg==" + }, + "@types/js-yaml": { + "version": "3.12.4", + "resolved": "https://registry.npmjs.org/@types/js-yaml/-/js-yaml-3.12.4.tgz", + "integrity": "sha512-fYMgzN+9e28R81weVN49inn/u798ruU91En1ZnGvSZzCRc5jXx9B2EDhlRaWmcO1RIxFHL8AajRXzxDuJu93+A==", + "dev": true + }, + "@types/node": { + "version": "14.0.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.1.tgz", + "integrity": "sha512-FAYBGwC+W6F9+huFIDtn43cpy7+SzG+atzRiTfdp3inUKL2hXnd4rG8hylJLIh4+hqrQy1P17kvJByE/z825hA==", + "dev": true + }, + "arg": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", + "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", + "dev": true + }, + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "requires": { + "sprintf-js": "~1.0.2" + } + }, + "buffer-from": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "dev": true + }, + "diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true + }, + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" + }, + "js-yaml": { + "version": "3.13.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz", + "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==", + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, + "jsonschema": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/jsonschema/-/jsonschema-1.2.6.tgz", + "integrity": "sha512-SqhURKZG07JyKKeo/ir24QnS4/BV7a6gQy93bUSe4lUdNp0QNpIz2c9elWJQ9dpc5cQYY6cvCzgRwy0MQCLyqA==" + }, + "make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", + "dev": true + }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + }, + "source-map-support": { + "version": "0.5.19", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", + "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, + "sprintf-js": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" + }, + "ts-node": { + "version": "8.10.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.10.1.tgz", + "integrity": "sha512-bdNz1L4ekHiJul6SHtZWs1ujEKERJnHs4HxN7rjTyyVOFf3HaJ6sLqe6aPG62XTzAB/63pKRh5jTSWL0D7bsvw==", + "dev": true, + "requires": { + "arg": "^4.1.0", + "diff": "^4.0.1", + "make-error": "^1.1.1", + "source-map-support": "^0.5.17", + "yn": "3.1.1" + } + }, + "typescript": { + "version": "3.9.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.9.2.tgz", + "integrity": "sha512-q2ktq4n/uLuNNShyayit+DTobV2ApPEo/6so68JaD5ojvc/6GClBipedB9zNWYxRSAlZXAe405Rlijzl6qDiSw==", + "dev": true + }, + "yn": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", + "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", + "dev": true + } + } +} diff --git a/script/validate-data/package.json b/script/validate-data/package.json new file mode 100644 index 0000000..a2b867d --- /dev/null +++ b/script/validate-data/package.json @@ -0,0 +1,21 @@ +{ + "name": "validate-data", + "version": "1.0.0", + "main": "index.ts", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "github/c2c-actions-experience", + "license": "MIT", + "devDependencies": { + "@types/js-yaml": "^3.12.4", + "@types/node": "^14.0.1", + "ts-node": "^8.10.1", + "typescript": "^3.9.2" + }, + "dependencies": { + "@actions/core": "^1.2.4", + "js-yaml": "^3.13.1", + "jsonschema": "^1.2.6" + } +} \ No newline at end of file diff --git a/script/validate-data/settings.json b/script/validate-data/settings.json new file mode 100644 index 0000000..1913e2f --- /dev/null +++ b/script/validate-data/settings.json @@ -0,0 +1,6 @@ +{ + "folders": [ + "../../ci", + "../../automation" + ] +} \ No newline at end of file diff --git a/script/validate-data/tsconfig.json b/script/validate-data/tsconfig.json new file mode 100644 index 0000000..7c50a20 --- /dev/null +++ b/script/validate-data/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + }, + "include": ["*.ts"] +} \ No newline at end of file From 3dd92068cf9c54c6abf3c6ca67ce9e522020cad6 Mon Sep 17 00:00:00 2001 From: Cameron Booth Date: Tue, 19 May 2020 09:59:46 -0700 Subject: [PATCH 09/14] Add missing icons --- icons/aws.svg | 1 + icons/azure.svg | 1 + icons/googlegke.svg | 1 + 3 files changed, 3 insertions(+) create mode 100644 icons/aws.svg create mode 100644 icons/azure.svg create mode 100644 icons/googlegke.svg diff --git a/icons/aws.svg b/icons/aws.svg new file mode 100644 index 0000000..59ff870 --- /dev/null +++ b/icons/aws.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/azure.svg b/icons/azure.svg new file mode 100644 index 0000000..2ff63c1 --- /dev/null +++ b/icons/azure.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/icons/googlegke.svg b/icons/googlegke.svg new file mode 100644 index 0000000..68ecb39 --- /dev/null +++ b/icons/googlegke.svg @@ -0,0 +1 @@ +image/svg+xml \ No newline at end of file From 1bb722865287973f4e166189d67c1f20009c3854 Mon Sep 17 00:00:00 2001 From: Cameron Booth Date: Tue, 19 May 2020 10:04:07 -0700 Subject: [PATCH 10/14] Report success as well for visibility --- script/validate-data/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/script/validate-data/index.ts b/script/validate-data/index.ts index 0809372..dbea113 100755 --- a/script/validate-data/index.ts +++ b/script/validate-data/index.ts @@ -3,7 +3,7 @@ import { promises as fs } from "fs"; import { safeLoad } from "js-yaml"; import { basename, extname, join } from "path"; import { Validator as validator } from "jsonschema"; -import { endGroup, error, setFailed, startGroup } from '@actions/core'; +import { endGroup, error, info, setFailed, startGroup } from '@actions/core'; interface WorkflowWithErrors { id: string; @@ -102,12 +102,14 @@ async function checkWorkflow(workflowPath: string, propertiesPath: string): Prom ) if (erroredWorkflows.length > 0) { - startGroup(`Found ${erroredWorkflows.length} workflows with errors:`); + startGroup(`😟 - Found ${erroredWorkflows.length} workflows with errors:`); erroredWorkflows.forEach(erroredWorkflow => { error(`Errors in ${erroredWorkflow.id} - ${erroredWorkflow.errors.map(e => e.toString()).join(", ")}`) }) endGroup(); setFailed(`Found ${erroredWorkflows.length} workflows with errors`); + } else { + info("🎉🤘 - Found no workflows with errors!") } } catch (e) { error(`Unhandled error while syncing workflows: ${e}`); From 74c1e87c6bb06c34c54405dda1276eadbabc8a81 Mon Sep 17 00:00:00 2001 From: Cameron Booth Date: Wed, 20 May 2020 16:31:20 -0700 Subject: [PATCH 11/14] =?UTF-8?q?Don=E2=80=99t=20fail=20if=20no=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/sync_ghes.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync_ghes.yaml b/.github/workflows/sync_ghes.yaml index 397c173..54193bd 100644 --- a/.github/workflows/sync_ghes.yaml +++ b/.github/workflows/sync_ghes.yaml @@ -24,5 +24,9 @@ jobs: working-directory: ./script/sync-ghes - run: | git add -A - git commit -m "Updating GHES workflows" + if [ -z "$(git status --porcelain)" ]; then + echo "No changes to commit" + else + git commit -m "Updating GHES workflows" + fi - run: git push From 9a0a11423d295d10201f83018c7cbfc38eca2b75 Mon Sep 17 00:00:00 2001 From: Cameron Booth Date: Wed, 20 May 2020 16:31:33 -0700 Subject: [PATCH 12/14] Name the workflow --- .github/workflows/validate-data.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/validate-data.yaml b/.github/workflows/validate-data.yaml index 3abd612..d923d73 100644 --- a/.github/workflows/validate-data.yaml +++ b/.github/workflows/validate-data.yaml @@ -1,3 +1,5 @@ +name: Validate Data + on: push: pull_request: From ec3fe32d4355d58639c819a074ac7266c5b5821c Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Thu, 21 May 2020 16:32:47 -0400 Subject: [PATCH 13/14] Define OTP/Elixir versions as strings As now [recommended](https://github.com/actions/setup-elixir/tree/2071beb570a53fb599fbd638d0a4f4577d57143d#usage) in the action's README, the configuration versions should be strings so that YAML parsing doesn't truncate something like `23.0` to `23`, which isn't equivalent. --- ci/elixir.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/elixir.yml b/ci/elixir.yml index 4de7dcb..ac918c8 100644 --- a/ci/elixir.yml +++ b/ci/elixir.yml @@ -16,8 +16,8 @@ jobs: - name: Setup elixir uses: actions/setup-elixir@v1 with: - elixir-version: 1.9.4 # Define the elixir version [required] - otp-version: 22.2 # Define the OTP version [required] + elixir-version: '1.9.4' # Define the elixir version [required] + otp-version: '22.2' # Define the OTP version [required] - name: Install Dependencies run: mix deps.get - name: Run Tests From 249441a642d6772b4531e1994d8056f9828953ae Mon Sep 17 00:00:00 2001 From: Cameron Booth Date: Thu, 21 May 2020 13:55:36 -0700 Subject: [PATCH 14/14] Update job name --- .github/workflows/validate-data.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/validate-data.yaml b/.github/workflows/validate-data.yaml index d923d73..20eee71 100644 --- a/.github/workflows/validate-data.yaml +++ b/.github/workflows/validate-data.yaml @@ -5,7 +5,7 @@ on: pull_request: jobs: - sync: + validate-data: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2