msys2 / setup-msys2

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

Is it possible to call msys2 from bash? #279

Closed radioactiveman closed 1 year ago

radioactiveman commented 1 year ago

The current GitHub actions for Audacious support Ubuntu and macOS with a build matrix. I would like to add Windows here with MSYS2.

Attempt: https://github.com/radioactiveman/audacious/commit/30316531e669d393463eb3ff30aa1ccb11759a18 -> Job run: https://github.com/radioactiveman/audacious/actions/runs/3982612562/jobs/6827228075

The MSYS2 Meson command works fine when running from PowerShell (see 'Configure v1'), but I would like to reuse the bash script run-action.sh on all platforms. Is this somehow possible?

Currently the step 'Configure v2' fails with: /usr/bin/bash: line 1: meson: command not found

Any help or suggestions are appreciated. Thanks. :)

Biswa96 commented 1 year ago

I am not sure why it was written that way. Generally, I copy this template https://www.msys2.org/docs/ci/ and build on top of that. If there is a build procedure in that project I can try to add msys2 actions.

radioactiveman commented 1 year ago

It's written that way to share most of the logic and avoid a ton of similar workflow steps with conditions for the OS and build system.

Idea: 1. configure 2. build 3. test 4. install

instead of 1. configure (Meson, Ubuntu) 1. configure (Autotools, Ubuntu) 1. configure (Meson, macOS) 1. configure (Autotools, macOS) ...

My idea is to add only the msys2/setup-msys2@v2 step in the existing workflow and handle everything else in the custom actions.

Adding a separate workflow.yml file for MSYS2 is not the issue. I don't need assistance there, thanks. :) But is it possible to call MSYS2 from the action which is started in a bash shell?

Edit: Or asked differently: Is this (working) PowerShell step also possible with Bash? msys2 is not available and msys2.cmd does not find Meson, as mentioned initially.

msys2 -c 'meson setup build'
  shell: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.EXE -command ". '{0}'"
  env:
    MSYSTEM: MINGW32
radioactiveman commented 1 year ago

The solution is to run the script with the MSYS2 shell instead of bash on Windows. This is easy since composite actions also support if conditions meanwhile.

Example:

steps:
  - run: '$GITHUB_ACTION_PATH/run-action.sh "${{ inputs.action }}" "${{ inputs.os }}" "${{ inputs.build-system }}"'
    if: (!startsWith(inputs.os, 'windows'))
    shell: bash

  - run: '$GITHUB_ACTION_PATH/run-action.sh "${{ inputs.action }}" "${{ inputs.os }}" "${{ inputs.build-system }}"'
    if: startsWith(inputs.os, 'windows')
    shell: msys2 {0}

Changes for Audacious Plugins: https://github.com/audacious-media-player/audacious-plugins/commit/95cee3dd3863b96e467a16621ecdc92f95852254 --> Slim workflow file for all platforms / build systems.

Marking as solved. :)