Skip to content

Commit

Permalink
Merge pull request #10 from hot-loader/publishing-automation
Browse files Browse the repository at this point in the history
Publishing automation - start
  • Loading branch information
theKashey authored Jul 14, 2019
2 parents 497b8ef + e1452ab commit f5fbfcd
Show file tree
Hide file tree
Showing 19 changed files with 4,036 additions and 204 deletions.
63 changes: 63 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
version: 2
jobs:
sanity_check:
working_directory: ~/project
docker:
- image: circleci/node:10
steps:
- checkout
- restore_cache:
name: Restore Yarn Package Cache
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- run:
name: Install Dependencies
command: yarn install --frozen-lockfile
- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn
- run:
name: Run Tests
command: yarn test

publish_if_needed:
working_directory: ~/project
docker:
- image: circleci/node:10
steps:
- checkout
- restore_cache:
name: Restore Yarn Package Cache
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- run:
name: Install Dependencies
command: yarn install --frozen-lockfile
- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn
- run:
name: Run Tests
command: node auto-publish/index.js

workflows:
version: 2

for_every_push:
jobs:
- sanity_check

publish_if_needed:
triggers:
- schedule:
cron: "0,30 * * * *"
filters:
branches:
only:
- publishing-automation
jobs:
- publish_if_needed
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
target
yarn-error.log
yarn-error.log
auto-publish/staging-area
auto-publish/staging-area-for-test
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/Dubnium
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["orta.vscode-jest", "editorconfig.editorconfig", "orta.vscode-jest"]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"debug.node.autoAttach": "on",
"jest.debugMode": false,
"jest.autoEnable": false,
"jest.enableCodeLens": true,
"jest.enableInlineErrorMessages": true,
"jest.runAllTestsFirst": true,
"jest.debugCodeLens.showWhenTestStateIn": ["fail", "unknown", "pass", "skip"],
}
1 change: 1 addition & 0 deletions .yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
registry "https://registry.npmjs.org"
10 changes: 10 additions & 0 deletions auto-publish/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require("path");
const fs = require("fs-extra");
const { getAndPatchGivenReactDOMVersionWithGivenRHLVersion } = require("./utils");

(async () => {
const targetDir = await getAndPatchGivenReactDOMVersionWithGivenRHLVersion(path.resolve(__dirname, "staging-area"), "16.8.6", "4.12.3", "@hot-loader/react-dom");
await fs.copy(targetDir, path.resolve(__dirname, "../target"))

console.log("Done!", { targetDir });
})();
59 changes: 59 additions & 0 deletions auto-publish/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const path = require("path");
const fs = require("fs-extra");
const {
execFile,
doesReactDOMOrHotLoaderHasNewerVersionThanUs,
getAndPatchGivenReactDOMVersionWithGivenRHLVersion
} = require("./utils");

// test with https://github.com/verdaccio/verdaccio ???

(async () => {
const ourDistTag = "latest";

// TODO: cover more dist tags
const answer = await doesReactDOMOrHotLoaderHasNewerVersionThanUs(
"latest",
"latest",
"test-org-bnaya-2",
"_rc"
);

if (answer) {
console.info("Going to publish!", answer)
if (
answer.reactDOMVersion === null ||
answer.reactHotLoaderVersion === null
) {
throw new Error("Versions to publish by can't be null");
}

const patchedPackageDir = await getAndPatchGivenReactDOMVersionWithGivenRHLVersion(
path.resolve(__dirname, "staging-area"),
answer.reactDOMVersion,
answer.reactHotLoaderVersion,
"test-org-bnaya-2"
);

console.info("don't really publish yet", { patchedPackageDir });

// const publishStdOut = await execFile(
// "yarn",
// [
// "publish",
// "--tag",
// ourDistTag + "_rc",
// "-y",
// "--access",
// "public",
// "--json"
// ],
// patchedPackageDir,
// 10000
// );

// console.info("Done publishing!", { publishStdOut });
} else {
console.info("Nothing to publish");
}
})();
82 changes: 82 additions & 0 deletions auto-publish/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
export interface yarnInfoJsonResponse {
type: "inspect";
data: {
name: string;
"dist-tags": Partial<{
[k: string]: string
}>;
versions: string[];
time: { [key: string]: string };
maintainers: Array<{
name: string;
email: string;
}>;
description: string;
homepage: string;
repository: {
type: string;
url: string;
};
bugs: {
url: string;
};
license: string;
readmeFilename: string;
keywords: string[];
version: string;
};
/*
example data:
{
"type": "inspect",
"data": {
"name": "@hot-loader/react-dom",
"dist-tags": { "latest": "16.8.6" },
"versions": [
"16.7.0-alpha.2",
"16.7.0-alpha.2.1",
"16.7.0-alpha.2.2",
"16.7.0-alpha.2.3",
"16.7.0-alpha.2.4",
"16.7.0",
"16.8.0-alpha.0",
"16.8.1",
"16.8.2",
"16.8.3",
"16.8.4",
"16.8.5",
"16.8.6"
],
"time": {
"created": "2018-11-21T10:47:51.342Z",
"16.7.0-alpha.2": "2018-11-21T10:47:51.742Z",
"modified": "2019-03-28T09:32:10.123Z",
"16.7.0-alpha.2.1": "2018-11-21T21:35:44.318Z",
"16.7.0-alpha.2.2": "2018-12-07T12:21:53.582Z",
"16.7.0-alpha.2.3": "2018-12-17T06:55:29.788Z",
"16.7.0-alpha.2.4": "2018-12-19T09:23:40.548Z",
"16.7.0": "2018-12-20T09:22:04.981Z",
"16.8.0-alpha.0": "2019-01-10T04:39:04.893Z",
"16.8.1": "2019-02-07T00:17:32.764Z",
"16.8.2": "2019-02-18T21:58:30.554Z",
"16.8.3": "2019-02-25T21:15:23.701Z",
"16.8.4": "2019-03-07T09:04:23.315Z",
"16.8.5": "2019-03-25T11:19:27.329Z",
"16.8.6": "2019-03-28T09:32:06.816Z"
},
"maintainers": [{ "name": "kashey", "email": "thekashey@gmail.com" }],
"description": "The Hot version of React-DOM",
"homepage": "https://github.com/hot-loader/react-dom#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/hot-loader/react-dom.git"
},
"bugs": { "url": "https://github.com/hot-loader/react-dom/issues" },
"license": "MIT",
"readmeFilename": "README.md",
"keywords": ["HMR", "react", "hot-loader"],
"version": "latest"
}
}
*/
}
Loading

0 comments on commit f5fbfcd

Please sign in to comment.