Situaciones típicas de integración continua

¿Ha estudiado los comandos de Git pero quiere imaginarse cómo ocurre la Integración Continua (CI) en la realidad? ¿O tal vez desea optimizar sus actividades diarias? Este curso le brindará habilidades prácticas de integración continua utilizando un repositorio de GitHub. Este curso no está destinado a ser un asistente en el que simplemente puede hacer clic, al contrario, realizará las mismas acciones que las personas realmente hacen en el trabajo, de la misma manera que lo hacen. Explicaré la teoría a medida que avance en los pasos relacionados.



qué hacemos?



A medida que avancemos, crearemos gradualmente una lista de pasos típicos de IC, que es una excelente manera de recordar esta lista. En otras palabras, crearemos una lista de acciones que los desarrolladores toman al realizar una integración continua, realizando una integración continua. También usaremos un conjunto de pruebas simple para acercar nuestro proceso de IC a la realidad.



Este GIF muestra esquemáticamente las confirmaciones en su repositorio a medida que avanza en el curso. Como ves, aquí no hay nada complicado y solo lo más necesario.



Pasos continuos de integración



Pasará por los siguientes scripts de CI estándar:



  • Trabajar en funciones;
  • Aplicación de autotest para aseguramiento de la calidad;
  • Ejecución de la tarea prioritaria;
  • Resolver un conflicto al fusionar ramas (fusionar conflicto);
  • Se produce un error en un entorno de producción.


¿Qué aprendes?



Puede responder las siguientes preguntas:



  • ¿Qué es la integración continua (CI)?
  • CI, ?
  • pull request ?
  • (Test Driven Development, TDD) CI?
  • (merge) (rebase)?
  • ?


"pull request", . " " "" , .


?



, CI, , , , .





. , . , . , , " " , , .



, C++ , , , , . (, (unit), ) . , , , , " + ", , , .



(Continuous Delivery, CD) , - .



,



  1. Pull in the latest code. Create a branch from master. Start working.
  2. Create commits on your new branch. Build and test locally. Pass? Go to the next step. Fail? Fix errors or tests and try again.
  3. Push to your remote repository or remote branch.
  4. Create a pull request. Discuss the changes, add more commits as discussion continues. Make tests pass on the feature branch.
  5. Merge/rebase commits from master. Make tests pass on the merge result.
  6. Deploy from the feature branch to production.
  7. If everything is good in production for some period of time, merge changes to master.


Proceso de integración continuo (opcional)







Node.js Git-.



Git-, .


, Git-,



Git-, , .





(fork) - GitHub. .



? , continuous-integration-team-scenarios-students, GitHub, URL



https://github.com/<    GitHub>/continuous-integration-team-scenarios-students


<URL >.



<> , .

GitHub actions . , , , , , Actions GitHub.



, , GitHub Actions .

Habilite las acciones de Github para el repositorio del curso



GitHub Markdown , ,



https://github.com/<your GitHub user name>/continuous-integration-team-scenarios-students/blob/master/ci.md




— , .



, , solution, .

, solution master . , , , Git. , master solution , .





(commit)



git add .
git commit -m "Backing up my work"




  • master master-backup;
  • solution master;
  • (checkout) master ;
  • "solution" "master" ( "solution") "solution".


git branch -m master master-backup
git branch -m solution master
git checkout master -f
git branch solution


git log master , .

:



git reset --hard <the SHA you need>


, - (remote). .



git push --force origin master


, git push --force. , , , , .



Starting working



Integración continua: introducción



CI. , , .



️ : , master,



  1. <URL >.
  2. npm install ; Jest, .
  3. feature. .
  4. ci.test.js .



    it('1. pull latest code', () => {
      expect(/.*pull.*/ig.test(fileContents)).toBe(true);
    });
    
    it('2. add commits', () => {
      expect(/.*commit.*/ig.test(fileContents)).toBe(true);
    });
    
    it('3. push to the remote branch with the same name', () => {
      expect(/.*push.*/ig.test(fileContents)).toBe(true);
    });
    
    it('4. create a pull request and continue working', () => {
      expect(/.*pull\s+request.*/ig.test(fileContents)).toBe(true);
    });


  5. 4 ci.md.

    1. Pull in the latest code. Create a branch from `master`. Start working.    
    2. Create commits on your new branch. Build and test locally.  
    Pass? Go to the next step. Fail? Fix errors or tests and try again.  
    3. Push to your remote repository or remote branch.  
    4. Create a pull request. Discuss the changes, add more commits  
    as discussion continues. Make tests pass on the feature branch.  




