-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
🦋 Changeset detectedLatest commit: 3ef0056 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
GeraldRequired Reviewers
Don't want to be involved in this pull request? Comment |
|
||
## 0.0.1 | ||
|
||
- Initial commit of porting over OLC functions for mobile release management |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)'" |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"}, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 Report
Additional details and impacted files@@ 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
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
@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. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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)'" |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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"}, |
There was a problem hiding this comment.
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": { |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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>> => { |
There was a problem hiding this comment.
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
Size Change: 0 B Total Size: 4.42 kB ℹ️ View Unchanged
|
There was a problem hiding this 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, |
There was a problem hiding this comment.
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
.
if (typeof input === "string") { | ||
return input; | ||
} else { | ||
return input.toString("utf8"); | ||
} |
There was a problem hiding this comment.
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:
if (typeof input === "string") { | |
return input; | |
} else { | |
return input.toString("utf8"); | |
} | |
return (typeof input === "string") ? input : input.toString("utf8"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree!
const v1v = v1.includes("-") ? v1.split("-")[1] : v1; | ||
const v2v = v2.includes("-") ? v2.split("-")[1] : v2; |
There was a problem hiding this comment.
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>
.
There was a problem hiding this comment.
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
const match = arg.match( | ||
/^(release\/(ios|android|unified)\/)?v?(\d+\.\d+\.\d+(-\w*)*)$/i, | ||
); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
There was a problem hiding this 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.
packages/wonder-stuff-ci/README.md
Outdated
@@ -0,0 +1,3 @@ | |||
# wonder-stuff-ci | |||
|
|||
This Wonder Stuff package contains functions for creating automation and scripts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
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)'" |
There was a problem hiding this comment.
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.
* | ||
* @returns all release tags sorted creation time ascending |
There was a problem hiding this comment.
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.
* | |
* @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/__tests__/mobile-release-utils.test.ts
Outdated
Show resolved
Hide resolved
@somewhatabstract Thanks for the feedback jeff, updated the pr based on your comments. Let me know if I missed anything! |
There was a problem hiding this 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.", |
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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:
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`. |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
* @returns {MobileReleaseInfo} The release version and prefix, if found; otherwise, `null`. | |
* @returns {MobileReleasBranchInfo} The release version and prefix, if found; otherwise, `null`. |
Summary:
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.Issue: FEI-5058
Test plan: