Skip to content

Teste de pull requests

alfsb edited this page Mar 23, 2023 · 7 revisions

Para realizar testes de pull requests enviados, uma série de scripts foram desenvolvidos para facilitar esse procedimento corriqueiro.

Testes não precisam de credenciais, e para evitar problemas outros, é melhor realizar os testes um em checkout exclusivo para isso:

mkdir phpdoc-prtests
cd phpdoc-prtests
git clone [email protected]:php/doc-base.git   doc-base
git clone [email protected]:php/doc-en.git     en
git clone [email protected]:php/doc-pt_br.git  pt_BR

O procedimento é o seguinte, que utiliza os scripts abaixo:

  1. Primeiro deve-se atualizar e conferir se o repositório oficial está compilando corretamente: ./conf.sh.

  2. Em caso de problemas de IDs inexistentes, o find.sh pode ajudar a procurar textos em todos os diretórios, original e traduções, assim como o open.sh ajuda a abrir original e tradução simultaneamente a partir de um único caminho relativo.

  3. Se o gatinho aparecer, tudo está bem para realizar o teste do pull request. Para tanto, deve executar ./test.sh [pr-number].

  4. Se o gatinho aparecer novamente, então o manual está compilando. Para enviar as alterações, realize o merge diretamente pela interface do GitHub e após isso rode um ./wipe.sh para restabelecer o repositório de testes ao seu estado original.

O fluxo, em grande resumo:

  1. ./conf.sh
  2. ./test.sh [pr-number]
  3. ./wipe.sh
  4. Merge diretamente no GitHub

E é isso.

Atenção: O wipe.sh é extremamente agressivo. Ele descartará quaisquer alterações locais, para criar ou recriar um ambiente mais próximo do repositório no servidor.

conf.sh

(cd doc-base; git pull)
(cd en;       git pull)
(cd pt_BR;    git pull)

#php doc-base/scripts/revcheck.php pt_BR > revcheck.html
#xdg-open revcheck.html

php doc-base/configure.php --with-lang=pt_BR --enable-xml-details

(cd pt_BR; git status)

Observação: As linhas comentadas permitem a criação e exibição automática do revcheck.html em cada execução. Multo útil caso estejam trabalhando em uma estação desktop com interface gráfica.

find.sh

grep -ri --exclude-dir={doc-base,.svn,.git} --color "$1" .

open.sh

#!/bin/bash

linha=$1

linha=${linha/'phpdoc/'/''}
linha=${linha/'/trunk/'/'/'}
linha=${linha/'./'/''}
linha=${linha/'en/'/''}
linha=${linha/'pt_BR/'/''}

en="en/${linha}";
br="pt_BR/${linha}";

#echo $en;
#echo $br;

nohup gedit $en $br > /dev/null 2>&1 &
#atom $en $br

test.sh

#!/bin/bash

if [[ $# -ne 1 ]]; then
    echo "Usage: $0 [pr number]" >&2
    exit 1
fi

#source wipe.sh

rm patch.txt
wget "https://patch-diff.githubusercontent.com/raw/php/doc-pt_br/pull/$1.diff" -O patch.txt

if ! $(cd pt_BR; git apply --check ../patch.txt); then

    #(cd pt_BR; git apply --verbose --reject ../patch.txt;)
    (cd pt_BR; git apply --verbose ../patch.txt;)

else

    (cd pt_BR; git apply ../patch.txt 2>&1 | tee ../merge.txt;)
    php doc-base/configure.php --with-lang=pt_BR --enable-xml-details    
    (cd pt_BR; git status)
    (cd pt_BR; git diff)

    echo
    echo "If OK, accept the pull on GitHub and then "
    echo "    ./wipe.sh"
    echo ""

fi

push.sh

if [ $# -eq 0 ]
then msg='Update translation.';
else msg=$1;
fi

(cd pt_BR; git commit -a -m "\"$msg\"")
(cd pt_BR; git push)
(cd pt_BR; git status)

wipe.sh

(cd en;    git clean -f -d)
(cd en;    git checkout .)
(cd en;    git reset  --hard )
(cd en;    git pull --rebase )
(cd en;    git rebase --skip )

(cd pt_BR; git clean -f -d)
(cd pt_BR; git checkout .)
(cd pt_BR; git reset  --hard )
(cd pt_BR; git pull --rebase )
(cd pt_BR; git rebase --skip )

(cd doc-base; git pull)
(cd en;       git pull)
(cd pt_BR;    git pull)

(cd en;    git status)
(cd pt_BR; git status)

spce.php

<?php

function wsfix( $filename )
{
    $filename = trim( $filename );
    if ( strpos( $filename , 'en' ) === 0 )
        $filename = substr( $filename , 2 );
    if ( strpos( $filename , 'pt_BR' ) === 0 )
        $filename = substr( $filename , 5 );
    if ( strpos( $filename , '/' ) === 0 )
        $filename = substr( $filename , 1 );
    
    $enname = 'en/' . $filename;
    $brname = 'pt_BR/' . $filename;
    
    $entext = file_get_contents( $enname );
    $brtext = file_get_contents( $brname );
    
    //$entext = rtrim( $entext );
    //$brtext = rtrim( $brtext );
    
    $enlines = explode( "\n" , $entext );
    $brlines = explode( "\n" , $brtext );
    
    if ( count( $enlines ) != count( $brlines ) )
        die( "Line count differs.\n" );
    
    $i = 0;
    $l = count( $enlines );
    for ( $i = 0 ; $i < $l ; $i++ )
    {
        $en = $enlines[$i];
        $br = $brlines[$i];
        
        $ws = "";
        $chars = str_split( $en );
        foreach( $chars as $char )
            if ( $char == ' ' )
                $ws .= ' ';
            else
                break;
        
        $br = $ws . trim( $br );
        $br = rtrim( $br );
        
        $brlines[$i] = $br;
    }
    
    $brtext = implode( "\n" , $brlines );
    file_put_contents( $brname , $brtext );
}

wsfix ( $argv[1] );

Clone this wiki locally