Skip to content

feat: add preview command to covector #187

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

Merged
merged 30 commits into from
May 5, 2021
Merged

feat: add preview command to covector #187

merged 30 commits into from
May 5, 2021

Conversation

minkimcello
Copy link
Collaborator

@minkimcello minkimcello commented Apr 8, 2021

Motivation

To continue the work of #179 and implement the actual preview command within covector. (179 set up the preview workflow and the basic conditionals within the action and covector to allow preview commands).

Approach

  • Made PR label configurable. If none is provided in the workflow it will use preview as default. You can specify your own like this:
    - name: covector preview
      uses: jbolda/covector/packages/action@mk/run-preview
      id: covector
      with:
        command: preview
        label: whateverLabel
    • If the preview workflow runs and the required label is not applied to the PR, it won't publish any preview packages.
  • Also made version template configurable. At the moment there are only two options: date and sha. If none is provided, the default will be date:
    - name: covector preview
      uses: jbolda/covector/packages/action@mk/run-preview
      id: covector
      with:
        command: preview
        label: whateverLabel
        previewVersion: sha
    • The templates look like this:
      • date = 1.0.0-${Date.now()} = 1.0.0-1618444347550
      • sha = 1.0.0-${commit.substring(0, 7)} = 1.0.0-abcdefg
  • Cleaned up commented out code from feat: preparations of covector/action for building and publishing preview packages #179
  • apply has a new argument that determines if a dependency bump should use its normal semver.inc(bumpType) or semver.valid(previewVersionTemplate)
    • But it looks like bumpDep is never triggered? See TODOs below.
  • preview command inside covector pretty much runs version and then publish but without deleting the change files or modifying the changelogs.
    • I also excluded postPublish command
  • Added preview label to the version PR creating step inside run-version-or-publish workflow to automatically opt-in to publishing preview packages. This takes care of "case 3"

TODOs

  • Generate comment on PR after publishing previews. Will do this in a separate PR. feat: pr comment generator for covector preview #191
  • I set the timeout to x2 the regular length because we're doing twice the work in preview. Should I keep it that way or just set it back to normal? No.
  • packagesPublished set here seems to always return an empty string on account of covectored[pkg].published boolean never being set. Separate PR
  • I wanted to see bumpDep in action so I ran the preview action with only change files for @covector/files hoping it'll update the @covector/files dependencies for apply, covector, assemble, and changelog but it only bumped covector, files, and action Fixed in bug: Fix bumping error #198:
Screenshot
  • How does env.NODE_AUTH_TOKEN get used? I can't find it in the action. I haven't been publishing any packages with covector yet but I'm guessing when it actually tries to publish it won't be authenticated yet.
  • I haven't done npm tags yet. Should I include that in this PR? Doesn't need to be in the same PR because pre-release semver won't be tagged as latest (1.0.0 will still be latest if you publish 1.0.1-12345) Separate PR

@minkimcello minkimcello added enhancement New feature or request and removed enhancement New feature or request labels Apr 9, 2021
@minkimcello minkimcello force-pushed the mk/run-preview branch 2 times, most recently from 2e9d04a to b6366fc Compare April 13, 2021 21:21
Base automatically changed from mk/previews to main April 13, 2021 23:06
@minkimcello minkimcello force-pushed the mk/run-preview branch 5 times, most recently from e6a75ef to b851087 Compare April 14, 2021 18:44
@minkimcello minkimcello changed the title [WIP] feat: add preview command to covector feat: add preview command to covector Apr 15, 2021
@minkimcello minkimcello marked this pull request as ready for review April 15, 2021 01:58
@cowboyd
Copy link
Collaborator

cowboyd commented Apr 15, 2021

How does this relate to when you have a preview, but no PR?

In other words, the mainline is v1, but we're working on v2, so everything on v2 should get released to a preview?

@minkimcello
Copy link
Collaborator Author

How does this relate to when you have a preview, but no PR?

In other words, the mainline is v1, but we're working on v2, so everything on v2 should get released to a preview?

Jacob is working on that part.

@jbolda
Copy link
Owner

jbolda commented Apr 16, 2021

Yep, prereleases coming in #180.

@jbolda
Copy link
Owner

jbolda commented Apr 19, 2021

packagesPublished set here seems to always return an empty string on account of covectored[pkg].published boolean never being set.

Seems like an oversight. We can probably open an issue and fix it in a separate PR.

I wanted to see bumpDep in action...

I believe the caveat here is that it will only bump the dependencies if the main package version also has a bump. Do you think that was the case? It is kind of hard to tell from that output.

How does env.NODE_AUTH_TOKEN get used? I can't find it in the action. I haven't been publishing any packages with covector yet but I'm guessing when it actually tries to publish it won't be authenticated yet.

The action/setup-node makes use of it. It sets a reference to that env var in the .nmprc if I recall correctly.

