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

Set Locale #762

Closed
BrightRan opened this issue Apr 21, 2020 · 20 comments
Closed

Set Locale #762

BrightRan opened this issue Apr 21, 2020 · 20 comments
Assignees
Labels
Area: Image administration investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Ubuntu

Comments

@BrightRan
Copy link

BrightRan commented Apr 21, 2020

In this ticket, the user wants to change the runner machine's locale language to PT-BR, he uses the below step to do set the locale:

      - name: SetLocale
        run: |
          sudo apt-get update && sudo apt-get install tzdata locales -y && sudo locale-gen pt_BR.UTF-8
          sudo localectl set-locale LANG="pt_BR.UTF-8"
          export LANG="pt_BR.UTF-8"
          sudo update-locale
          echo "Testing language settings"
          echo "All languages..."
          locale -a
          echo "Actual locale"
          locale
          echo "Actual numeric settings"
          locale -c -k LC_NUMERIC
          echo "LANG Variable"
          echo "$LANG"
          echo "LocaleCtl"
          localectl status
          echo "Printing decimal"
          printf "%'.3f\n" 123123,123

The locale language seems changed successfully, but when he tries to check the number formats and date formats, they are shown inconsistent with the locale language.

@TingluoHuang
Copy link
Member

I am able to repro the problem on a fresh Ubuntu 18.04 Azure VM without the runner at all.
Feels like a VM setup or OS problem.
Moving to the virtual-environment team for further investigation.

@TingluoHuang TingluoHuang transferred this issue from actions/runner Apr 22, 2020
@Darleev Darleev added Area: Image administration investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Ubuntu and removed needs triage labels Apr 22, 2020
@dsame dsame self-assigned this Apr 23, 2020
@dsame
Copy link
Contributor

dsame commented Apr 23, 2020

printf is built in command of bash and a bash process does not catch up the locale settings changed within the same process.

The following code in the above workflow works as expected

          echo "Printing decimal in child shell"
          /bin/bash -c "printf \"%'.3f\n\" 123123,123"

@hugoj-goncalves
Copy link

@dsame
I can't really say that I understand but it's cool that it works that way. I'm no linux expert at all.
Why is it different from running these commands locally/in a docker?
As I'm using without a problem in those two situations.
Would it work if I create a shell script with everything inside, or would I still need to call /bin/bash -c for everything I need localized?

@maxim-lobanov
Copy link
Contributor

@hugoj-goncalves , I believe it will also work if we use different steps for setting locale and testing it because the second step will be new shell session:

- name: SetLocale
  run: |
          sudo apt-get update && sudo apt-get install tzdata locales -y && sudo locale-gen pt_BR.UTF-8
          sudo localectl set-locale LANG="pt_BR.UTF-8"
          export LANG="pt_BR.UTF-8"
          sudo update-locale
          locale -a
          locale
          locale -c -k LC_NUMERIC
          localectl status
- name: Test
  run: |
          echo "Printing decimal"
          printf "%'.3f\n" 123123,123

@hugoj-goncalves
Copy link

@maxim-lobanov That definitely is not the case as my first test was like that 😞
I had a SetLocale step and a SetTime step which I just used date command to check if timezone was okay.
image
As you can see it didn't print date respecting the locale change.

@al-cheb
Copy link
Contributor

al-cheb commented Apr 23, 2020

@hugoj-goncalves

env:
  LANG: "pt_BR.UTF-8"
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: pt_BR.UTF-8
      run: |
          sudo locale-gen pt_BR.UTF-8
          sudo update-locale LANG=pt_BR.UTF-8
    - name: date
      run: |
          date

time - Copy

@hugoj-goncalves
Copy link

hugoj-goncalves commented Apr 23, 2020

@al-cheb oh wow...
would've never guessed it tough
everything worked just fine that way (just the printf thing that needs the bash -c to work)

image

It's still a little confusing for me but I guess this issue is solved. Sorry about the trouble.

@galaxy4public
Copy link

galaxy4public commented Apr 28, 2020

Just in case somebody stumbles on this thread, the following command in the above comments does not seem right:

sudo locale-gen pt_BR.UTF-8

