<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # Shell scripting standards and style guidelines > 原文:[https://docs.gitlab.com/ee/development/shell_scripting_guide/](https://docs.gitlab.com/ee/development/shell_scripting_guide/) * [Overview](#overview) * [Avoid using shell scripts](#avoid-using-shell-scripts) * [Scope of this guide](#scope-of-this-guide) * [Shell language choice](#shell-language-choice) * [Code style and format](#code-style-and-format) * [Linting](#linting) * [Formatting](#formatting) * [Testing](#testing) * [Code Review](#code-review) # Shell scripting standards and style guidelines[](#shell-scripting-standards-and-style-guidelines "Permalink") ## Overview[](#overview "Permalink") GitLab 由許多不同的服務和子項目組成. 他們的大多數后端代碼都是用[Ruby](https://www.ruby-lang.org)和[Go](https://s0golang0org.icopy.site)編寫的. 但是,其中一些使用 shell 腳本來自動化日常系統管理任務,例如部署,安裝等.之所以這樣做是出于歷史原因,或者是為了最大程度地減少對 Docker 映像的依賴性. 該頁面旨在根據我們的各種經驗來定義和組織我們的 Shell 腳本編寫準則. GitLab 項目中的所有 Shell 腳本最終都應與本指南保持一致. 如果每個項目與本指南存在差異,則應在此類項目的`README.md`或`PROCESS.md`文件中進行說明. ### Avoid using shell scripts[](#avoid-using-shell-scripts "Permalink") **注意:**這是必讀部分. 綜上所述,我們建議盡可能遠離 Shell 腳本. 像 Ruby 或 Python 這樣的語言(如果需要與我們利用的代碼庫保持一致),幾乎總是一個更好的選擇. 高級解釋語言具有更易讀的語法,為單元測試,整理和錯誤報告提供了更成熟的功能. 僅在對項目的依賴項大小有嚴格限制或在特定情況下更重要的任何其他要求時,才使用 Shell 腳本. ## Scope of this guide[](#scope-of-this-guide "Permalink") 根據[GitLab 安裝要求](../../install/requirements.html) ,本指南僅涵蓋受[支持的 Linux 發行版](../../install/requirements.html#supported-linux-distributions)使用的那些 shell,即: * [POSIX Shell](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html) * [Bash](https://www.gnu.org/software/bash/) ## Shell language choice[](#shell-language-choice "Permalink") * 當您需要減少依賴關系列表時,請使用環境提供的內容. 例如,對于泊塢圖片是`sh`從`alpine`這是基本的圖像對于大多數我們的工具的圖像. * 如果可能,請在其他任何地方使用`bash` . 它比`sh`更強大,但仍然是廣泛使用的 shell. ## Code style and format[](#code-style-and-format "Permalink") 本節描述了包含外殼程序腳本的工具,這些工具應成為項目 CI 管道的必需部分. 這些工具可自動執行 Shell 代碼格式化,檢查錯誤或漏洞等. ### Linting[](#linting "Permalink") 我們在默認配置中使用[ShellCheck](https://www.shellcheck.net/)實用程序來[整理](https://www.shellcheck.net/)我們的 Shell 腳本. 所有帶有 shell 腳本的項目都應使用此 GitLab CI / CD 作業: ``` shell check: image: koalaman/shellcheck-alpine:stable stage: test before_script: - shellcheck --version script: - shellcheck scripts/**/*.sh # path to your shell scripts ``` **提示:**默認情況下,ShellCheck 將使用[外殼檢測](https://github.com/koalaman/shellcheck/wiki/SC2148#rationale)來確定使用中的外殼方言. 如果 shell 文件不在您的控制范圍內,并且 ShellCheck 無法檢測到方言,請使用`-s`標志指定它: `-s sh`或`-s bash` . ### Formatting[](#formatting "Permalink") 建議使用[shfmt](https://github.com/mvdan/sh#shfmt)工具來保持一致的格式. 我們根據《 [Google Shell 樣式指南》設置](https://google.github.io/styleguide/shell.xml)外殼腳本的格式,因此以下`shfmt`調用應應用于項目的腳本文件: ``` shfmt -i 2 -ci -w scripts/**/*.sh ``` 除了[Linting](#linting) GitLab CI / CD 作業外,所有帶有 shell 腳本的項目也應使用此作業: ``` shfmt: image: mvdan/shfmt:v3.1.0-alpine stage: test before_script: - shfmt -version script: - shfmt -i 2 -ci -d scripts # path to your shell scripts ``` **提示:**默認情況下,shfmt 將使用類似于 ShellCheck 之一的[shell 檢測](https://github.com/mvdan/sh#shfmt) ,并忽略以句點開頭的文件. 要覆蓋它,請使用`-ln`標志來指定 shell 方言: `-ln posix`或`-ln bash` . ## Testing[](#testing "Permalink") **注意:**這是一項正在進行的工作. 評估各種工具以自動測試 Shell 腳本(例如[BATS](https://github.com/bats-core/bats-core) )是一項[持續的工作](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/64016) . ## Code Review[](#code-review "Permalink") 代碼審查應根據以下條件執行: * [ShellCheck Checks list](https://github.com/koalaman/shellcheck/wiki/Checks) * [Google Shell Style Guide](https://google.github.io/styleguide/shell.xml) * [Shfmt formatting caveats](https://github.com/mvdan/sh#caveats) 但是,建議采取的措施是使用上述工具并處理報告的違法行為. 這應該消除對代碼審查的需要. * * * [Return to Development documentation](../README.html).
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看