From 1684a4063ae7b8b076f2ef3601a13cbc5ee7989a Mon Sep 17 00:00:00 2001 From: Kareem Khazem Date: Fri, 4 Jun 2021 20:44:41 +0100 Subject: [PATCH 1/3] Use private submodules before CI run The CBMC CI will now replace some of the submodules in this repository with 'private' versions if the CI run was triggered by the private version of this repository. --- cbmc-ci/ci-config.yaml | 5 +- cbmc-ci/switch-private-submodules | 102 ++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 1 deletion(-) create mode 100755 cbmc-ci/switch-private-submodules diff --git a/cbmc-ci/ci-config.yaml b/cbmc-ci/ci-config.yaml index 94d3c51f0..6d4602e25 100644 --- a/cbmc-ci/ci-config.yaml +++ b/cbmc-ci/ci-config.yaml @@ -22,4 +22,7 @@ behaviors: checkout-script: - - git submodule update --init –-checkout --recursive + # If this is the private version of the repository, we need to pull in + # the private versions of the submodules. + - "echo Originating GitHub repository: ${GITHUB_REPOSITORY}" + - cbmc-ci/switch-private-submodules --verbose env diff --git a/cbmc-ci/switch-private-submodules b/cbmc-ci/switch-private-submodules new file mode 100755 index 000000000..adc0d3daa --- /dev/null +++ b/cbmc-ci/switch-private-submodules @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"). You +# may not use this file except in compliance with the License. A copy of +# the License is located at +# +# http://aws.amazon.com/apache2.0/ +# +# or in the "license" file accompanying this file. This file is +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF +# ANY KIND, either express or implied. See the License for the specific +# language governing permissions and limitations under the License. + + +import argparse +import logging +import os +import subprocess +import sys + + +DESCRIPTION = "Switch between public and private versions of submodules" + +MODULES = [{ + "submodule": "aws-encryption-sdk-cpp/tests/test_vectors/aws-encryption-sdk-test-vectors", + "private": "https://github.com/awslabs/private-aws-encryption-sdk-test-vectors-staging.git", + "public": "https://github.com/awslabs/aws-encryption-sdk-test-vectors.git", +}, { + "submodule": "aws-encryption-sdk-specification", + "private": "https://github.com/awslabs/private-aws-encryption-sdk-specification-staging.git", + "public": "https://github.com/awslabs/aws-encryption-sdk-specification.git", +}] + + +def switch_to(version): + logging.info("Switching to %s version of the submodules", version) + for module in MODULES: + cmd = [ + "git", "config", "--file=.gitmodules", + f"submodule.{module['submodule']}.url", + module[version]] + logging.info(" ".join(cmd)) + subprocess.run(cmd, check=True) + + subprocess.run(["git", "submodule", "sync"], check=True) + subprocess.run([ + "git", "submodule", "update", "--init", "--recursive", "--checkout"], + check=True) + + +def switch_to_env(_): + repo = os.getenv("GITHUB_REPOSITORY") + if not repo: + logging.error( + "Could not determine which submodules to check out " + "($GITHUB_REPOSITORY is not set).") + sys.exit(1) + + if repo == "aws/private-aws-encryption-sdk-c-staging": + switch_to("private") + else: + switch_to("public") + + +OPERATIONS = { + "public": switch_to, + "private": switch_to, + "env": switch_to_env, +} + + +def main(): + pars = argparse.ArgumentParser(description=DESCRIPTION) + for arg in [{ + "flags": ["operation"], + "choices": list(OPERATIONS.keys()), + "default": "public", + "help": "Switch to public or private versions of the submodules, " + "or decide which by reading the $GITHUB_REPOSITORY " + "environment variable. Default: %(default)s." + }, { + "flags": ["-v", "--verbose"], + "action": "store_true", + "help": "verbose output", + }]: + flags = arg.pop("flags") + pars.add_argument(*flags, **arg) + args = pars.parse_args() + + fmt = "switch-private-submodules: %(message)s" + if args.verbose: + logging.basicConfig(format=fmt, level=logging.INFO) + else: + logging.basicConfig(format=fmt, level=logging.WARNING) + + OPERATIONS[args.operation](args.operation) + + +if __name__ == "__main__": + main() From f0d34ba46ee0461d6f88f2ed2c02ac5981b527b9 Mon Sep 17 00:00:00 2001 From: Kareem Khazem Date: Tue, 8 Jun 2021 22:02:29 +0100 Subject: [PATCH 2/3] [squash] Move switch-private-submodules script to repo root --- cbmc-ci/ci-config.yaml | 2 +- cbmc-ci/switch-private-submodules => switch-private-submodules | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename cbmc-ci/switch-private-submodules => switch-private-submodules (100%) diff --git a/cbmc-ci/ci-config.yaml b/cbmc-ci/ci-config.yaml index 6d4602e25..8d50f1655 100644 --- a/cbmc-ci/ci-config.yaml +++ b/cbmc-ci/ci-config.yaml @@ -25,4 +25,4 @@ checkout-script: # If this is the private version of the repository, we need to pull in # the private versions of the submodules. - "echo Originating GitHub repository: ${GITHUB_REPOSITORY}" - - cbmc-ci/switch-private-submodules --verbose env + - ./switch-private-submodules --verbose env diff --git a/cbmc-ci/switch-private-submodules b/switch-private-submodules similarity index 100% rename from cbmc-ci/switch-private-submodules rename to switch-private-submodules From 8e347c1581253ad56624cfcf0bf04f724098a115 Mon Sep 17 00:00:00 2001 From: Kareem Khazem Date: Tue, 8 Jun 2021 22:05:40 +0100 Subject: [PATCH 3/3] [squash] Use local .git/config insteadOf --- switch-private-submodules | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/switch-private-submodules b/switch-private-submodules index adc0d3daa..d9c6ddfa8 100755 --- a/switch-private-submodules +++ b/switch-private-submodules @@ -38,9 +38,10 @@ def switch_to(version): logging.info("Switching to %s version of the submodules", version) for module in MODULES: cmd = [ - "git", "config", "--file=.gitmodules", - f"submodule.{module['submodule']}.url", - module[version]] + "git", "config", + f'url."{module[version]}".insteadOf', + module["public"], + ] logging.info(" ".join(cmd)) subprocess.run(cmd, check=True)