Since locale-gen is a bash script and it does not take arguments. All it does is that it loads /etc/locale.gen and rebuilds locales specified over there.

@al-cheb
Copy link
Contributor

al-cheb commented Apr 28, 2020

@galaxy4public, Just for example:

$ locale-gen NOTFOUNDLOCALE
Error: 'NOTFOUNDLOCALE' is not a supported language or locale

Find a parameter $1:

$ cat /usr/sbin/locale-gen | grep 'is not a supported'
        echo "Error: '$1' is not a supported language or locale" >&2

As you can see $1 is the first argument

$ sudo locale-gen fr_FR.UTF-8
Generating locales (this might take a while)...
  fr_FR.UTF-8... done
Generation complete.

$ sudo locale-gen --lang fr_FR.UTF-8
Generating locales (this might take a while)...
  fr_FR.UTF-8... done
Generation complete.

@galaxy4public
Copy link

Well, I trust that on your system it works like you showcased, however Ubuntu's man page does not mention such a behaviour and other distros do not follow it too (e.g. on Archlinux the script is pretty simple and does not respect any arguments to locale-gen)

@AlenaSviridenko
Copy link
Contributor

Hi! I am closing this issue since the original question was solved.
Please, feel free to file a new ticket if you have any other issues with locale.
Thank you!

glensc added a commit to glensc/php-zf1s that referenced this issue Dec 3, 2020
glensc added a commit to glensc/php-zf1s that referenced this issue Dec 7, 2020
@robinmatz
Copy link

Hey,

I am experiencing some issues related to the locale settings inside a GitHub Actions pipeline. I am trying to run test cases with x3270 using Robotframework. This is the link to my fork.

This is what the .yml looks like:

# This workflow runs the test suites with different versions of python
name: tests

on: [push, pull_request]

env:
  LANG: "en_US.UTF-8"
  LANGUAGE: "en_US:en"
  LC_ALL: "en_US.UTF-8"

jobs:
  tests:
    
    runs-on: ubuntu-latest

    strategy:
      matrix:
        python-version: [3.7, 3.9]

    steps:
    - uses: actions/checkout@v2

    - name: Set up python
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install dependencies
      run: |
        sudo apt-get install -y xvfb x3270 locales
        python -m pip install -r robotframework_mainframe3270.egg-info/requires.txt
        
    - name: Run tests
      run: |
        sudo locale-gen ${{ env.LANG }}
        sudo update-locale LANG=${{ env.LANG }}
        xvfb-run robot --exclude No-CI --loglevel DEBUG tests
    
    - uses: actions/upload-artifact@v2
      if: ${{ always() }}
      with:
        name: Tests results python${{ matrix.python-version }}
        path: |
          log.html
          report.html
          output.xml

This is the error I am getting:

image

I am struggling to understand why the encoding is not set correctly. Any help would be very much appreciated!

@al-cheb
Copy link
Contributor

al-cheb commented Dec 15, 2021

Hey, @robinmatz
The tests hang locally at Test With Login:

sudo locale-gen en_US
LANG=en_US.iso88591 xvfb-run robot --exclude No-CI --loglevel DEBUG tests

image

@robinmatz
Copy link

robinmatz commented Dec 15, 2021

Hi @al-cheb, the solution you provided worked perfectly. Thank you so much!

As for the tests hanging: Test With Login prompt for user input and should have been skipped in pipeline execution. In tests/mainframe.robot it should look like this:

Test With Login
    [Tags]    No-CI
    Test Send Enter
    Test Send PF

I assume you checked out from master, where the file had not yet been adapted.

Just out of curiosity:
I also tried

sudo locale-gen en_US.UTF-8
LANG=en_US.UTF-8 xvfb-run robot --exclude No-CI --loglevel DEBUG tests

But that also resulted in the original error. Why is that?

@al-cheb
Copy link
Contributor

al-cheb commented Dec 16, 2021

@insinfo
Copy link

insinfo commented Aug 16, 2023

