From 56967422d390104ef308abf1b977d5b8b8809ffd Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Sun, 21 Sep 2025 09:45:08 -0700 Subject: [PATCH 1/4] use GITHUB_ACTION_PATH instead of github.action_path Signed-off-by: Jade Abraham --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index e8c75e1..ed5167b 100644 --- a/action.yml +++ b/action.yml @@ -73,7 +73,7 @@ runs: COMPILER: ${{ inputs.compiler }} VERSION: ${{ inputs.version }} run: | - cd $(echo '/${{ github.action_path }}' | sed -e 's/\\/\//g' -e 's/://') + cd $(echo "$GITHUB_ACTION_PATH" | sed -e 's/\\/\//g' -e 's/://') source ./main.sh if [[ "${{ inputs.update-environment }}" == "true" ]]; then From f6288e6c6f5b689aa1aa31972615d80dbc90e32c Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Sun, 21 Sep 2025 10:00:17 -0700 Subject: [PATCH 2/4] Avoid sudo if its missing Signed-off-by: Jade Abraham --- setup-fortran.sh | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/setup-fortran.sh b/setup-fortran.sh index 5633e97..03f4fc5 100755 --- a/setup-fortran.sh +++ b/setup-fortran.sh @@ -2,6 +2,15 @@ set -ex +if command -v sudo > /dev/null 2>&1; then + SUDO=sudo +else + if [[ $EUID -ne 0 ]]; then + echo "This script requires 'sudo' to install packages. Please install 'sudo' or run as root." + exit 1 + fi +fi + require_fetch() { if command -v curl > /dev/null 2>&1; then @@ -18,7 +27,7 @@ require_fetch() # https://github.com/cea-hpc/modules install_environment_modules_apt() { echo "Installing environment-modules package..." - sudo apt-get install -y environment-modules + $SUDO apt-get install -y environment-modules echo "Environment-modules installed." echo "Sourcing modules.sh script to set up environment modules..." source /etc/profile.d/modules.sh @@ -53,8 +62,8 @@ install_gcc_brew() install_gcc_apt() { if [ "$version" == "latest" ]; then - sudo apt-get update - sudo apt-get install -y gcc gfortran g++ + $SUDO apt-get update + $SUDO apt-get install -y gcc gfortran g++ else # Check whether the system gcc version is the version we are after. cur=$(apt show gcc | grep "Version" | cut -d':' -f3 | cut -d'-' -f1) @@ -68,15 +77,15 @@ install_gcc_apt() fi else # Install the PPA for installing other versions of gcc. - sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test - sudo apt-get update + $SUDO add-apt-repository --yes ppa:ubuntu-toolchain-r/test + $SUDO apt-get update fi if [ "${needs_install}" == "1" ]; then - sudo apt-get install -y gcc-${version} gfortran-${version} g++-${version} + $SUDO apt-get install -y gcc-${version} gfortran-${version} g++-${version} fi - sudo update-alternatives \ + $SUDO update-alternatives \ --install /usr/bin/gcc gcc /usr/bin/gcc-${version} 100 \ --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${version} \ --slave /usr/bin/gcov gcov /usr/bin/gcov-${version} \ @@ -367,25 +376,25 @@ install_intel_apt() require_fetch local _KEY="GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB" $fetch https://apt.repos.intel.com/intel-gpg-keys/$_KEY > $_KEY - sudo apt-key add $_KEY + $SUDO apt-key add $_KEY rm $_KEY echo "deb https://apt.repos.intel.com/oneapi all main" \ - | sudo tee /etc/apt/sources.list.d/oneAPI.list - sudo apt-get update + | $SUDO tee /etc/apt/sources.list.d/oneAPI.list + $SUDO apt-get update if [ "$version" == "latest" ]; then - sudo apt-get install -y \ + $SUDO apt-get install -y \ intel-oneapi-compiler-fortran \ intel-oneapi-compiler-dpcpp-cpp else # c/cpp compiler package names changed with 2024+ case $version in 2024* | 2025*) - sudo apt-get install -y \ + $SUDO apt-get install -y \ intel-oneapi-compiler-{fortran,dpcpp-cpp}-$version ;; *) - sudo apt-get install -y \ + $SUDO apt-get install -y \ intel-oneapi-compiler-{fortran,dpcpp-cpp-and-cpp-classic}-$version ;; esac @@ -453,7 +462,7 @@ install_intel_dmg() require_fetch $fetch $MACOS_HPCKIT_URL > m_HPCKit.dmg hdiutil attach m_HPCKit.dmg - sudo /Volumes/"$(basename "$MACOS_HPCKIT_URL" .dmg)"/bootstrapper.app/Contents/MacOS/bootstrapper -s \ + $SUDO /Volumes/"$(basename "$MACOS_HPCKIT_URL" .dmg)"/bootstrapper.app/Contents/MacOS/bootstrapper -s \ --action install \ --eula=accept \ --continue-with-optional-error=yes \ @@ -589,10 +598,10 @@ install_nvidiahpc_apt() # install NVIDIA HPC SDK echo "Installing NVIDIA HPC SDK $version..." - curl https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg - echo 'deb [signed-by=/usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' | sudo tee /etc/apt/sources.list.d/nvhpc.list - sudo apt-get update -y - sudo apt-get install -y nvhpc-$cversion + curl https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK | $SUDO gpg --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg + echo 'deb [signed-by=/usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' | $SUDO tee /etc/apt/sources.list.d/nvhpc.list + $SUDO apt-get update -y + $SUDO apt-get install -y nvhpc-$cversion echo "NVIDIA HPC SDK $version installed." # load NVIDIA HPC SDK module From 2f7629fed145c8fb785dc67328197992933d2de5 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Sun, 21 Sep 2025 18:20:37 -0700 Subject: [PATCH 3/4] Fix windows issues Signed-off-by: Jade Abraham --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index ed5167b..c95e316 100644 --- a/action.yml +++ b/action.yml @@ -73,7 +73,7 @@ runs: COMPILER: ${{ inputs.compiler }} VERSION: ${{ inputs.version }} run: | - cd $(echo "$GITHUB_ACTION_PATH" | sed -e 's/\\/\//g' -e 's/://') + cd $(echo "/$GITHUB_ACTION_PATH" | sed -e 's/\\/\//g' -e 's/://') source ./main.sh if [[ "${{ inputs.update-environment }}" == "true" ]]; then From 2351da580d5952282bf9ae9a4bafa898775b8815 Mon Sep 17 00:00:00 2001 From: Jade Abraham Date: Sun, 21 Sep 2025 21:15:01 -0700 Subject: [PATCH 4/4] use a function for sudo to avoid issues on windows Signed-off-by: Jade Abraham --- setup-fortran.sh | 54 ++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/setup-fortran.sh b/setup-fortran.sh index 03f4fc5..ff39c84 100755 --- a/setup-fortran.sh +++ b/setup-fortran.sh @@ -2,14 +2,18 @@ set -ex -if command -v sudo > /dev/null 2>&1; then - SUDO=sudo -else - if [[ $EUID -ne 0 ]]; then - echo "This script requires 'sudo' to install packages. Please install 'sudo' or run as root." - exit 1 +sudo_wrapper() { + if command -v sudo > /dev/null 2>&1; then + SUDO="sudo" + else + if [[ $EUID -ne 0 ]]; then + echo "This script requires 'sudo' to install packages. Please install 'sudo' or run as root." + exit 1 + fi + SUDO="" fi -fi + $SUDO "$@" +} require_fetch() { @@ -27,7 +31,7 @@ require_fetch() # https://github.com/cea-hpc/modules install_environment_modules_apt() { echo "Installing environment-modules package..." - $SUDO apt-get install -y environment-modules + sudo_wrapper apt-get install -y environment-modules echo "Environment-modules installed." echo "Sourcing modules.sh script to set up environment modules..." source /etc/profile.d/modules.sh @@ -62,8 +66,8 @@ install_gcc_brew() install_gcc_apt() { if [ "$version" == "latest" ]; then - $SUDO apt-get update - $SUDO apt-get install -y gcc gfortran g++ + sudo_wrapper apt-get update + sudo_wrapper apt-get install -y gcc gfortran g++ else # Check whether the system gcc version is the version we are after. cur=$(apt show gcc | grep "Version" | cut -d':' -f3 | cut -d'-' -f1) @@ -77,15 +81,15 @@ install_gcc_apt() fi else # Install the PPA for installing other versions of gcc. - $SUDO add-apt-repository --yes ppa:ubuntu-toolchain-r/test - $SUDO apt-get update + sudo_wrapper add-apt-repository --yes ppa:ubuntu-toolchain-r/test + sudo_wrapper apt-get update fi if [ "${needs_install}" == "1" ]; then - $SUDO apt-get install -y gcc-${version} gfortran-${version} g++-${version} + sudo_wrapper apt-get install -y gcc-${version} gfortran-${version} g++-${version} fi - $SUDO update-alternatives \ + sudo_wrapper update-alternatives \ --install /usr/bin/gcc gcc /usr/bin/gcc-${version} 100 \ --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${version} \ --slave /usr/bin/gcov gcov /usr/bin/gcov-${version} \ @@ -376,25 +380,25 @@ install_intel_apt() require_fetch local _KEY="GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB" $fetch https://apt.repos.intel.com/intel-gpg-keys/$_KEY > $_KEY - $SUDO apt-key add $_KEY + sudo_wrapper apt-key add $_KEY rm $_KEY echo "deb https://apt.repos.intel.com/oneapi all main" \ - | $SUDO tee /etc/apt/sources.list.d/oneAPI.list - $SUDO apt-get update + | sudo_wrapper tee /etc/apt/sources.list.d/oneAPI.list + sudo_wrapper apt-get update if [ "$version" == "latest" ]; then - $SUDO apt-get install -y \ + sudo_wrapper apt-get install -y \ intel-oneapi-compiler-fortran \ intel-oneapi-compiler-dpcpp-cpp else # c/cpp compiler package names changed with 2024+ case $version in 2024* | 2025*) - $SUDO apt-get install -y \ + sudo_wrapper apt-get install -y \ intel-oneapi-compiler-{fortran,dpcpp-cpp}-$version ;; *) - $SUDO apt-get install -y \ + sudo_wrapper apt-get install -y \ intel-oneapi-compiler-{fortran,dpcpp-cpp-and-cpp-classic}-$version ;; esac @@ -462,7 +466,7 @@ install_intel_dmg() require_fetch $fetch $MACOS_HPCKIT_URL > m_HPCKit.dmg hdiutil attach m_HPCKit.dmg - $SUDO /Volumes/"$(basename "$MACOS_HPCKIT_URL" .dmg)"/bootstrapper.app/Contents/MacOS/bootstrapper -s \ + sudo_wrapper /Volumes/"$(basename "$MACOS_HPCKIT_URL" .dmg)"/bootstrapper.app/Contents/MacOS/bootstrapper -s \ --action install \ --eula=accept \ --continue-with-optional-error=yes \ @@ -598,10 +602,10 @@ install_nvidiahpc_apt() # install NVIDIA HPC SDK echo "Installing NVIDIA HPC SDK $version..." - curl https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK | $SUDO gpg --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg - echo 'deb [signed-by=/usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' | $SUDO tee /etc/apt/sources.list.d/nvhpc.list - $SUDO apt-get update -y - $SUDO apt-get install -y nvhpc-$cversion + curl https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK | sudo_wrapper gpg --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg + echo 'deb [signed-by=/usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' | sudo_wrapper tee /etc/apt/sources.list.d/nvhpc.list + sudo_wrapper apt-get update -y + sudo_wrapper apt-get install -y nvhpc-$cversion echo "NVIDIA HPC SDK $version installed." # load NVIDIA HPC SDK module