#   
git clone <repository URL>
cd <repository name>

#  npm install    ;   Jest,      .
npm install

#      feature.     .
git checkout -b feature

#  ci.test.js   .
#  ci.md   


,



, .



,



  • :

    • ;
    • ( JIT- );
    • ( );
    • ;
    • .


  • (build server) :

    • / .
    • .
    • ( master).
    • /


, , . .



  • — , CI
  • , — , CI
  • — CI
  • , — CI/CD, // , , - .




, npm test. git hook . : Git hooks GitHub . hook, install_hook.sh repo/hooks/pre-commit .git/hooks/.

, , , .



  1. , npm test . , .
  2. hook (pre-commit hook), install_hook.sh.
  3. .
  4. , .


.

Integración continua: primer compromiso





#  pre-commit hook  install_hook.sh.  

#     .  "Add first CI steps"     .
git add ci.md ci.test.js
git commit -m "Add first CI steps"

# ,     .  




, , . GitHub (personal fork, ), .





, .



.





  • ,




git push --set-upstream origin feature


pull request



pull request Steps review. feature "head branch" master "base branch".



, master "base branch", .

GitHub "base branch" — , , "head branch" — , .



,



Pull request(PR)



Pull request(PR) — , (code review) . Pull request . . (pull) , , , (merge) . , , merge request.



pull request GitHub . , , , pull requests . :



  • , ;
  • , ;
  • ;
  • , .


pull request - . , , , , . , pull request , - , . PR : . , @ , pull request'.



PR .



  • , .
  • , . :

    • - , , - , # ;
    • @ , , @ ;
    • - - .


PR , . , , .



, . PR GitHub. .



️ CI



, , , .



