semantic-release-action icon indicating copy to clipboard operation
semantic-release-action copied to clipboard

Support NPM config environment variables

Open wsams opened this issue 1 year ago • 2 comments

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/[email protected]
        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"]
              }]
            ]

wsams avatar May 04 '23 21:05 wsams

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!

codfish avatar May 22 '23 02:05 codfish

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/[email protected]
        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.

wsams avatar Jun 15 '23 23:06 wsams