#17 Openshift preps
Merged 3 years ago by jibecfed. Opened 3 years ago by darknao.
fedora-docs/ darknao/translations-scripts feature/openshift  into  master

file modified
+7 -2
@@ -13,7 +13,7 @@ 

  

  trap clean_tmp exit

  

- for staged in $(git status --porcelain); do

+ for staged in $(git diff --name-only --cached); do

      if [ "${staged##*.}" == "pot" ] ; then

          echo "$staged"

          git diff --no-ext-diff --cached --patch-with-raw --output="$output" "$staged"
@@ -25,7 +25,12 @@ 

  

          if [ "$countChanges" -eq $(("$countDateAdd" + "$countDateRem")) ] ; then

              echo "the file $staged only contains POT-Creation-Date"

-             git rm --cached "$staged"

+             git reset -q HEAD "$staged"

          fi

      fi

  done

+ 

+ if [ $(git diff --name-only --cached | wc -l) -eq 0 ]; then

+ 	echo "nothing to commit, aborting..."

+ 	exit 1

+ fi

file modified
+11 -12
@@ -1,12 +1,11 @@ 

- # asamalik/fedora-docs-translations

- 

- FROM fedora:29

- 

- RUN dnf -y install po4a vim git findutils tree

- 

- # Workaround: I need a patch for po4a that hasn't been released, yet.

- 

- RUN mkdir -p /usr/share/custom-po4a && \

-     git clone https://github.com/mquinson/po4a.git /usr/share/custom-po4a

- 

- ENV PERLLIB /usr/share/custom-po4a/lib

+ FROM fedora:32

+ RUN dnf -y install \

+         po4a \

+         git \

+         findutils \

+         python3-pyyaml \

+         "perl(YAML::Tiny)"

+ ENV HOME /workspace

+ COPY . /workspace

+ RUN chmod -R g+w /workspace

+ WORKDIR /workspace

file modified
+12 -11
@@ -123,7 +123,6 @@ 

      repo_dir = os.path.dirname(os.path.abspath(__file__)) + "/l10n/" + repo_name

  

      if os.path.exists(repo_dir):

-         subprocess.run(['git', 'reset', "--hard", "origin"], check=True, cwd=repo_dir)

          subprocess.run(['git', 'pull', "--quiet"], check=True, cwd=repo_dir)

      else:

          subprocess.run(["git", "clone", url, repo_dir, "--config",
@@ -139,7 +138,6 @@ 

      url = "https://pagure.io/fedora-docs/translated-sources.git"

  

      if os.path.exists(repo_dir):

-         subprocess.run(['git', 'reset', "--hard", "origin"], check=True, cwd=repo_dir)

          subprocess.run(['git', 'pull', "--quiet"], check=True, cwd=repo_dir)

      else:

          subprocess.run(["git", "clone", url, repo_dir, "--config",
@@ -160,10 +158,11 @@ 

              out = subprocess.run(['git', 'status', lang, '--porcelain'], check=True, cwd=repo_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

  

              if out.stdout.decode("utf-8") :

-                 subprocess.run(["git", "commit", "-m", "["+lang+"]automatic update of translated content", "--quiet"],

-                                 check=True, cwd=repo_dir)

- 

-                 subprocess.run(['git', 'push', "--quiet"], check=True, cwd=repo_dir)

+                 r_commit = subprocess.run(["git", "commit",

+                                           "-m", "["+lang+"]automatic update of translated content", "--quiet"],

+                                           cwd=repo_dir)

+                 if r_commit.returncode == 0:

+                     subprocess.run(['git', 'push', "--quiet"], check=True, cwd=repo_dir)

              else:

                  print(" ["+lang+"] No changes to commit", flush=True)

  
@@ -189,7 +188,7 @@ 

      try:

          # add hooks

          dir_path = os.path.dirname(os.path.abspath(__file__))

-         shutil.copytree(os.path.join(dir_path, '.githooks'), os.path.join(repo_dir, '.githooks'))

+         shutil.copytree(os.path.join(dir_path, '.githooks'), os.path.join(repo_dir, '.githooks'), dirs_exist_ok=True)

  

          shutil.copy(os.path.join(dir_path, 'check.sh'), os.path.join(repo_dir, 'check.sh'))

          subprocess.run(['./check.sh'], check=True, cwd=repo_dir)
@@ -200,14 +199,16 @@ 

          out = subprocess.run(['git', 'status', '--porcelain'], check=True, cwd=repo_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

  

          if out.stdout.decode("utf-8") :

-             subprocess.run(["git", "commit", "-m", "automatic update of pot/po files", "--quiet"],

-                            check=True, cwd=repo_dir)

+             r_commit = subprocess.run(["git", "commit",

+                                       "-m", "automatic update of pot/po files", "--quiet"],

+                                       cwd=repo_dir)

  

-             subprocess.run(['git', 'push', "--quiet"], check=True, cwd=repo_dir)

+             if r_commit.returncode == 0:

+                 subprocess.run(['git', 'push', "--quiet"], check=True, cwd=repo_dir)

          else:

              print(" No changes to commit", flush=True)

      except subprocess.CalledProcessError as e:

-         print("** ERROR " + (e.output if e.output else str(e.returncode)))

+         print("** ERROR" + e.output)

  

  def clone_sources():

      """List sources repositories from antora yaml file"""

This PR is related to fedora-infrastructure#9126
The pre-commit hook doesn't remove pot file from repo, but only unstage it.
I've also added a check to prevent empty commit if all files are unstaged.
And revert the latest commit related to EL7 adaptation since we are moving to fedora.

1 new commit added

  • only push if commit is successful
3 years ago

Pull-Request has been merged by jibecfed

3 years ago

you now have commit access, it will make your life easier.
could you please add in readme how to use the container?

there is many little things I'm struggling with because of my lack of expertise in automation. Your help is really welcome!

Happy to help :)
I'll write a little something about how to build and use this new container.