Pernahkah Anda mempelajari perintah Git tetapi ingin membayangkan bagaimana Continuous Integration (CI) terjadi dalam kenyataan? Atau mungkin Anda ingin mengoptimalkan aktivitas sehari-hari? Kursus ini akan memberi Anda keterampilan integrasi berkelanjutan langsung menggunakan repositori GitHub. Kursus ini tidak dimaksudkan sebagai wizard yang dapat Anda klik, sebaliknya, Anda akan melakukan tindakan yang sama seperti yang dilakukan orang di tempat kerja, dengan cara yang sama mereka melakukannya. Saya akan menjelaskan teori saat Anda melalui langkah-langkah terkait.
Apa yang kita lakukan?
Saat kami melanjutkan, kami secara bertahap akan membuat daftar langkah-langkah CI yang khas, yang merupakan cara terbaik untuk mengingat daftar ini. Dengan kata lain, kami akan membuat daftar tindakan yang diambil pengembang saat melakukan integrasi berkelanjutan, melakukan integrasi berkelanjutan. Kami juga akan menggunakan rangkaian pengujian sederhana untuk membawa proses CI kami lebih dekat ke kenyataan.
GIF ini secara skematis menunjukkan komit di repositori Anda saat Anda maju melalui kursus. Seperti yang Anda lihat, tidak ada yang rumit di sini dan hanya hal-hal yang paling penting.

Anda akan melalui skrip CI standar berikut:
- Bekerja pada fitur;
- Penerapan autotest untuk jaminan kualitas;
- Pelaksanaan tugas prioritas;
- Menyelesaikan konflik saat menggabungkan cabang (menggabungkan konflik);
- Terjadi kesalahan dalam lingkungan produksi.
Apa yang kamu pelajari?
Anda dapat menjawab pertanyaan-pertanyaan berikut:
- Apa itu Continuous Integration (CI)?
- CI, ?
- pull request ?
- (Test Driven Development, TDD) CI?
- (merge) (rebase)?
- ?
"pull request", . " " "" , .
?
, CI, , , , .
. , . , . , , " " , , .
, C++ , , , , . (, (unit), ) . , , , , " + ", , , .
(Continuous Delivery, CD) , - .
,
- Pull in the latest code. Create a branch from
master. Start working. - Create commits on your new branch. Build and test locally. Pass? Go to the next step. Fail? Fix errors or tests and try again.
- Push to your remote repository or remote branch.
- Create a pull request. Discuss the changes, add more commits as discussion continues. Make tests pass on the feature branch.
- Merge/rebase commits from master. Make tests pass on the merge result.
- Deploy from the feature branch to production.
- If everything is good in production for some period of time, merge changes to master.
๏ธ
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 .

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"
-
mastermaster-backup; -
solutionmaster; - (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

CI. , , .
๏ธ : , master,
-
<URL >. -
npm install; Jest, . -
feature. . 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); });
- 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/.
, , , .
- ,
npm test. , . - hook (pre-commit hook),
install_hook.sh. - .
- , .
.

# 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, ), .
- , , . , . , , . GitHub. [Team Work and CI with Git] (http://devops.redpill.solutions/).
- ,
master"". , , ,master.
, .
.
๏ธ
- ,
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
-
master. -
bugfix. -
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/). - .
-
bugfix. - pull request Adding a remark
bugfixmaster.
, master "base branch", . .

# 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"
๏ธ
- pull request.
- "Merge pull request".
- "Confirm merge".
- "Delete branch", .
.

๏ธ
pull request . , , CI.
. " "(contribution guidelines). .
. pre-commit hook , , , . : , - . , , , , , . , , , .
(TDD)
TDD . TDD .
- .
- , .
- .
- , , .
- .
- .
, , , โ , "--"(red-green-refactor).
๏ธ
, CI. , ("").
, GitHub , PR.
-
feature. ci.test.jsit (...);.
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); });
- .
pre-commithook , . -
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. - .
-
feature.
-

# 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) "" .
.
๏ธ
- ,
master. -
feature. -
master. ,ci.md. - , CI, .
-
feature. - 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"
- pull request.
- "Merge pull request".
- "Confirm merge".
- "Delete branch", .

, ยซ , , ยป. , , , .
:
- , ;
-
master, .
?
""(rolling back) โ (revert) , . " "(fixing forward) โ master . API , , , , , .
, ,
- ;
-
master.
๏ธ
-
master. - .
- PR Steps review
master. - .

# 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) ,
featuremaster; -
feature.
, pull request .
๏ธ
-
feature-fix. feature. , .

ci.test.js:
it('does not contain the sneaky bug', () => { expect( /.*sneaky\s+bug.*/gi.test(fileContents)).toBe(false); });
- , , .
- " with a sneaky bug"
ci.md. - .
- .
-

# 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.
๏ธ
- "Merge pull request".
- "Confirm merge".
- "Delete branch", .
,

!
, .
Jika Anda melihat ada masalah dengan kursus atau tahu bagaimana memperbaikinya, buat masalah di repositori dengan materi kursus . Kursus ini juga memiliki versi interaktif menggunakan GitHub Learning Lab sebagai platform.