<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by SeongChan Lee on Medium]]></title>
        <description><![CDATA[Stories by SeongChan Lee on Medium]]></description>
        <link>https://medium.com/@foriequal0?source=rss-f3ff3257c097------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*MkRWFCsCmQZAkOylKBPkCQ.png</url>
            <title>Stories by SeongChan Lee on Medium</title>
            <link>https://medium.com/@foriequal0?source=rss-f3ff3257c097------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 09:48:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@foriequal0/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Continuous Integration on CodeChain]]></title>
            <link>https://medium.com/codechain/continuous-integration-on-codechain-25721da2470b?source=rss-f3ff3257c097------2</link>
            <guid isPermaLink="false">https://medium.com/p/25721da2470b</guid>
            <category><![CDATA[travis-ci]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[mergify]]></category>
            <category><![CDATA[chaincode]]></category>
            <dc:creator><![CDATA[SeongChan Lee]]></dc:creator>
            <pubDate>Tue, 11 Jun 2019 01:52:29 GMT</pubDate>
            <atom:updated>2019-06-11T01:52:29.684Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*uyCeZiXkJ5FmeH-rpJn9BA.jpeg" /><figcaption><a href="https://commons.wikimedia.org/wiki/File:BMW_Leipzig_MEDIA_050719_Download_Karosseriebau_max.jpg">https://commons.wikimedia.org/wiki/File:BMW_Leipzig_MEDIA_050719_Download_Karosseriebau_max.jpg</a></figcaption></figure><p>Everything changes during the development process. Different requirements may emerge, or the development environment may change, and the code must be adjusted accordingly. As code regularly becomes modified and altered, there must be steady ongoing management and investment in order to keep the code from breaking apart. Without diligent care and effort may lose formatting consistency, and failed test cases may be left unattended. In the worst case, compile errors are accumulated over long periods of time behind build flags that are not used very often, and ultimately lead to build errors. If the codebase continues to break in this manner, it will have adverse effects on the productivity of the development team, and ultimately, affect the quality of the entire product. For a blockchain project that stresses utmost reliability, it is crucial to maintain proper coding practices.</p><p>It is important to maintain your code in good shape by enforcing practices, such as strengthening code reviews, regularizing code formatting, running test cases on a regular basis, and building code with various build flag combinations. However, it is not possible to get rid of the responsibilities of this repetitive and constant work to each individual developer. Putting it in the hands of a human being not only leads to errors, but it will also increase the fatigue of the developers, lower efficiency, and gradually become a big mess.</p><p>Therefore, it is important to automate tools and workflows related to code maintenance. The CodeChain Core project takes advantage of a variety of software and services that enables the code to stay in the best condition. At the time of the pull request creation in the <a href="https://github.com/">Github</a> repository, <a href="https://travis-ci.org/">Travis CI</a> automatically performs software that performs various checks and reports the results to inform the developer of the flaws of the code. <a href="https://mergify.io/">Mergify</a> works with CI and the review system to automate the tasks associated with Github’s pull requests, such as branch updates and merges, which are repetitive, cumbersome and often delayed, reducing the team’s overall workload.</p><h3>Automation of the Merge Process Using Mergify</h3><p>The CodeChain Core project used <a href="https://help.github.com/en/articles/types-of-required-status-checks">strict status checks</a> on pull requests merged into the master branch, and used the rebase merge as the default merge method. With strict status checks, pull requests must be up-to-date with the branch you want to merge in order for them to be merged. This is because even if the rebase or merge commit creation was successful when you attempted the merge, the resulting code might be incorrect code. For example, let’s imagine a situation where you try to merge branches A and B sequentially into the master branch. In branch A, code that uses the function foo was added, and in branch B, foo was removed from the code. In this case, merge A merge is successful, and merge B is successful as well, but after B merges, a compilation error will occur. Therefore, if you create a rebase or a merge commit, you should run the test again and apply it to the master branch only when there are no problems.</p><p>In the CodeChain Core project, which uses this approach, in order for pull requests to be merged into the master branch, the following workflow has to be followed:</p><ol><li>The contributor creates a pull request.</li><li>Wait for Travis CI’s test results.</li><li>Anyone specified as a code reviewer must review the code.</li><li>When all reviews are finished and Travis CI doesn’t report any errors, the merge process will begin.</li><li>If the branch of a pull request is fast-forwardable to the master, or if the merge commit is up-to-date with the branch’s latest commit, it will attempt rebase merging.</li><li>If it is not up-to-date, the branch is updated to master by using rebase or Github’s Update Branch function and returns to step 2.</li></ol><p>However, there is a drawback to this workflow. The merge can only be done on one pull request that has been updated to the master, and once the updated pull requests have been merged into the master, the remaining pull requests must be updated to be merged again. If you make a mistake to update other pull requests and merge them first, instead of merging the already updated pull requests first, you need to refresh the pull requests that were updated recently. Fewer mistakes are made in situations with fewer open pull requests. However, as the number of open pull requests increases and the test by Travis CI begins to become delayed, mistakes become more common. Frequent branch updates increase the number of tasks that are trapped in Travis CI, and because the number of concurrent tasks that Travis CI can run is limited, the work of other pull requests become gradually delayed as well. To avoid this situation, the one who merges the pull requests must remember carefully which pull requests have been updated and merge sequentially.</p><p>In order to reduce the burden on the merger in this situation and the workload on Travis CI to reduce the merge delay, and to consequently improve the efficiency of the team, the CodeChain engine team introduced <a href="https://mergify.io/">Mergify</a>. Mergify is a merge management service that works with Github. You can set the policy on the .mergify.yaml file included in the repository, and you can proceed or stop the automatic merging of the pull request according to the set policy. Furthermore, various actions can be performed automatically.</p><p>Here is the .mergify.yml rule that we enforce on our team: (<a href="https://github.com/CodeChain-io/codechain/blob/master/.mergify.yml">link</a>)</p><pre>pull_request_rules:<br>  - name: Merge when CI passes and resolves all requested reviews<br>    conditions:<br>      - &quot;#approved-reviews-by&gt;=1&quot;<br>      - &quot;#review-requested=0&quot;<br>      - &quot;#changes-requested-reviews-by=0&quot;<br>      - status-success=continuous-integration/travis-ci/pr<br>      - base=master<br>      - label!=do-not-merge<br>      - &quot;- title~=\\b(wip|WIP)\\b&quot;<br>    actions:<br>      merge:<br>        method: rebase<br>        rebase_fallback: null<br>        strict: smart</pre><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*NmHwn2c17AKxEL2mCtZ2oA.png" /><figcaption>The workflow of Mergify</figcaption></figure><p>This rule allows Mergify to automatically merge pull requests that passes the following conditions:</p><ol><li>Has more than 1 reviewer, and is approved by all the reviewers.</li><li>Passes Travis CI.</li><li>Does not have ‘WIP’ in the title.</li><li>Does not have ‘do-not-merge’ in the label.</li></ol><p>We also tried merge rebasing only when merged, and we have set the strict merge setting to ON.</p><p>If you use the strict merge setting in Mergify, it will automatically update the pull request that satisfies the condition to the master branch. However, I have already explained why it is important to keep the update and merge order consistent. If Mergify randomly updates and tries to merge, there will still be a delay in the workload on Travis CI. So use the strict: smart option. With the strict: smart option, Mergify manages the work queue so that one pull request is updated and merged at a time.</p><h3>Code Inspection and Test Automation Using Travis CI</h3><p>Mergify is only responsible for automating the process of merging pull requests on the basis of reviews and results from <a href="https://travis-ci.org/">Travis CI</a>, and it is up to Travis CI to check for possible problems in the code. Once Github has created a pull request, it will automatically create a build job to check that pull request on Travis CI by working with Github. The jobs that are created can be defined in the .travis.yml file in the repository’s root directory. In the CodeChain Core project, two kinds of jobs are defined. Checking the formatting of the code and checking for minor mistakes, verifying that CodeChain is being built on the target platform to which CodeChain is deployed, and doing the unit tests and the end-to-end tests. Jobs defined in CodeChain can be found <a href="https://github.com/CodeChain-io/codechain/blob/master/.travis.yml">here</a>.</p><p>CodeChain Core projects are written in the Rust programming language. We use the code formatter, rust-fmt, to check the formatting of the Rust code, and use the lint tool, rust-clippy, to check for minor mistakes in the code. Unit tests are run using the cargo test, which naturally attempts to compile and detect compile errors. The E2E test is written in TypeScript, a script used to test code written in Rust, but this code is also subject to management. We use a formatter called ‘prettier’ to check the formatting, and minor mistakes in the code are checked by the lint tool called ‘tslint’. The E2E test is written and executed with the mocha test framework.</p><h3>Reducing Execution Time for Unnecessary Tasks in Travis CI</h3><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*ReJCeRt3UrdFp65T8mWs1A.png" /><figcaption>Travis CI</figcaption></figure><p>Since the CodeChain project is not a small one, it takes a long time to complete tests. The CodeChain binaries written in Rust alone take tens of minutes to build, and the E2E test takes up to 30 minutes to run a variety of tests, waiting for the consensus on the binaries built identically to the actual operating environment. If you do all this work in a row, it takes about an hour and 20 minutes, and once a pull request is created, these operations are performed once in the pull request branch when the pull request was first created, once again after it has been merged into master, and one last time in the master branch. Performing this process takes up to 4 hours. The free plan Travis CI offers to open source projects limits the number of concurrent tasks to four, so the total working time available for an 8 hour work day is only 8 * 4 = 32 hours. It’s like saying you can only create up to eight pull requests per day. Due to code changes from peer reviews and new jobs created by work-in-progress pull requests, this number is greatly reduced and the pull request checks were gradually being pushed away. We needed to optimize the time it takes to do this jobs.</p><p>We have optimized the process so that the unnecessary work done in Travis CI can be finished as early as possible. Travis CI provides a way to define jobs <a href="https://docs.travis-ci.com/user/conditions-v1">conditionally</a>, but because of the limited information available and DSL’s low degree of freedom, a more flexible shell script was used to finish the defined jobs earlier. The types of jobs that we finish early using a shell script are:</p><ol><li>If the pull request contains only changes to documents that do not affect the build, tests are not performed.</li><li>If only E2E tests are edited, no unit tests are performed.</li><li>Any merge tests performed on the master branch immediately after it is automatically merged into master by mergify are not performed. This is because due to the strict merge settings and the rebase merge policy, the updated code from the pull request via Mergify is identical to the master branch code that finished the rebase merge process.</li></ol><p>It is easy to write a shell script that checks for these conditions and immediately aborts the job. However, in a special situation called Travis CI, additional considerations were necessary to create a recyclable script. In order for Mergify to automatically merge, Travis CI should be reported as “successful” even if the task is finished early, and because no bug-free code exists, the shell script also stops the task if it encounters an unexpected error, and the shell script should be able to log and verify what command was executed.</p><p>It was relatively simple to log the shell script and abort it immediately in cases of failure. The bash shell has several flags that can be turned on or off with the set command, which is solved by turning on the e flag and the v (or x) flag. If you turn on the e flag with set -e, an error occurs in the command in the shell script. If a nonzero exit code is encountered, the shell is immediately stopped and the exit code of the last failed command is considered as the exit code of the shell. If the command listed in .travis.yml is terminated with a non-zero exit code, Travis CI will abort the operation and report “Failed.” Turning on the v flag with set -v will print out what commands were executed in the shell script. If you turn on the x flag instead of v, you will see an expanded set of variables as they were passed as command arguments.</p><p>However, it was not possible within a shell script to stop Travis CI’s operations while it is “successful.” Commands such as exit 0 and travis_terminate 0 stop the shell itself when called from within a shell script, but did not stop the operations of Travis CI. We had to return the values of either “shut down” or “resume” jobs from the inside to the outside. In order to return values from a sub-shell, there are usually two ways to do this: one is to return the exit code, and the other way is to print the output to standard output and capture the standard output from the parent shell. However, the shell’s exit code was already being used to determine if the Travis operation has “failed”or not , and the standard output was what ordinary commands in the shell scripts were using to log the situation.</p><p>However, there is one more thing Travis CI logs in addition to the standard output, known as a standard error. In a Unix type operating system, running a process creates three standard streams that interact with the outside world: the standard error specified in file descriptor 0, the standard output specified in 1, the standard error specified in 2. In the case of an interactive shell, a standard input is used to receive input from the keyboard, and the standard output is used to output text to the terminal screen. The standard error is used to output a program error in a stream that can be differentiated from the standard output. Travis CI also logs the standard error stream.</p><p>Our scripts could use this point to return values from the subshell and log the command execution history in Travis CI. The Bash shell has powerful I / O(Input and Output) redirection capabilities. You can redirect the I / O to individual commands running within the shell, but you can also control the redirection of the I / O across the shell. We redirected all standard output (fd 1) in the shell to standard error out-of-shell fd 2 (fd 2), and redirected fd 3, which is output from within the shell, to standard output(fd 1) by using the following Bash command:</p><pre>exec 3&gt;&amp;1 1&gt;&amp;2</pre><p>The shell can capture the standard output of the subshell like RESULT = $ (./ script) and save it to a variable. If FD3 is redirected to standard output, it can be used as a stream to pass return values such as echo skip&gt; &amp; 3 echo noskip&gt; &amp; 3. We used this to run a shell script that determines if Travis CI’s .travis.yml stops working early, and with the return value, call the exit 0 command itself. This allows one to stop the Travis CI operation early, leaving it in the “Success” state.</p><pre>./.travis/check-foo<br>#!/usr/bin/env bash<br>set -ex;<br>exec 3&gt;&amp;1 1&gt;&amp;2<br>function return_to_travis { echo $1 &gt;&amp;3; }<br>if some_condition_foo; then <br> echo “Skipped!”; <br> return_to_travis “skip”; <br>else <br> echo “Don’t Skip!”<br> return_to_travis “noskip”<br>fi</pre><pre>.travis.yml<br>RESULT=$(./.travis/check-foo); if [ “$RESULT” = “skip” ]; then terminate_travis 0; fi;</pre><p>If you put these together, the shell script and the Travis CI script are as shown above. Through batch redirection of all standard output of common commands to standard error stream, you do not have to redirect individual commands but write your shell as you normally would if you wrote a shell script. This leaves trace logs in Travis CI and by turning on the set -e flag, a shell script can be stopped if it encounters an unexpected error within a command, and can be stopped early with a “success” status report if desired.</p><p>In this article, we introduced how we are utilizing CI to maintain a healthy state of the CodeChain Core project and to improve the team’s productivity. Mergify automates the workflow of pull requests on Github and reduces the effort of developers, and various inspection tools running on the Travis CI detect the anomalies of the code at the pull request level to prevent the error from flowing into the code base at all. In addition, Travis CI’s operations are configured to perform verification operations only when necessary, making full use of our limited resources. Our CI environment did not look like this from the beginning. By making development progress while keeping Github as a focus point, and resolving productivity issues step by step along the way, it was possible to evolve into the current state we are at today. Our projects will continue, and our code and environment will continue to change. Accordingly, our CI environment will also be steadily evolving to improve productivity.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25721da2470b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codechain/continuous-integration-on-codechain-25721da2470b">Continuous Integration on CodeChain</a> was originally published in <a href="https://medium.com/codechain">CodeChain</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[코드체인에의 지속적 통합 환경 구성]]></title>
            <link>https://medium.com/codechain-kr/%EC%BD%94%EB%93%9C%EC%B2%B4%EC%9D%B8%EC%97%90%EC%9D%98-%EC%A7%80%EC%86%8D%EC%A0%81-%ED%86%B5%ED%95%A9-%ED%99%98%EA%B2%BD-%EA%B5%AC%EC%84%B1-fa77f4a9c7d4?source=rss-f3ff3257c097------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa77f4a9c7d4</guid>
            <category><![CDATA[mergify]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[chaincode]]></category>
            <category><![CDATA[travis-ci]]></category>
            <dc:creator><![CDATA[SeongChan Lee]]></dc:creator>
            <pubDate>Wed, 05 Jun 2019 12:20:00 GMT</pubDate>
            <atom:updated>2019-06-10T10:19:16.278Z</atom:updated>
            <content:encoded><![CDATA[<h3>코드체인의 지속적 통합 환경 구성</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uyCeZiXkJ5FmeH-rpJn9BA.jpeg" /><figcaption><a href="https://commons.wikimedia.org/wiki/File:BMW_Leipzig_MEDIA_050719_Download_Karosseriebau_max.jpg">https://commons.wikimedia.org/wiki/File:BMW_Leipzig_MEDIA_050719_Download_Karosseriebau_max.jpg</a></figcaption></figure><p>개발이 진행되는 과정에서는 모든것이 변합니다. 요구사항이 변하기도 하고, 개발환경이 변하기도 하며, 이에 맞춰 코드도 변합니다. 이렇게 꾸준히 변하는 코드는 이를 건강하게 유지하려는 지속적인 관리와 투자가 없으면 금방 망가지기 마련입니다. 노력을 기울이지 않은 코드는 사소하게는 포매팅의 일관성을 잃기도 하고, 테스트케이스들이 실패하는 채로 방치되거나, 자주 사용되지 않는 빌드 플래그 뒤에 컴파일 에러가 오랜 세월 누적되어 한번에 빌드되지 않기도 합니다. 이런 식으로 망가져가는 코드베이스는 개발팀의 생산성에도, 제품의 품질에도 악영향을 끼치게 됩니다. 안정성이 중시되는 블록체인 프로젝트로서는 코드가 망가지지 않게 관리하는것이 중요합니다.</p><p>코드리뷰를 강화하고, 코드 포매팅을 규칙화 하고, 정기적으로 테스트케이스를 실행해보고, 다양한 빌드 플래그 조합으로 코드를 빌드하는 등의 방법으로 코드가 건강한 상태에서 멀어지지 않도록 해야합니다. 그러나 이런 반복적이고 꾸준히 해야하는 일의 책임을 개발자 개인에게 한없이 지울 수는 없습니다. 사람의 손에 맡기는 일은 실수의 여지가 많고, 개발자의 피로감을 높이고, 능률을 낮추며 점차 흐지부지 될 것입니다.</p><p>그렇기에 이런 일련의 도구들과 작업 흐름들을 자동화하는것이 중요합니다. 코드체인 코어 프로젝트에서는 코드가 최선의 상태로 유지될 수 있도록 하는 다양한 소프트웨어와 서비스들을 활용합니다. <a href="https://github.com/">GitHub</a> 저장소에 풀 리퀘스트가 만들어지는 시점에 <a href="https://travis-ci.org/">Travis CI</a>는 다양한 검사를 수행하는 소프트웨어들을 자동으로 수행하고, 그 결과를 보고해 줘 코드의 결함이 개발자가 인지하지 못한 채 몰래 코드베이스로 흘러 들어가는 사태를 미연에 방지합니다. <a href="https://mergify.io/">Mergify</a>는 CI와 리뷰 시스템 등과 연동되어 반복적이고, 손길이 많이 가며, 자칫 지연되기 십상인 브랜치 업데이트, 병합과 같은 GitHub의 풀 리퀘스트와 관련된 작업을 자동화하여 팀의 일손을 돕습니다.</p><h3>Mergify 를 이용한 병합 과정 자동화</h3><p>코드체인 코어 프로젝트는 master 브랜치로 병합되는 풀 리퀘스트에 대해서 <a href="https://help.github.com/en/articles/types-of-required-status-checks">엄격한 상태 확인</a>을 적용하고, 리베이스 병합을 기본 병합 방식으로 사용하고 있었습니다. 엄격한 상태 확인을 사용하면 풀 리퀘스트가 병합되기 위해서는 병합되려는 브랜치에 맞춰 최신으로 업데이트 되어야 합니다. 병합을 시도할 때 리베이스나 병합 커밋 만들기가 성공적으로 완료되었어도 그 결과로 나온 코드는 올바르지 않은 코드일 수 있기 때문입니다. 예를 들어 master에 A, B 브랜치를 순차적으로 병합을 시도하는 상황을 상상해봅시다. A 브랜치에서는 함수 foo를 사용하는 코드를 추가했고, B 브랜치에서는 코드에서 foo를 삭제했습니다. 이 경우 A 병합도 성공하고, B 병합도 성공하지만, B 병합 이후에는 컴파일 오류가 납니다. 그렇기 때문에 리베이스, 혹은 병합 커밋 만들기에 성공해도 테스트를 다시 수행해서 이상이 없을 때만 master에 반영해야합니다.</p><p>이런 방식을 사용하는 코드체인 코어 프로젝트에서는 풀 리퀘스트가 master 브랜치에 병합되기 위해서는 다음과 같은 작업 흐름을 따라야 했습니다.</p><ol><li>기여자는 풀 리퀘스트를 만듭니다.</li><li>Travis CI의 검사 결과를 기다립니다.</li><li>코드 리뷰어로 지정된 사람은 코드를 리뷰합니다.</li><li>모든 리뷰어들의 리뷰가 완료되고, Travis CI가 이상 없음을 알리면 병합을 시작합니다.</li><li>풀 리퀘스트의 브랜치가 master에 대해 fast-forward가 가능하거나, 병합 커밋이 브랜치의 최신 커밋으로 올라가 있어 최신화 되어 있는 상태이면 리베이스 병합을 시도합니다.</li><li>최신화되어있지 않으면 브랜치를 master에 대해 리베이스나 GitHub의 Update Branch 기능 등으로 최신화하고 2.로 되돌아갑니다.</li></ol><p>그러나 이런 작업흐름에는 한가지 결점이 있었습니다. 병합은 master에 맞춰 최신화된 풀 리퀘스트 하나에서만 이뤄질 수 있고, 최신화된 풀 리퀘스트가 master에 병합되고 나면 적체된 나머지 풀 리퀘스트들은 병합되기 위해서는 다시 한번 최신화 되어야합니다. 이미 최신화된 풀 리퀘스트를 먼저 병합하지 않고, 다른 풀 리퀘스트를 최신화하고 먼저 병합해버리는 실수를 저지르면 이전에 최신화했던 풀 리퀘스트는 다시 최신화 해야 합니다. 동시에 열려있는 풀 리퀘스트의 개수가 적은 상황에서는 실수의 여지가 적지만 동시에 열린 풀 리퀘스트의 개수가 많아지고 Travis CI에 의한 검사가 지연되기 시작하면 이런 실수는 더 흔하게 일어납니다. 잦은 브랜치 최신화는 Travis CI 에 적체되는 작업의 개수를 늘리고, Travis CI는 동시 실행 가능 한 작업의 개수가 제한되어있기 때문에 다른 풀 리퀘스트들의 작업이 점차 지연됩니다. 이런 상황을 피하려면 풀 리퀘스트를 병합하는 작업자는 어떤 풀 리퀘스트가 최신화되었는지를 기억하고 신중하게 순차적으로 병합해야만 합니다.</p><p>이런 상황에서 병합 작업자의 부담을 줄이고, Travis CI의 작업량 부담을 줄여 병합 지연을 줄이고, 결과적으로 팀의 능률을 향상시키기 위해서 저희 코드체인 엔진 팀에서는 <a href="https://mergify.io/">Mergify</a> 를 도입하게 되었습니다. Mergify 는 GitHub과 연동되는 병합 관리 서비스로, 정책을 저장소에 포함된 .mergify.yaml 파일로 유연하게 설정 가능하고, 설정된 정책에 따라 조건에 맞는 풀 리퀘스트의 자동 병합을 진행하거나 중단할 수 있고, 다양한 동작들을 자동으로 수행할 수 있습니다.</p><p>저희 팀에서 사용중인 .mergify.yml 규칙은 다음과 같습니다. (<a href="https://github.com/CodeChain-io/codechain/blob/master/.mergify.yml">링크</a>)</p><pre>pull_request_rules:<br>  - name: Merge when CI passes and resolves all requested reviews<br>    conditions:<br>      - &quot;#approved-reviews-by&gt;=1&quot;<br>      - &quot;#review-requested=0&quot;<br>      - &quot;#changes-requested-reviews-by=0&quot;<br>      - status-success=continuous-integration/travis-ci/pr<br>      - status-success=clahub<br>      - base=master<br>      - label!=do-not-merge<br>      - &quot;- title~=\\b(wip|WIP)\\b&quot;<br>    actions:<br>      merge:<br>        method: rebase<br>        rebase_fallback: null<br>        strict: smart</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*NmHwn2c17AKxEL2mCtZ2oA.png" /><figcaption>Mergify의 작업흐름</figcaption></figure><p>이 규칙을 통해 저희 팀에서는 한 명 이상의 리뷰어가 할당되고, 리뷰가 완료되었으며, Travis CI와, <a href="https://www.clahub.com/">Clahub</a>의 검사를 통과한 master로 병합되는 풀 리퀘스트에 대해서 do-not-merge라벨이나 제목에 WIP가 붙지 않은 풀 리퀘스트들을 자동으로 병합할 수 있었습니다. 또한 병합될 때 리베이스 병합만 시도하며, strict 병합을 설정을 사용하게 설정하였습니다.</p><p>Mergify에서 strict 병합 설정을 사용하면 Mergify는 조건을 만족한 풀 리퀘스트를 자동으로 master에 대해서 최신화를 합니다. 그러나 이전에 최신화와 병합 순서를 일관되게 유지하는것이 중요한 이유에 대해서 설명했었습니다. 만약 Mergify가 무작위로 최신화와 병합을 시도한다고 하면 Travis CI 에 작업 부담이 늘어 지연되는 문제는 여전할 것입니다. 그렇기 때문에 strict:smart 옵션을 사용합니다. strict: smart 옵션을 사용하면 Mergify가 한번에 하나의 풀 리퀘스트가 최신화되고 병합되게끔 작업 큐를 관리해줍니다.</p><h3>Travis CI 를 이용한 코드 검사 및 테스트 자동화</h3><p>Mergify 는 리뷰와 Travis CI 등의 결과를 조건으로 풀 리퀘스트가 병합되는 과정을 자동화 해주는 역할만을 수행하고, 코드에서 발생할 수 있는 문제들을 점검하는 일은 Travis CI에서 이뤄집니다. GitHub에 풀 리퀘스트가 만들어지면, GitHub과의 연동에 의해서 Travis CI 에 해당 풀 리퀘스트를 검사하는 작업이 자동으로 만들어집니다. 만들어지는 작업은 저장소 루트 디렉토리의 .travis.yml 파일에 정의할 수 있는데, 코드체인 코어 프로젝트에서는 크게 두 종류의 작업이 정의됩니다. 코드의 포매팅과 작은 실수들을 점검하는 작업과, 코드체인이 배포되는 타겟 플랫폼에서 빌드가 되는 지 확인하고, 단위테스트와 E2E 테스트(the end-to-end test)를 진행하는 작업입니다. 코드체인에 정의된 작업들은 <a href="https://github.com/CodeChain-io/codechain/blob/master/.travis.yml">이 곳</a>에서 확인하실 수 있습니다.</p><p>코드체인 코어 프로젝트는 Rust 코드로 작성되어있습니다. Rust 코드의 포매팅을 점검하기 위해서는 코드 포매터인 rust-fmt 를 사용하고 있고, 코드의 작은 실수들을 점검하는데에는 린트 도구인 rust-clippy 를 사용합니다. 단위테스트들은 cargo test 를 이용해 실행되고, 이 과정에서 자연스럽게 컴파일을 시도하여 컴파일 에러를 탐지합니다. E2E 테스트는 TypeScript로 작성되는데, Rust 로 작성된 코드를 테스트하는데 사용되는 스크립트지만 이 코드 역시 관리의 대상입니다. 포매팅을 점검할 때에는 포매터 prettier를 사용하고, 코드상의 작은 실수들은 린트 도구 tslint를 이용해 점검합니다. E2E 테스트는 mocha 테스트 프레임워크로 작성되어 실행됩니다.</p><h3>Travis CI 에서 필요없는 작업의 실행시간 줄이기</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*ReJCeRt3UrdFp65T8mWs1A.png" /><figcaption>Travis CI</figcaption></figure><p>코드체인 프로젝트는 작은 프로젝트가 아니기 때문에 테스트가 완료되기까지 시간이 오래 걸립니다. Rust로 작성된 코드체인 바이너리는 빌드하는데만 십수분이 걸리고, E2E 테스트는 실제 운용되는 환경과 흡사하게 빌드된 바이너리를 띄워 서로 합의하기를 기다리며 다양한 테스트를 수행하기 때문에 삼십분까지 걸립니다. 모든 작업을 직렬로 수행하면 1시간 20분가량의 시간이 소요되고, 풀 리퀘스트 하나가 만들어지면 이 작업들은 풀 리퀘스트가 처음 만들어졌을 때 풀 리퀘스트 브랜치에서 한 번, 병합하기 위해 최신화 한 직후에 풀 리퀘스트 브랜치에서 또 한 번, 그리고 master에 병합된 직후에 master 브랜치에서 마지막으로 또 한 번 총 세 번 수행되어 도합 4시간이 걸립니다. Travis CI 가 오픈소스 프로젝트에 제공하는 무료 플랜은 동시 작업 개수를 4개로 제한하고 있는데, 그러면 근무시간 8시간 동안 제공되는 총 작업시간은 8 * 4 = 32 시간에 불과합니다. 하루에 최대 8개의 풀 리퀘스트만을 만들 수 있다는 말과 같습니다. 리뷰에 의한 코드 변경과 work-in-progress 풀 리퀘스트에 의해 추가로 만들어지는 작업에 의해 이 개수는 크게 줄어들고, 풀 리퀘스트 점검 작업은 점차 밀리게 됩니다. 우리는 작업에 소요되는 시간을 최적화 할 필요가 있었습니다.</p><p>저희는 <a href="https://travis-ci.org/">Travis CI</a> 에서 수행되는 불필요한 작업은 최대한 일찍 끝날 수 있게 최적화했습니다. Travis CI에서는 <a href="https://docs.travis-ci.com/user/conditions-v1">조건부로 작업을 정의하는 방법</a>을 제공하고 있지만, 접근 가능한 정보가 제한적이고 DSL의 자유도가 낮기 때문에 좀 더 유연한 셸 스크립트를 이용해 정의된 작업을 일찍 끝내는 방식으로 이뤄졌습니다. 셸 스크립트로 일찍 끝내는 작업의 종류는 다음과 같습니다.</p><ol><li>풀 리퀘스트가 빌드에 영향을 주지 않는 문서의 변경사항만을 포함하고 있으면 테스트를 수행하지 않습니다.</li><li>E2E 테스트만 변경된 경우 유닛테스트를 수행하지 않습니다.</li><li>mergify에 의해서 master로 자동 병합된 직후 master 브랜치에서 수행되는 병합 테스트는 수행하지 않습니다. strict 병합 설정과, 리베이스 병합 정책으로 인해 풀 리퀘스트가 최신화된 직후와 동일하기 때문입니다.</li></ol><p>이런 조건을 검사하고 작업을 즉시 중단하는 셸 스크립트를 작성하는것은 쉽습니다. 그러나 Travis CI 라는 특수한 상황에서 재활용 가능한 스크립트를 작성하기 위해서는 추가적인 고려가 필요했습니다. Mergify 에 의해 자동으로 병합이 진행되기 위해서는 작업이 일찍 끝내져도 Travis CI 를 “성공” 상태로 보고하게 만들어야 하고, 버그가 없는 코드는 없기 때문에 셸 스크립트 역시 예기치 못한 오류가 생기면 작업을 중단하고 “실패” 상태로 보고해야하며, 셸 스크립트는 무슨 커맨드를 실행했는 지 로그를 남기고 확인할 수 있어야 합니다.</p><p>셸 스크립트의 로그와 오류시 실패 상태를 남기며 즉시 중단하기는 상대적으로 간단했습니다. 배시 셸에는 set 명령어로 켜고 끌 수 있는 플래그가 몇가지 있는데 그 중 e 플래그와 v(혹은 x)플래그를 켜는것으로 해결됩니다. set -e 로 e플래그를 켜면 셸 스크립트 내의 커맨드에서 오류가 발생해 0 이외의 종료코드가 발생하면 즉시 해당 셸을 중단하고, 마지막으로 실패한 커맨드의 종료코드를 셸의 종료코드로 삼습니다. .travis.yml에 기재된 커맨드가 0이 아닌 종료코드로 종료되면 Travis CI는 해당 작업을 중단하고 “실패”로 보고합니다. set -v로 v플래그를 켜면 셸 스크립트 내에서 어떤 커맨드가 실행됐는지 출력합니다. v 대신에 x 플래그를 켜면, 커맨드 인자로 변수들이 전달될 때, 변수들이 어떤 값 이었는지를 확장해서 보여줍니다.</p><p>그러나 Travis CI의 작업을 “성공” 상태로 중단하는것은 셸 스크립트 내에서는 불가능했습니다. exit 0이나, travis_terminate 0와 같은 명령어는 셸 스크립트 내에서 호출했을 때 셸 자체를 중단시키는데 그치고 Travis CI의 작업을 중단시키지 않았습니다. 셸 내부에서 외부로 작업을 “중단”할것인지, “재개”할 것인지 리턴할 필요가 있었습니다. 일반적으로 서브 셸에서 값을 리턴할 때에는 두 가지 방법이 사용됩니다. 하나는 종료 코드를 리턴하는 방법이고, 나머지 하나는 표준출력으로 결과를 출력하고 부모 셸에서 표준출력을 캡쳐해 사용하는 방법입니다. 하지만 셸의 종료코드는 Travis 작업의 “실패” 여부를 판별하는데 이미 사용되고 있었고, 표준출력은 셸 스크립트의 일반 커맨드들이 상황을 로그하는데 사용하고 있었던 상황이었습니다.</p><p>그러나 Travis CI 가 표준출력 이외에 로그로 남기는게 하나 더 있습니다. 바로 표준 오류입니다. 유닉스 계열 운영체제에서는 프로세스를 실행하면 외부와 상호작용하는 세 개의 표준 스트림을 만듭니다. 파일디스크립터 0에 지정된 표준 입력, 1에 지정된 표준 출력, 2에 지정된 표준 오류입니다. 인터랙티브 셸의 경우에 표준 입력은 키보드로부터 입력을 받는데 사용되고, 표준 출력은 터미널 화면에 텍스트를 출력하기 위해 사용됩니다. 그리고 표준 오류는 표준 출력과는 구분되는 스트림으로 프로그램의 오류를 출력하기 위해 사용됩니다. 그리고 Travis CI는 표준 오류 스트림도 로그로 남깁니다.</p><p>저희 스크립트들은 이 점을 이용해 서브셸에서 값을 리턴함과 동시에 Travis CI 에 커맨드 실행 내역을 로그로 남길 수 있었습니다. 배시 셸은 강력한 입출력 리디렉션 기능을 가지고 있습니다. 셸 내에서 실행되는 개별 커맨드에 대해서 입출력을 리디렉션 할수도 있지만 셸 전체의 입출력의 리디렉션을 제어할 수도 있습니다. 저희는 다음과 같은 배시 커맨드를 이용해 셸 내에서 발생하는 모든 표준 출력(fd 1)을 셸 밖의 표준 오류(fd 2)로 리디렉션 시켰고, 셸 내에서 fd 3으로 출력되는 출력을 셸 밖의 표준 출력(fd 1)으로 리디렉션 시켰습니다.</p><pre>exec 3&gt;&amp;1 1&gt;&amp;2</pre><p>셸은 RESULT=$(./foo-bar) 와 같이 서브 셸의 표준출력을 캡쳐해 변수에 저장할 수 있는데, FD3을 표준출력으로 리디렉션하면 서브셸에서 echo skip &gt;&amp;3 echo noskip &gt;&amp;3 처럼 리턴값을 전달하기 위한 스트림으로 사용할 수 있습니다. 이것을 이용하여 Travis CI의 .travis.yml 에서 작업을 일찍 중단할 것인지를 결정하는 셸 스크립트를 실행하고, 리턴 값을 받아 `exit 0` 커맨드를 직접 호출합니다. 이렇게 하면 Travis CI 작업을 “성공”상태로 남김과 동시에 일찍 중단할 수 있습니다.</p><p>./.travis/check-foo</p><pre>#!/usr/bin/env bash</pre><pre>set -ex;<br>exec 3&gt;&amp;1 1&gt;&amp;2</pre><pre>function return_to_travis { echo $1 &gt;&amp;3; }</pre><pre>if some_condition_foo; then <br>  echo “Skipped!”; <br>  return_to_travis “skip”; <br>else <br>  echo “Don’t Skip!”<br>  return_to_travis “noskip”<br>fi</pre><p>.travis.yml</p><pre>RESULT=$(./.travis/check-foo); if [ “$RESULT” = “skip” ]; then terminate_travis 0; fi;</pre><p>이것들을 취합하면 셸 스크립트와 Travis CI 스크립트는 위와 같습니다. 일반 커맨드들의 모든 표준출력을 표준오류 스트림으로 일괄 리디렉션 함으로써 개별 커맨드들을 일일이 리디렉션하지 않고 평소 셸 스크립트를 작성하던대로 셸을 작성해도 Travis CI 에 실행 로그가 남고, set -e 플래그를 켜서 셸 스크립트 내의 커맨드에서 예기치 못한 오류가 나면 오류와 함께 중단되고, 원하는 경우 “성공” 상태 보고와 함께 일찍 중지시킬 수 있는 Travis CI 스크립트입니다.</p><p>이번 글에서는 저희가 코드체인 코어 프로젝트의 건강한 상태를 유지하고 팀의 생산성을 향상시키기 위해 CI를 활용하고 있는지 소개해드렸습니다. Mergify 로는 GitHub 풀 리퀘스트의 작업 흐름을 자동화시켜 개발자들의 일손을 덜고, Travis CI 상에서 실행되는 다양한 검사 도구들은 코드의 이상을 풀 리퀘스트 수준에서 탐지하여 코드베이스로 이상이 흘러들어가는것을 미연에 방지합니다. 또한 Travis CI의 작업은 필요한 경우에만 확인작업을 수행하게 설정되어 한정된 자원을 최대한으로 활용합니다. 저희 CI 환경은 처음부터 이런 모습을 갖추고 있지는 않았습니다. GitHub을 중심으로 개발하면서 마주하는 다양한 생산성 문제들을 해결해 나가며 현재와 같은 모습을 갖추게 되었습니다. 앞으로도 저희의 프로젝트는 계속 될 것이고, 코드와 환경은 꾸준히 변해나갈 것 입니다. 그에 맞춰 저희 CI 환경 역시도 생산성 향상을 위해 꾸준히 변해나갈 것입니다.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa77f4a9c7d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/codechain-kr/%EC%BD%94%EB%93%9C%EC%B2%B4%EC%9D%B8%EC%97%90%EC%9D%98-%EC%A7%80%EC%86%8D%EC%A0%81-%ED%86%B5%ED%95%A9-%ED%99%98%EA%B2%BD-%EA%B5%AC%EC%84%B1-fa77f4a9c7d4">코드체인에의 지속적 통합 환경 구성</a> was originally published in <a href="https://medium.com/codechain-kr">코드체인</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>