Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating wonder-stuff-ci package! #628

Merged
merged 9 commits into from
Apr 12, 2023
Merged

Conversation

jlauzy
Copy link
Member

@jlauzy jlauzy commented Apr 6, 2023

Summary:

  • Created a new package wonder-stuff-ci. This package will contain typescript functions that are used throughout our scripts and automations ( OLC, Bitrise, Github Actions, etc.). I found a need for this when needing common functions for interacting with mobile releases.
  • Ported over three functions that I need and will continue adding functions into this package as they arise.

Issue: FEI-5058

Test plan:

  • Wrote Jest test for the functions.

@jlauzy jlauzy self-assigned this Apr 6, 2023
@changeset-bot
Copy link

changeset-bot bot commented Apr 6, 2023

🦋 Changeset detected

Latest commit: 3ef0056

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@khanacademy/wonder-stuff-ci Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@khan-actions-bot khan-actions-bot requested a review from a team April 6, 2023 23:23
@khan-actions-bot
Copy link
Contributor

khan-actions-bot commented Apr 6, 2023

Gerald

Required Reviewers
  • @Khan/frontend-infra for changes to tsconfig-build.json, yarn.lock, .changeset/clean-houses-press.md, packages/wonder-stuff-ci/README.md, packages/wonder-stuff-ci/package.json, packages/wonder-stuff-ci/tsconfig.json, packages/wonder-stuff-ci/src/buffer-to-string.ts, packages/wonder-stuff-ci/src/compare-versions.ts, packages/wonder-stuff-ci/src/exec-async.ts, packages/wonder-stuff-ci/src/extract-mobile-release-info-from-branch-name.ts, packages/wonder-stuff-ci/src/get-mobile-release-tags.ts, packages/wonder-stuff-ci/src/get-tags-from-git.ts, packages/wonder-stuff-ci/src/index.ts, packages/wonder-stuff-ci/src/types.ts, packages/wonder-stuff-ci/src/__tests__/buffer-to-string.test.ts, packages/wonder-stuff-ci/src/__tests__/compare-versions.test.ts, packages/wonder-stuff-ci/src/__tests__/extract-mobile-release-info-from-branch-name.test.ts, packages/wonder-stuff-ci/src/__tests__/get-mobile-release-tags.test.ts, packages/wonder-stuff-ci/src/__tests__/get-tags-from-git.test.ts

Don't want to be involved in this pull request? Comment #removeme and we won't notify you of further changes.

@jlauzy jlauzy changed the title Adding three functions that I need for CI scripts that are used in OLC Creating wonder-stuff-ci package! Apr 6, 2023

## 0.0.1

- Initial commit of porting over OLC functions for mobile release management
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should I format the change log in wonderstuff? Is there a getting started guide on creating a package in wonder-stuff? All I did was copy what another package was doing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh no - so we're using Changesets! The CHANGELOG is generated automatically, so you shouldn't make it. You can see how to do this here: https://khanacademy.atlassian.net/wiki/spaces/WB/pages/2217640195/Versioning+and+releasing+Wonder+Blocks+packages (it's Wonder Blocks but we follow the same process for Wonder Stuff)

