Skip to content

Commit

Permalink
Fix testing in GH actions
Browse files Browse the repository at this point in the history
* use alternativ '.gitconfig' to avoid corruption of users $HOME/.gitconfig when
  test env requires global config options and started by user while
  development process

* added 'protocol.file.allow always' to git fixtures config as
  workaround for
  https://github.blog/2022-10-18-git-security-vulnerabilities-announced/#cve-2022-39253

* improved handling of locales in testing for github actions

* update to checkout v3 for github actions
  • Loading branch information
M0ses committed Nov 2, 2022
1 parent a5d025d commit 026bf0e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ jobs:
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Install required dpkg packages
run: sudo apt-get install libxslt1-dev bzr subversion mercurial

- name: Generate default locales
run: |
sudo locale-gen "en_US.UTF-8"
sudo apt-get update && sudo apt-get install tzdata locales -y && sudo locale-gen "en_US.UTF-8"
sudo dpkg-reconfigure locales
sudo update-locale "LANG=en_US.UTF-8"
sudo update-locale "LC_ALL=en_US.UTF-8"
Expand Down
9 changes: 8 additions & 1 deletion tests/gitfixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ class GitFixtures(Fixtures):
def init(self):
self.user_name = 'test'
self.user_email = 'test@test.com'

tmpdir = os.path.join(os.path.dirname(
os.path.abspath(__file__)), 'tmp')
gitconfig = os.path.join(tmpdir, '.gitconfig')
os.environ["GIT_CONFIG_GLOBAL"] = gitconfig
self.safe_run('config --global protocol.file.allow always')
self.safe_run('config --global commit.gpgsign false')

self.create_repo(self.repo_path)
self.wdir = self.repo_path
self.submodules_path = self.container_dir + '/submodules'
Expand All @@ -40,7 +48,6 @@ def create_repo(self, repo_path):
self.safe_run('init')
self.safe_run('config user.name ' + self.user_name)
self.safe_run('config user.email ' + self.user_email)
self.safe_run('config commit.gpgsign false')
print("created repo %s" % repo_path)

def get_metadata(self, fmt):
Expand Down
29 changes: 25 additions & 4 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io
import shutil
import subprocess
import sys
import six


Expand All @@ -22,12 +23,32 @@ def mkfreshdir(path):
os.makedirs(path)
os.chdir(cwd)

def check_locale(loc):
try:
aloc_tmp = subprocess.check_output(['locale', '-a'])
except AttributeError:
aloc_tmp, _ = subprocess.Popen(['locale', '-a'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT).communicate()
aloc = {}

for tloc in aloc_tmp.split(b'\n'):
aloc[tloc] = 1

for tloc in loc:
print("Checking .... %s"%tloc, file=sys.stderr)
try:
if aloc[tloc.encode()]:
return tloc
except KeyError:
pass

return 'C'

def run_cmd(cmd):
os.putenv('LANG', 'C.utf-8')
os.putenv('LC_ALL', 'C.utf-8')
os.environ['LANG'] = 'C.utf-8'
os.environ['LC_ALL'] = 'C.utf-8'
use_locale = check_locale(["en_US.utf8", 'C.utf8'])
os.environ['LANG'] = use_locale
os.environ['LC_ALL'] = use_locale
if six.PY3:
cmd = cmd.encode('UTF-8')
proc = subprocess.Popen(
Expand Down

0 comments on commit 026bf0e

Please sign in to comment.