I haven't done npm tags yet. Should I include that in this PR? Doesn't need to be in the same PR because pre-release semver won't be tagged as latest (1.0.0 will still be latest if you publish 1.0.1-12345)

I am going to need this for prereleases as well. I think we can address this in a follow up PR.

@jbolda
Copy link
Owner

jbolda commented Apr 20, 2021

I wanted to see bumpDep in action...

I believe the caveat here is that it will only bump the dependencies if the main package version also has a bump. Do you think that was the case? It is kind of hard to tell from that output.

So say there's a change file to bump package-A (and none for package-B) but package-A is listed as a dependency in package-B, you're saying this is how it would look?:

{
  "name": "package-A",
  "version": "1.0.0-abcdef"
},
{
  "name": "package-B",
  "version": "1.0.0",
  "dependencies:": {
    "package-A": "1.0.0-abcdef"
  }
}

I believe it would look like:

{
  "name": "package-A",
  "version": "1.0.0-abcdef"
},
{
  "name": "package-B",
  "version": "1.0.0-abcdef",
  "dependencies:": {
    "package-A": "1.0.0-abcdef"
  }
}

The bump to package-A also creates a bump for package-B with a patch (or it will use whatever higher bump if you are already directly bumping package-B otherwise).

How does env.NODE_AUTH_TOKEN get used? I can't find it in the action. I haven't been publishing any packages with covector yet but I'm guessing when it actually tries to publish it won't be authenticated yet.

The action/setup-node makes use of it. It sets a reference to that env var in the .nmprc if I recall correctly.

I mean it gets passed into the action here but I can't find the instance of the action utilizing the variable.

The action/setup-node sets it in a config file here which npm publish then picks up on when it runs. If you were running it locally, you would like npm login and it would set that same token in a file that it references locally when publishing. If you check your HOME DIR for an .npmrc, it will contain something like this:

registry.npmjs.org/:_authToken={token-here}

So locally it gets hard-coded, but in CI, it relies on an env var so you can pass it in through your secrets.

@minkimcello
Copy link
Collaborator Author

I wanted to see bumpDep in action...

I believe the caveat here is that it will only bump the dependencies if the main package version also has a bump. Do you think that was the case? It is kind of hard to tell from that output.

So say there's a change file to bump package-A (and none for package-B) but package-A is listed as a dependency in package-B, you're saying this is how it would look?:

{
  "name": "package-A",
  "version": "1.0.0-abcdef"
},
{
  "name": "package-B",
  "version": "1.0.0",
  "dependencies:": {
    "package-A": "1.0.0-abcdef"
  }
}

I believe it would look like:

{
  "name": "package-A",
  "version": "1.0.0-abcdef"
},
{
  "name": "package-B",
  "version": "1.0.0-abcdef",
  "dependencies:": {
    "package-A": "1.0.0-abcdef"
  }
}

The bump to package-A also creates a bump for package-B with a patch (or it will use whatever higher bump if you are already directly bumping package-B otherwise).

Screen Shot 2021-04-14 at 9 51 10 PM

So if I have a change file for @covector/files, it should've applied bumps to @covector/apply, covector, @covector/assemble, and @covector/changelog but as you can see in the screenshot, it only applied bumps to @covector/files, covector, and @covector/action.

How does env.NODE_AUTH_TOKEN get used? I can't find it in the action. I haven't been publishing any packages with covector yet but I'm guessing when it actually tries to publish it won't be authenticated yet.

The action/setup-node makes use of it. It sets a reference to that env var in the .nmprc if I recall correctly.

I mean it gets passed into the action here but I can't find the instance of the action utilizing the variable.

The action/setup-node sets it in a config file here which npm publish then picks up on when it runs. If you were running it locally, you would like npm login and it would set that same token in a file that it references locally when publishing. If you check your HOME DIR for an .npmrc, it will contain something like this:

registry.npmjs.org/:_authToken={token-here}

So locally it gets hard-coded, but in CI, it relies on an env var so you can pass it in through your secrets.

So the setup-node action sets the config file and so for the rest of the workflow it would have access to config but why does the token need to be passed into covector's action?

- uses: actions/setup-node@v2
  with:
    registry-url: "https://registry.npmjs.org"
- name: git config
  run: |
    git config --global user.name "${{ github.event.pusher.name }}"
    git config --global user.email "${{ github.event.pusher.email }}"
- run: npm ci --ignore-scripts
- run: npm run build
- run: npm run pkg -w action
- name: covector version-or-publish
  uses: ./packages/action
  id: covector


  env:
    NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}


  with:
    token: ${{ secrets.GITHUB_TOKEN }}
    command: "version-or-publish"
    createRelease: true

@jbolda
Copy link
Owner

jbolda commented Apr 27, 2021