️ : pull request



  1. master.
  2. bugfix.
  3. ci.md.

    > **GitHub flow** is sometimes used as a nickname to refer to a flavor of trunk-based development  
    when code is deployed straight from feature branches. This list is just an interpretation  
    that I use in my [DevOps courses](http://redpill.solutions).  
    The official tutorial is [here](https://guides.github.com/introduction/flow/).
  4. .
  5. bugfix .
  6. pull request Adding a remark bugfix master.


, master "base branch", .

.

Revisión de integración continua





#    master.   bugfix.
git checkout master

#   bugfix-remark.
git checkout -b bugfix

#     ci.md.

#  
git add ci.md
git commit -m "Add a remark about the list being opinionated"

#   bugfix   .
git push --set-upstream origin bugfix

#  pull request    GitHub   


pull request "Adding a remark"





  1. pull request.
  2. "Merge pull request".
  3. "Confirm merge".
  4. "Delete branch", .


.

Integración continua: fusionando una solución con un maestro





pull request . , , CI.



. " "(contribution guidelines). .



. pre-commit hook , , , . : , - . , , , , , . , , , .



(TDD)



TDD . TDD .



  1. .
  2. , .
  3. .
  4. , , .
  5. .
  6. .


, , , — , "--"(red-green-refactor).





, CI. , ("").

, GitHub , PR.



  1. feature.
  2. ci.test.js it (...);.



    it('5. Merge/rebase commits from master. Make tests pass on the merge result.', () => {
      expect(/.*merge.*commits.*tests\s+pass.*/ig.test(fileContents)).toBe(true);
    });
    
    it('6. Deploy from the feature branch to production.', () => {
      expect(/.*Deploy.*to\s+production.*/ig.test(fileContents)).toBe(true);
    });
    
    it('7. If everything is good in production for some period of time, merge changes to master.', () => {
      expect(/.*merge.*to\s+master.*/ig.test(fileContents)).toBe(true);
    });


  3. . pre-commit hook , .
  4. ci.md.

    5. Merge/rebase commits from master. Make tests pass on the merge result.  
    6. Deploy from the feature branch with a sneaky bug to production.
    7. If everything is good in production for some period of time, merge changes to master. 
  5. .
  6. feature.


-

Integración continua: trabajo continuo






#   feature
git checkout feature

#    ci.test.js   

#    ci.test.js   
git add ci.test.js

#   .  pre-commit hook ,   .
git commit

#     ci.md   

#     
git add ci.md
git commit -m "Add the remaining CI steps"

#     feature
git push




Steps review.



, , , feature master. , bugfix master PR.

, master , , feature. - HEAD master feature. (merge), feature (rebase) master. GitHub , . , ci.md. (merge conflict), .



Merge rebase



Merge



  • (merge commit) .

    • .
    • SHA .
  • .
  • .

    • - ( IDE).
    • , , git bisect — .


Rebase



  • .

    • SHA, GitHub pull requests, .
    • .
  • .
  • .

    • , .
    • : git bisect, .
  • --force .


, . "" "" - , , (git rebase -i) , , (merge) "" .



.





  1. , master .
  2. feature.
  3. master. , ci.md.
  4. , CI, .
  5. feature.
  6. pull request' GitHub, .




# ,      `master`    .
git checkout master
git pull

#    feature
git checkout feature

#     master 
git merge master

# A merge conflict related to concurrent changes to ci.md will be reported
# => Auto-merging ci.md
#    CONFLICT (content): Merge conflict in ci.md
#    Automatic merge failed; fix conflicts and then commit the result.

#   ,      CI,       .
#  ci.md       
git add ci.md
git merge --continue
#       

#       feature.
git push

#         GitHub,      .


!



, pull request master.



️ : pull request "Steps review"



  1. pull request.
  2. "Merge pull request".
  3. "Confirm merge".
  4. "Delete branch", .




Integración continua: integración de funciones





, « , , ». , , , .



:



  • , ;
  • master , .


?



""(rolling back) — (revert) , . " "(fixing forward) — master . API , , , , , .



, ,



  • ;
  • master .




  1. master .
  2. .
  3. PR Steps review master.
  4. .




Integración continua: deshacer una combinación





#    master.
git checkout master

#      .
git pull

#    PR Steps review  master.
#    ,      ,    
git show HEAD

# ,  ,      master  ,     
git revert HEAD -m 1
#     

#     
git push




, ci.md "sneaky bug" .



CI master



feature. , master. , . , , feature master .



-:



  • (revert) , feature master;
  • feature.


, pull request .





  1. feature-fix .
  2. feature . , .



    Integración continua: confirmación de funciones que regresan



  3. ci.test.js:



    it('does not contain the sneaky bug', () => {
    expect( /.*sneaky\s+bug.*/gi.test(fileContents)).toBe(false);
    });


  4. , , .
  5. " with a sneaky bug" ci.md.
  6. .
  7. .


-

Integración continua: función fija





#     feature-fix    .
git checkout -b feature-fix

#       feature   .   ,    .
#      :
# -      : C0
# -    : C2
git log --oneline --graph
git cherry-pick C0..C2
#   
# -  ci.md / ci.test.js
# -    
# -  "git cherry-pick --continue",     

#     ci.test.js
#   ,  ,     .

#   " with a sneaky bug"  ci.md.

#            .
git add ci.md ci.test.js
git commit -m "Fix the bug in steps list"

#     .
git push --set-upstream origin feature-fix


pull request.



pull request Fixing the feature. feature-fix "head branch", master "base branch".

, , . PR.



, master "base branch", .


pull request "Fixing the feature"



! , master pull request.





  1. "Merge pull request".
  2. "Confirm merge".
  3. "Delete branch", .


,

Integración continua: arreglo integrado en maestro



!



, .



Si nota algún problema con el curso o sabe cómo mejorarlo, cree un problema en el repositorio con los materiales del curso . Este curso también tiene una versión interactiva que utiliza el laboratorio de aprendizaje de GitHub como plataforma.




All Articles