msys2 / setup-msys2

GitHub Action to setup MSYS2
https://github.com/marketplace/actions/setup-msys2
MIT License
282 stars 37 forks source link

Provide alternative for $GITHUB_PATH inside MSYS2 with path-type: minimal #347

Open takase1121 opened 6 months ago

takase1121 commented 6 months ago

I want to use path-type: minimal (the default), but I want to be able to add things to PATH like appending to $GITHUB_PATH does. I don't want to inherit $env:PATH entirely.

Currently, a workaround I use is to do echo 'export PATH=$PATH:/blabla' >> .bashrc, which I don't think is as elegant as the $GITHUB_PATH solution. I propose $MSYS2_PATH as the equivalent to $GITHUB_PATH in MSYS2.

Biswa96 commented 6 months ago

Currently, a workaround I use is to do echo 'export PATH=$PATH:/blabla' >> .bashrc

May I ask why you are using that workaround? Would not the export PATH=path/to/folder:$PATH command work?

takase1121 commented 6 months ago

I've not thought of that and I'm unsure if that would work. My rationale is that I would add my path directly to PATH by exporting it in .bashrc. I'm not sure if the changes are inherited in next steps (that's what I want).

Biswa96 commented 6 months ago

I'm not sure if the changes are inherited in next steps (that's what I want).

Yes, the changes are "inherited" in next steps if you are using shell: msys2 {0} option in actions yml file as documented here https://www.msys2.org/docs/ci/

takase1121 commented 6 months ago

That did not seem to work. Here is a snippet of what I am doing:

  build_windows_msys2:
    name: Windows
    runs-on: windows-2019
    strategy:
      matrix:
        config:
          - {msystem: MINGW32, arch: i686}
          - {msystem: MINGW64, arch: x86_64}
    defaults:
      run:
        shell: msys2 {0}
    steps:
    - uses: actions/checkout@v3

    - uses: msys2/setup-msys2@v2
      with:
        msystem: ${{ matrix.config.msystem }}
        release: false
        install: >-
          git
          zip
          wget
          curl
          mingw-w64-${{ matrix.config.arch }}-gcc
          mingw-w64-${{ matrix.config.arch }}-ntldd

    - name: Set Environment Variables
      run: |
        echo "INSTALL_REF=${GITHUB_REF##*/}" >> "$GITHUB_ENV"
        echo "INSTALL_NAME=lite-xl-${GITHUB_REF##*/}-windows-${{ matrix.config.arch }}" >> "$GITHUB_ENV"
        export PATH="$PATH:$HOME/.local/bin:$USERPROFILE/.local/bin:$(cygpath '${{ steps.git-path.outputs.path }}')"

    - uses: actions/setup-python@v4
      id: install-python
      with:
        python-version: '3.11'

    - name: Cache Poetry and other build tools
      id: build-tools
      uses: actions/cache@v3
      with:
        path: ~/.local
        key: build-tools-msys2-${{ runner.os }}-${{ steps.install-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

    - name: Install Poetry
      if: steps.build-tools.outputs.cache-hit != 'true'
      uses: snok/install-poetry@v1

    - name: Configure Poetry
      run: |
        echo "$PATH" # does not have %USERPROFILE%/.local/bin and ~/.local/bin
        poetry config virtualenvs.path "$(cygpath -w "$USERPROFILE/.local/virtualenvs")"

Hopefully this explains my intentions better.

Biswa96 commented 6 months ago

Now I wonder why poetry need additional directories in PATH environment variable. But that would be different topic. Please wait for other to comment on this issue.

silverqx commented 2 months ago

I have exactly the same problem, exporting the same path in every step isn't ideal, in every other shell env. I can add to GITHUB_PATH once and that's it, but on MSYS2 it doesn't work like that of course.

silverqx commented 2 months ago

Appending to .bashrc is a nice workaround for this problem, thx

silverqx commented 2 months ago

Also, would be nice to have eg. path parameter on msys2/setup-msys2 action and it should do this work for us behind the scene.