So if I have a change file for @covector/files, it should've applied bumps to @covector/apply, covector, @covector/assemble, and @covector/changelog but as you can see in the screenshot, it only applied bumps to @covector/files, covector, and @covector/action.

Hmm, to get the whole and properly bumping, we chain a few functions together. The only things I can guess are bug or we are missing one of those links in the chain?

So the setup-node action sets the config file and so for the rest of the workflow it would have access to config but why does the token need to be passed into covector's action?

- uses: actions/setup-node@v2
  with:
    registry-url: "https://registry.npmjs.org"
- name: git config
  run: |
    git config --global user.name "${{ github.event.pusher.name }}"
    git config --global user.email "${{ github.event.pusher.email }}"
- run: npm ci --ignore-scripts
- run: npm run build
- run: npm run pkg -w action
- name: covector version-or-publish
  uses: ./packages/action
  id: covector


  env:
    NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}


  with:
    token: ${{ secrets.GITHUB_TOKEN }}
    command: "version-or-publish"
    createRelease: true

It sets up the .npmrc with a value that references that env var instead of hard coding it.

@@ -300,12 +309,12 @@ const bumpMain = ({
if (pkg.vfile.extname === ".json") {
// for javascript
// @ts-ignore TODO bumpType should be narrowed to meet ReleaseType
let version = semver.inc(pkg.pkg.version, bumpType);
let version = previewVersion ? semver.valid(`${pkg.pkg.version}-${previewVersion}`) : semver.inc(pkg.pkg.version, bumpType);
Copy link
Owner

Choose a reason for hiding this comment

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

Can we add a couple tests in apply to confirm that version number that is output (and see we don't break it in the future)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

"}\n"
);

expect({
Copy link
Owner

Choose a reason for hiding this comment

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

Looking at the snapshot, consoleDir and consoleLog don't have any data, Is that expected? I presume there would be some output here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reason why there's no console log is because it's been omitted but I just added it here

},
"version": "0.6.2-branch-name.12345",
},
"version": "0.6.2-branch-name.12345",
Copy link
Owner

Choose a reason for hiding this comment

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

Looks like we are getting the version here 👍 . It doesn't seem like it is attempting to publish it though, I imagine because of the change files? May be worth creating a new fixture if it is painful finding one that works for your tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It doesn't seem like it is attempting to publish it though

Doesn't this mean it did try to publish?

Copy link
Owner

Choose a reason for hiding this comment

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

I was looking for something like "Checking if [email protected] is already published with: echo 0.5.2",, but not seeing it which is kind of confusing. Like I don't see any of the output mention trying to publish tauri.js.

Copy link
Owner

Choose a reason for hiding this comment

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

But yea, you are right, it does say "tauri.js [publish]: echo publishing tauri.js would happen here",. I wonder if it is worth checking the version there by adjusting that publish command to echo it out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So in that fixture, there's a change file for tauri and tauri-updater. tauri-updater isn't in the snapshot because publish is set to false. tauri.js gets a preview bump because it lists tauri as a dependency. But that doesn't explain why tauri isn't getting bumped and why tauri.js isn't trying to publish. This might have to do with the bug I pointed out about the interdependent bumping logic.

Comment on lines 1521 to 1538
Array [
"bumping package-b to 0.0.1-branch-name.12345 to publish a preview",
],
Array [
"bumping package-a to 0.0.1-branch-name.12345 to publish a preview",
],
Array [
"package-a [publish]: echo publishing package-a would happen here",
],
Array [
"publishing package-a would happen here",
],
Array [
"package-b [publish]: echo publishing package-b would happen here",
],
Array [
"publishing package-b would happen here",
],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this new fixture I have package-a and package-b and package-a has package-b as one of its dependencies. I added a changefile only for package-b to see if it'll bump the dependency inside package-a.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So maybe the issue we saw earlier comes from when different managers are mixed in together?

Copy link
Owner

Choose a reason for hiding this comment

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

So maybe the issue we saw earlier comes from when different managers are mixed in together?

That would be surprising to me. It might be worth adding a package-c with the same manager as your change to confirm?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

should package-c have any dependencies? or have it be added as a dependency to package-a or package-b?

Comment on lines +1555 to +1561
"pkg": Object {
"dependencies": Object {
"package-b": "0.0.1-branch-name.12345",
},
"name": "package-a",
"version": "0.0.1-branch-name.12345",
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

package-a

* Fix overlooked refactor of a variable in apply

* Rename package files in config to match the packages json files

* Reintroduce accidentally deleted toml file in fixtures

* Fix change files with the correct package names
Copy link
Owner

@jbolda jbolda left a comment

Choose a reason for hiding this comment

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

🙌

@minkimcello minkimcello merged commit 5506b19 into main May 5, 2021
@minkimcello minkimcello deleted the mk/run-preview branch May 5, 2021 18:19
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.

3 participants