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

Allow environment variable use in dictionary definitions #924

Closed
JonZeolla opened this issue Feb 7, 2021 · 5 comments
Closed

Allow environment variable use in dictionary definitions #924

JonZeolla opened this issue Feb 7, 2021 · 5 comments

Comments

@JonZeolla
Copy link

JonZeolla commented Feb 7, 2021

Is your feature request related to a problem? Please describe.
I am using cspell in a github action, and I would like to allow repositories that use the action to provide a custom dictionary in addition to the dictionaries that the action provides.

Describe the solution you'd like
I would like the ability to use environment variables in a dictionary definition path.

Describe alternatives you've considered
Attempted a partial workaround using ~, but that expands to the $HOME for the root user (/root), but we need the runner home dir. Using ~runner resulted in /rootrunner.

I also attempted to glob the directories that change per-github action user in the dictionary definition (with a hard coded home directory due to the above issue) via /home/runner/work/*/*/.github/etc/dictionary.txt and received the following:

Dictionary Error with (per-repository dictionary) Error: ENOENT: no such file or directory, open '/home/runner/work/*/*/.github/etc/dictionary.txt'

Note that dictionary.txt is anticipated to be in ${GITHUB_WORKSPACE}/.github/etc/dictionary.txt during the GitHub actions run. I was able to confirm that this file did exist there as expected during my testing; I have avoided any workarounds using symlinks so far.

Additional context
packages/cspell-lib/src/util/resolveFile.ts appears to have very specific support for ^~ only, which uses $HOME and is the closest support to this request that I could find.

@Jason3S
Copy link
Collaborator

Jason3S commented Feb 9, 2021

@JonZeolla,

Thank you for the suggestion.

I can see how using environment variables might be useful.

I am assuming you are using a cspell.json file in your repository to define the dictionary.

Things to note:

  • relative paths are ok: ~/../home/runner/ would result in /home/runner/ assuming $HOME is /root
  • You can always set the $HOME environment variable to point where you like in the github action before calling cspell.
  • By default, paths starting with ./ are relative to the cspell.json file they are defined in.

@Jason3S
Copy link
Collaborator

Jason3S commented Feb 9, 2021

I took a quick look at your pull request.

I see that the cspell config file is part of the action and not part of the repository. In that case relative path won't exactly work.

You can also use a cspell.config.js file instead of a .json file.

'use strict';

/** @type { import("@cspell/cspell-types").CSpellUserSettings } */
const cspell = {
    description: 'Example config using environment variables.',
    dictionaryDefinitions: [
        {
            name: 'repo-dict',
            path: `${process.env['GITHUB_WORKSPACE']}/.github/etc/dictionary.txt`,
        },
    ],
    dictionaries: ['repo-dict'],
};

module.exports = cspell;

@JonZeolla
Copy link
Author

Thank you, I will take a stab at moving to cspell.config.js and report back.

@JonZeolla
Copy link
Author

That worked wonderfully. Thank you!

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants