go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/swarming/proto/update.sh (about)

     1  #!/bin/bash
     2  # Copyright 2019 The LUCI Authors.
     3  #
     4  # Licensed under the Apache License, Version 2.0 (the "License");
     5  # you may not use this file except in compliance with the License.
     6  # You may obtain a copy of the License at
     7  #
     8  #      http://www.apache.org/licenses/LICENSE-2.0
     9  #
    10  # Unless required by applicable law or agreed to in writing, software
    11  # distributed under the License is distributed on an "AS IS" BASIS,
    12  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  # See the License for the specific language governing permissions and
    14  # limitations under the License.
    15  
    16  set -eu
    17  
    18  cd "$(dirname $0)"
    19  
    20  LUCI_ROOT=../../../../../../luci
    21  
    22  function import_dir() {
    23    local src_dir=${1}
    24    local dst_dir=${2}
    25  
    26    echo "- ${dst_dir}: cleaning existing files"
    27    rm -f ${dst_dir}/*.proto
    28    rm -f ${dst_dir}/*.pb.go
    29    rm -f ${dst_dir}/*_dec.go
    30    rm -f ${dst_dir}/pb.discovery.go
    31  
    32    echo "- ${dst_dir}: copy the proto files from luci-py"
    33    cp ${src_dir}/*.proto ${dst_dir}
    34  
    35    echo "- ${dst_dir}: fix import paths"
    36    sed -i 's#import "proto/#import "go.chromium.org/luci/swarming/proto/#' ${dst_dir}/*.proto
    37  }
    38  
    39  function add_luci_file_metadata() {
    40    local proto=${1}
    41    local cfg_file=${2}
    42  
    43    local fragment=(
    44      "\n"
    45      "import \"go.chromium.org/luci/common/proto/options.proto\";\n"
    46      "\n"
    47      "option (luci.file_metadata) = {\n"
    48      "  doc_url: \"https://config.luci.app/schemas/services/swarming:${cfg_file}\";\n"
    49      "};"
    50    )
    51    local joined=`printf '%s' "${fragment[@]}"`
    52  
    53    sed -i "s#option go_package = \"\\(.*\\)\";#option go_package = \"\\1\";\\n${joined}#" ${proto}
    54  }
    55  
    56  import_dir ${LUCI_ROOT}/appengine/swarming/proto/api api
    57  import_dir ${LUCI_ROOT}/appengine/swarming/proto/config config
    58  import_dir ${LUCI_ROOT}/appengine/swarming/proto/internals internals
    59  import_dir ${LUCI_ROOT}/appengine/swarming/proto/api_v2 api_v2
    60  
    61  echo "- adding luci.file_metadata option"
    62  add_luci_file_metadata config/bots.proto bots.cfg
    63  add_luci_file_metadata config/config.proto settings.cfg
    64  add_luci_file_metadata config/pools.proto pools.cfg
    65  
    66  echo "- regenerating Go code"
    67  go generate ./...
    68  
    69  echo "- updating README.md"
    70  pushd ${LUCI_ROOT} > /dev/null
    71  LUCI_REV=`git rev-parse HEAD`
    72  popd > /dev/null
    73  sed -i "s#Revision: .*#Revision: ${LUCI_REV}#" README.md