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

Support NPM config environment variables #188

Open
wsams opened this issue May 4, 2023 · 2 comments
Open

Support NPM config environment variables #188

wsams opened this issue May 4, 2023 · 2 comments

Comments

@wsams
Copy link

wsams commented May 4, 2023

I have a workflow running on a GitHub Enterprise runner and need to override certain NPM directories/files like ~/.npm and ~/.npmrc.

The step below shows the environment variables I use in other actions. But for some reason the default ~/.npm location is being used instead of /home/github/npm_cache. If I exec into the container running this job, and set those environment variables manually, /home/github/npm_cache will be used correctly.

Does anyone know if these environment variables, NPM_CONFIG_PREFIX and NPM_CONFIG_GLOBALCONFIG, can be used with this action? Or another way to override them?

      - name: NPM configuration
        run: |
          echo '${{ secrets.NPMRC }}' | base64 -d > /home/github/.npmrc
          echo 'cache=/home/github/npm_cache' >> /home/github/.npmrc

      - name: Semantic Release
        id: semantic-release
        uses: codfish/semantic-release-action@v2.1.0
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
          GIT_CONFIG_GLOBAL: /home/github/.gitconfig
          NPM_CONFIG_PREFIX: /home/github/node_modules
          NPM_CONFIG_GLOBALCONFIG: /home/github/.npmrc
        with:
          branches: |
            [
              "main"
            ]
          additional_packages: |
            [
              "@google/semantic-release-replace-plugin",
              "@semantic-release/git"
            ]
          plugins: |
            [
              "@semantic-release/commit-analyzer",
              "@semantic-release/release-notes-generator",
              ["@semantic-release/github", {
                "githubUrl": "https://test.github.example.com",
                "githubApiPathPrefix": "/api/v3"
              }],
              ["@google/semantic-release-replace-plugin", {
                "replacements": [
                  {
                    "files": ["Chart.yaml"],
                    "from": "version: .*",
                    "to": "version: ${nextRelease.version}",
                    "results": [
                      {
                        "file": "Chart.yaml",
                        "hasChanged": true,
                        "numMatches": 1,
                        "numReplacements": 1
                      }
                    ],
                    "countMatches": true
                  }
                ]
              }],
              ["@semantic-release/git", {
                  "assets": ["Chart.yaml"]
              }]
            ]
@codfish
Copy link
Owner

codfish commented May 22, 2023

hey @wsams, not sure honestly, this is a Docker action so that might complicate things but I believe anything you set under env and with are being passed in as environment variables so they are accessible within the container.

so I don't think this action is necessarily the blocker here. i think something else might be at play but I don't have enough knowledge on enterprise runners and what the home directory is in and outside of docker actions..

You could take a look at your step outputs and see what is being passed into the semantic step, i.e. https://github.com/codfish/actions-playground/actions/runs/4589554453/jobs/8104523903#step:11:94 ... that might help illuminate what the issue is.

Sorry I couldn't provide a solution, let me know if you figure it out!

@wsams
Copy link
Author

wsams commented Jun 15, 2023

Hi @codfish , I still haven't been able to resolve that issue, but today I tried to use the semantic-release-docker plugin. It appears to be running fine but then cannot access the environment variables DOCKER_USERNAME and DOCKER_PASSWORD. In this case I have,

      - name: Semantic Release
        uses: codfish/semantic-release-action@v2.1.0
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN_ADMIN_PASSWORD }}
          GIT_CONFIG_GLOBAL: /home/github/.gitconfig
          DOCKER_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
        with:
          branches: |
            [
              'main'
            ]
          plugins: |
            [
              "@semantic-release/commit-analyzer",
              "@semantic-release/release-notes-generator",
              [
                "@semantic-release/github",
                {
                  "githubUrl": "https://github.enterprise",
                  "githubApiPathPrefix": "/api/v3"
                }
              ],
              [
                "semantic-release-docker",
                {
                  "registryUrl": "docker.io",
                  "name": "foo/bar"
                }
              ]
            ]
          additional_packages: |
            [
              "semantic-release-docker"
            ]

I suppose it could be the enterprise runners, but we use environment variables all over the place with many different actions. If you think of anything else I'd love to hear it. I can't figure out what's going on.

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

No branches or pull requests

2 participants