@BrightRan @al-cheb @robinmatz
I am experiencing some issues related to the locale settings inside a GitHub Actions pipeline. I am trying to run test cases with pt_BR.CP1252 locale

    steps:
      - name: SetLocale
        run: |
          sudo apt-get update && sudo apt-get install tzdata locales -y   
          sudo localedef -f CP1252 -i /usr/share/i18n/locales/pt_BR /usr/lib/locale/pt_BR.CP1252
          sudo locale-gen pt_BR.UTF-8      
          sudo locale-gen pt_BR.CP1252
          sudo locale-gen
          locale -a
          echo "Actual locale"
          locale
          echo "Actual numeric settings"
          locale -c -k LC_NUMERIC
          echo "LANG Variable"
          echo "$LANG"
          echo "LocaleCtl"
          localectl status

i am getting this error:
Error: 'pt_BR.CP1252' is not a supported language or locale
image
https://github.com/insinfo/postgres_fork/actions/runs/5879086761/job/15942427559
do any of you know how i can solve this?

@vpolikarpov-akvelon
Copy link
Contributor

Hey @insinfo. locale-gen is just a shell script and it is quite straightforward. If it says that this locale is not supported then it is. You may try adding your locale to the list of supported, like this:

echo "pt_BR.CP1252 CP1252" | sudo tee -a /usr/share/i18n/SUPPORTED

I'm not sure that this is correct but at least it makes script completing with no error.

@insinfo
Copy link

insinfo commented Aug 17, 2023

Thank you for your help.

I updated like this and now it seems to be working

  steps:
      - name: SetLocale
        run: |
          sudo apt-get update && sudo apt-get install tzdata locales -y   
          sudo localedef -f CP1252 -i /usr/share/i18n/locales/pt_BR /usr/lib/locale/pt_BR.CP1252
          sudo echo 'pt_BR.CP1252 CP1252' | sudo tee -a /etc/locale.gen > /dev/null  
          sudo mkdir /usr/local/share/i18n
          sudo touch /usr/local/share/i18n/SUPPORTED
          sudo echo 'pt_BR.CP1252 CP1252' | sudo tee -a /usr/local/share/i18n/SUPPORTED > /dev/null  
          sudo locale-gen pt_BR.UTF-8      
          sudo locale-gen pt_BR
          sudo locale-gen
          locale -a
          echo "Actual locale"
          locale
          echo "Actual numeric settings"
          locale -c -k LC_NUMERIC
          echo "LANG Variable"
          echo "$LANG"
          echo "LocaleCtl"
          localectl status

https://github.com/insinfo/postgres_fork/blob/master/.github/workflows/dart.yml

britodfbr added a commit to incolume-jedi/coding-dojo that referenced this issue May 23, 2024
@michaelviveiros
Copy link

Estou recebendo erro também, porém o meu yml é escrito para o .NET Framework 4.8, alguém teria a solução por favor ?

name: CI - Run Unit Tests

on:
push:
branches:
- 'development'
- 'homologation'
- 'feature/'
- 'main'
pull_request:
branches:
- 'development'
- 'homologation'
- 'feature/
'
- 'main'

env:
LANG: "pt_BR.UTF-8"

jobs:
build:
runs-on: windows-latest

steps:
  - name: Checkout Code
    uses: actions/checkout@v4

  - name: Setup MSBuild
    uses: microsoft/setup-msbuild@v1.0.2

  - name: Install NuGet
    uses: NuGet/setup-nuget@v1.0.5

  - name: Install Visual Studio Build Tools
    run: |
      choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Workload.WebBuildTools --includeRecommended --includeOptional" --yes
  - name: Restore NuGet Packages
    run: nuget restore test.sln

  - name: Build Solution
    run: msbuild test.sln /p:Configuration=Release
    
  - name: Set Locale to pt-BR
    shell: pwsh
    run: |
      $env:DOTNET_CLI_TELEMETRY_OPTOUT = 1
      $env:LANG = "pt_BR.UTF-8"
      dotnet --info

  - name: Run Unit Tests
    run: dotnet test test.csproj --no-build --configuration Release

@michaelviveiros
Copy link

Discussion Number: #10067

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Image administration investigate Collect additional information, like space on disk, other tool incompatibilities etc. OS: Ubuntu
Projects
None yet
Development

No branches or pull requests