"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
},
"devDependencies": {
"@types/node": "^18.15.11",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to add this to resolve some types in the functions i need.

},
"devDependencies": {
"@types/node": "^18.15.11",
"ws-dev-build-settings": "^1.1.0"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the ws-dev-build-settings? Should I be adding the @types/node into this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is internal to wonder-stuff itself, these are the shared tools that we use to help with test running, builds, etc. I'm not sure if it makes sense to have the node types, or not! I'd say "no" only because not everything in wonder-stuff is designed to run in Node.

"version": "0.0.1",
"description": "Functions for creating automation and scripts.",
"scripts": {
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to get the test to run with yarn jest, but that didn't work because of typing. But using the yarn command it did work!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah - I think this handles some of the trickiness with being in a monorepo, if I remember correctly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, you have to run yarn jest and yarn test from the root directory. This confusing command at the package level basically does that for you, so you can do yarn test in one of the package folders, and it will do the right thing.

@@ -12,5 +12,6 @@
{"path": "./packages/wonder-stuff-sentry"},
{"path": "./packages/wonder-stuff-server"},
{"path": "./packages/wonder-stuff-testing"},
{"path": "./packages/wonder-stuff-ci"},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious how the tsconfig-build.json is used in wonderstuff?

What else is needed for me to get this new package published to npm?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of it is managed by Changesets - once you changes are approved and landed then a Changesets PR will be generated, once that's approved and landed it'll publish to NPM!

@codecov
Copy link

codecov bot commented Apr 6, 2023

Codecov Report

Merging #628 (3ef0056) into main (02bcad1) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #628   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           87        93    +6     
  Lines         1322      1349   +27     
  Branches       331       328    -3     
=========================================
+ Hits          1322      1349   +27     
Impacted Files Coverage Δ
packages/wonder-stuff-ci/src/buffer-to-string.ts 100.00% <100.00%> (ø)
packages/wonder-stuff-ci/src/compare-versions.ts 100.00% <100.00%> (ø)
packages/wonder-stuff-ci/src/exec-async.ts 100.00% <100.00%> (ø)
...rc/extract-mobile-release-info-from-branch-name.ts 100.00% <100.00%> (ø)
...ges/wonder-stuff-ci/src/get-mobile-release-tags.ts 100.00% <100.00%> (ø)
packages/wonder-stuff-ci/src/get-tags-from-git.ts 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7b1664b...3ef0056. Read the comment docs.

@jlauzy
Copy link
Member Author

jlauzy commented Apr 6, 2023

@somewhatabstract @kevinbarabash , uh did i do this right lol

Curious about what other steps I need to do to get this package publish, so that I can import it from a script I have in bitrise.

Copy link
Member

@jeresig jeresig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exciting! Suggestions and corrections inline.


## 0.0.1

- Initial commit of porting over OLC functions for mobile release management
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh no - so we're using Changesets! The CHANGELOG is generated automatically, so you shouldn't make it. You can see how to do this here: https://khanacademy.atlassian.net/wiki/spaces/WB/pages/2217640195/Versioning+and+releasing+Wonder+Blocks+packages (it's Wonder Blocks but we follow the same process for Wonder Stuff)

},
"devDependencies": {
"@types/node": "^18.15.11",
"ws-dev-build-settings": "^1.1.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is internal to wonder-stuff itself, these are the shared tools that we use to help with test running, builds, etc. I'm not sure if it makes sense to have the node types, or not! I'd say "no" only because not everything in wonder-stuff is designed to run in Node.

"version": "0.0.1",
"description": "Functions for creating automation and scripts.",
"scripts": {
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah - I think this handles some of the trickiness with being in a monorepo, if I remember correctly.

@@ -0,0 +1,70 @@
import execProm from "./exec-prom";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this file to mobile-release-utils.ts. That being said, this logic is rather specific to our release processes!

@@ -12,5 +12,6 @@
{"path": "./packages/wonder-stuff-sentry"},
{"path": "./packages/wonder-stuff-server"},
{"path": "./packages/wonder-stuff-testing"},
{"path": "./packages/wonder-stuff-ci"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of it is managed by Changesets - once you changes are approved and landed then a Changesets PR will be generated, once that's approved and landed it'll publish to NPM!

"name": "@khanacademy/wonder-stuff-ci",
"version": "0.0.1",
"description": "Functions for creating automation and scripts.",
"scripts": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're missing a critical index.ts file with all the things that you've created exported. Looking at wonder-stuff-core you'll probably want to add these lines here:

    "module": "dist/es/index.js",
    "main": "dist/index.js",
    "types": "dist/index.d.ts",

And then make a src/index.ts file that imports your files and re-exports them again.

* @param arg
* @returns match, if found, null otherwise
*/
export const isGetReleaseBranch = (arg: string) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this to: extractMobileReleaseBranch.

*
* @returns all release tags sorted creation time ascending
*/
const allReleaseTags = async (): Promise<Array<string>> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would re-name this to: allMobileReleaseTags

@github-actions
Copy link
Contributor

github-actions bot commented Apr 7, 2023

Size Change: 0 B

Total Size: 4.42 kB

ℹ️ View Unchanged
Filename Size
packages/wonder-stuff-core/dist/browser/es/index.js 1.78 kB
packages/wonder-stuff-sentry/dist/browser/es/index.js 1.66 kB
packages/wonder-stuff-testing/dist/browser/es/index.js 970 B

compressed-size-action

Copy link
Contributor

@kevinbarabash kevinbarabash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. A few nits, but nothing blocking. Thanks for creating this new shared package.

stderr: bufferToString(stderr),
})
: res({
err: null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): You could use null here which would allow the type for err to be Error | undefined.

Comment on lines 7 to 11
if (typeof input === "string") {
return input;
} else {
return input.toString("utf8");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): The following would be a bit more succinct:

Suggested change
if (typeof input === "string") {
return input;
} else {
return input.toString("utf8");
}
return (typeof input === "string") ? input : input.toString("utf8");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree!

Comment on lines 23 to 24
const v1v = v1.includes("-") ? v1.split("-")[1] : v1;
const v2v = v2.includes("-") ? v2.split("-")[1] : v2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: why are we checking for "-" here? The docstring says the version should be of the form <num>.<num>.<num>.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I need to update the docstring! tags are in the form unified-7.9.0, but this function also takes in raw version string 7.9.0

Comment on lines 47 to 49
const match = arg.match(
/^(release\/(ios|android|unified)\/)?v?(\d+\.\d+\.\d+(-\w*)*)$/i,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: I like that we're using a regex for this. Maybe we can do the same for compareVersions so that there's more consistency with how we're parsing version strings. This would allow the code in that function to be less defensive (we could assume there's always three numbers in a version string).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see what you are saying

    const v1p = v1v.replace(/^v/g, "").split(".");
    const v2p = v2v.replace(/^v/g, "").split(".");
    for (let i = 0; i < v1p.length || i < v2p.length; i++) {
        const p1 = +v1p[i] || 0;
        const p2 = +v2p[i] || 0;
        if (+p1 !== +p2) {
            return p1 > p2 ? 1 : -1;
        }
    }

This does not check if there are 3 numbers in the version string only. It just checks each digit that is split by "."

"release/unified/7.8.0",
"release/android/7.8.0",
"release/ios/7.8.0",
])("get the version from the release branch", (testCase: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: does TS complain if we type the testCase as string instead of any?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm interestingly my IDE does not complain. I ran tsc no complaints. I even ran yarn test and no complaints.

@jlauzy jlauzy requested a review from jeresig April 7, 2023 22:00
Copy link
Member

@jeresig jeresig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes!

Copy link
Member

@somewhatabstract somewhatabstract left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good. I have a few changes I'd like to see before this gets landed. See my inline comments for info.

@@ -0,0 +1,3 @@
# wonder-stuff-ci

This Wonder Stuff package contains functions for creating automation and scripts.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
This Wonder Stuff package contains functions for creating automation and scripts.
This Wonder Stuff package contains functions for automation and scripts.

"version": "0.0.1",
"description": "Functions for creating automation and scripts.",
"scripts": {
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, you have to run yarn jest and yarn test from the root directory. This confusing command at the package level basically does that for you, so you can do yarn test in one of the package folders, and it will do the right thing.

packages/wonder-stuff-ci/src/mobile-release-utils.ts Outdated Show resolved Hide resolved
Comment on lines 5 to 6
*
* @returns all release tags sorted creation time ascending
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Don't forget a first docline as well as types on the return.

Suggested change
*
* @returns all release tags sorted creation time ascending
* Get mobile release tags.
*
* Tags are filtered to only include those matching our tag version format
* (`<tag>-<num>.<num>.<num>`), then they are sorted by the version information from
* earliest version to most recent.
*
* @returns {Promise<Array<string>>} all release tags sorted creation time ascending

packages/wonder-stuff-ci/src/mobile-release-utils.ts Outdated Show resolved Hide resolved
packages/wonder-stuff-ci/src/exec-prom.ts Outdated Show resolved Hide resolved
packages/wonder-stuff-ci/src/exec-prom.ts Outdated Show resolved Hide resolved
packages/wonder-stuff-ci/src/exec-prom.ts Outdated Show resolved Hide resolved
packages/wonder-stuff-ci/src/mobile-release-utils.ts Outdated Show resolved Hide resolved
@jlauzy jlauzy requested a review from somewhatabstract April 10, 2023 21:46
@jlauzy
Copy link
Member Author

jlauzy commented Apr 10, 2023

@somewhatabstract Thanks for the feedback jeff, updated the pr based on your comments. Let me know if I missed anything!

Copy link
Member

@somewhatabstract somewhatabstract left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all these changes. This is looking great. I have one more change to suggest, but not blocking. See the inline commentary for info.

@@ -7,7 +7,7 @@
},
"name": "@khanacademy/wonder-stuff-ci",
"version": "0.0.1",
"description": "Functions for creating automation and scripts.",
"description": "Functions for automation and scripts.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Thanks!

* @param {string} The release branch of the form `[release/[unified|ios|android]]/[v]<num>.<num>.<num>[-extra]`.
* @returns {Object} The release version and prefix, if found; otherwise, `null`.
*/
export const extractMobileReleaseInfoFromBranchName = (arg: string | null) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Currently, the return type is inferred from the code and as such, there isn't a concrete way to refer to this type. It would be helpful for calling code if there was one as it can be used by them to type their own arguments and variables.

Something like:

type MobileReleaseInfo = {
    prefix: "release/unified/" | "release/ios" | "release/android",
    version: string,
};

And then:

Suggested change
export const extractMobileReleaseInfoFromBranchName = (arg: string | null) => {
export const extractMobileReleaseInfoFromBranchName =
(arg: string | null): MobileReleaseInfo => {

* }
*
* @param {string} The release branch of the form `[release/[unified|ios|android]]/[v]<num>.<num>.<num>[-extra]`.
* @returns {Object} The release version and prefix, if found; otherwise, `null`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: If you create the type as suggested below and then replace {Object} with {MobileReleaseInfo}, which gives folks a little nicer info in their IDEs.

/**
* The information about a release branch.
*/
type MobileReleaseBranchInfo = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Don't forget to export this type from index.ts so consumers of the API can use it.

export type {MobileReleaseBranchInfo} from "./types";

or

export * from "./types";

* }
*
* @param {string} The release branch of the form `[release/[unified|ios|android]]/[v]<num>.<num>.<num>[-extra]`.
* @returns {MobileReleaseInfo} The release version and prefix, if found; otherwise, `null`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion:

Suggested change
* @returns {MobileReleaseInfo} The release version and prefix, if found; otherwise, `null`.
* @returns {MobileReleasBranchInfo} The release version and prefix, if found; otherwise, `null`.

@jlauzy jlauzy merged commit d2fbdcc into main Apr 12, 2023
@jlauzy jlauzy deleted the FEI-5058-CreateWonderStuffCI branch April 12, 2023 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants