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

[BUG]: Cannot redefine key #107

Open
carlosmfreitas2409 opened this issue Nov 12, 2024 · 11 comments · May be fixed by #109
Open

[BUG]: Cannot redefine key #107

carlosmfreitas2409 opened this issue Nov 12, 2024 · 11 comments · May be fixed by #109
Labels
bug Something isn't working

Comments

@carlosmfreitas2409
Copy link

carlosmfreitas2409 commented Nov 12, 2024

Hello!

I have the following step (exactly as it says in the README):

- name: Setup bun
  uses: oven-sh/setup-bun@v2
  with:
    bun-version: 1.1.26
    registry-url: https://npm.pkg.github.com/
    scope: '@my-org'

- name: Install dependencies
  env:
    BUN_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: bun install --frozen-lockfile

And when running the workflow, the following error occurs:
Image

The bunfig.toml was created automatically by the action and looks like this:

[install.scopes]
'@my-org' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com/"}

There is an issue with this problem (#33), but it is closed and without a solution.

@Yurchishin
Copy link

Fix Summary

I resolved an issue related to package installation in the CI/CD pipeline. Here's how:

  1. Avoid committing .npmrc
    Remove or avoid committing the .npmrc file. For reasons I couldn't fully determine, having .npmrc with bunfig.toml in the repository caused configuration issues on the CI/CD side.

  2. Commit a custom bunfig.toml file
    To enable local package installation, create and commit a bunfig.toml file with the following content and commit it:

    [install.scopes]
    '@my-org' = { token = "$BUN_AUTH_TOKEN", url = "https://npm.pkg.github.com" }
  3. Set up a .env file for local development
    Ensure you have a .env file locally to define the BUN_AUTH_TOKEN for authentication:

    BUN_AUTH_TOKEN=******
  4. Update your CI/CD workflow
    Use the following configuration in your GitHub Actions workflow to install dependencies:

    - name: Install Bun
      uses: oven-sh/setup-bun@v2
    - name: Install Dependencies
      run: bun install --frozen-lockfile
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Optional
        NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Optional
        BUN_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

@xhyrom
Copy link
Collaborator

xhyrom commented Nov 16, 2024

We should probably create some sort of merge mechanic like in #39

@xhyrom xhyrom added the bug Something isn't working label Nov 16, 2024
@xhyrom xhyrom linked a pull request Nov 16, 2024 that will close this issue
@xhyrom
Copy link
Collaborator

xhyrom commented Nov 16, 2024

Hi @carlosmfreitas2409 and @Yurchishin, could you please test my PR fixing this issue? I think oven-sh/setup-bun@feat/multiple-registries or oven-sh/setup-bun@7ac6e6faeade3b75e9bff88d66e9200170e311cd should work :)

@carlosmfreitas2409
Copy link
Author

Hi @Yurchishin and @xhyrom

First of all, thanks for the answers guys!

To update you guys. I didn't have any bunfig.toml in my repository, however, in the workflow I'm using setup-bun, there's another step later (changesets) that needs to update some files in the repository and then pushes those changes, creating a new pull request.

Since the Bun action creates the bunfig.toml file, the later step was committing the config file to the PR (and I merged).

So the first time, when bunfig.toml hadn't been merged, the install step worked without any problems.
And after merged, the install step started giving the redefine key error.


Even though I was committing the file that is being created from the action, I think this should not happen, right? (I could be wrong)

Because theoretically, if I create the file manually, it will have the same content/code that the action created and the same error would happen again (I haven't tested this).

So the temporary solution I had was to delete the bunfig.toml file after the install deps step and it works fine.

I will test if your PR resolves it in a few hours @xhyrom, thank you so much!

@xhyrom
Copy link
Collaborator

xhyrom commented Nov 18, 2024

Thanks, I wonder that we should probably also handle this case by removing the bunfig at the end / reverthing the content of the file 🤔

@carlosmfreitas2409
Copy link
Author

carlosmfreitas2409 commented Nov 18, 2024

Yes, I believe it would be important. However, it would not solve all cases (including this one).

Let's suppose that I wanted to publish a lib on the Github Registry and for that I need to use the registry-url. I will need bunfig.toml until the publish script runs.

  1. Setup bun (with registry-url)
  2. Install dependencies
  3. Run publish (need the registry-url)
  4. Post-setup bun (remove bunfig)

In the above step, it will work.

However, if between these steps we are using something that commits, bunfig will still be committed because the post-setup will not have been run yet. Example:

  1. Setup bun (with registry-url)
  2. Install dependencies
  3. Commit and push auto version changes (still have the bunfig)
  4. Run publish (need the registry-url)
  5. Post-setup bun (remove bunfig)

setup-bun/src/action.ts

Lines 46 to 48 in 8f1bc2e

export default async (options: Input): Promise<Output> => {
const bunfigPath = join(process.cwd(), "bunfig.toml");
writeBunfig(bunfigPath, options);

Maybe, instead of writing the bunfig file with process.cwd, there is some way to create it in temporarily directory? I think Github provide a RUNNER_TEMP and HOME env.

(I think this also refers to #99)

@xhyrom
Copy link
Collaborator

xhyrom commented Nov 19, 2024

Ohh, yes, you're right about this one, I'll see what we can do.

@csoylu

This comment has been minimized.

@xhyrom

This comment has been minimized.

@carlosmfreitas2409
Copy link
Author

carlosmfreitas2409 commented Nov 29, 2024

Hi @xhyrom

First of all, I apologize for the delay in testing your PR.

I tested it here and apparently it solves the problem of this issue, which is having bunfig.toml already created was not being able to install the dependencies (cannot redefine key error). And now it's possible, just needing to change the registry parameter.

- name: Setup bun
  uses: oven-sh/setup-bun@feat/multiple-registries
  with:
    bun-version: 1.1.34
    registries: |
      [
        {
          "registry-url": "https://npm.pkg.github.com/",
          "scope": "@repo",
          "token": "$BUN_AUTH_TOKEN"
        }
      ]

- name: Install dependencies
  env:
    BUN_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
  run: bun install --frozen-lockfile

However, the error in the previous comment, which is to create bunfig.toml in a temporary repository (because if I do a push, it will be published together), not yet.

But I believe this must be another issue, right?

--

Another thing that I saw is the possibility of a new parameter in the action, allowing to switch between bunfig.toml and .npmrc. This is maybe necessary because some actions do not yet support bunfig.toml, which ends up requiring .npmrc.

But I'm sure this should be another issue, so I created the #112

@xhyrom
Copy link
Collaborator

xhyrom commented Nov 30, 2024

Hey, thanks for testing the changes and creating new issue.

Before closing this issue as completed, I'll work on the changes to create bunfig.toml somewhere else to avoid accidentally pushing the config file.


Also, adding support for .npmrc might be a really nice addition. Definitely will look into it after this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants