mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 19:10:14 +01:00
Our mirror repositories contain vim scripts and textmate grammars, neither of which have any need for the LLVM exception, so we can use the base Apache 2.0 license there with no loss of relevant permissions. This is a compatible license, so providing these repositories under these license terms is valid. Other than removing the LLVM exception, the new license file has one other change compared to LICENSE: the amount of whitespace on some lines is reduced from four spaces to three. This makes the new license *exactly* match the Apache 2.0 license, byte-for-byte. This is important because the license checking done by GitHub's linguist project doesn't recognize Apache-2.0-with-LLVM-exception as an acceptable license, but does allow plain Apache-2.0.
84 lines
2.5 KiB
Bash
Executable File
84 lines
2.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#
|
|
# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
# Exceptions. See /LICENSE for license information.
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
#
|
|
# Sync directories in the main Carbon repository into dedicated child
|
|
# repositories to better match repository-oriented installing and tooling.
|
|
|
|
set -eux
|
|
|
|
ORIGIN_DIR="$PWD"
|
|
COMMIT_SHA="$(git rev-parse --short $GITHUB_SHA)"
|
|
COMMIT_SUMMARY="Original $(git show -s --pretty=full "$COMMIT_SHA")
|
|
|
|
$(git diff --summary "${COMMIT_SHA}^!")
|
|
"
|
|
|
|
# Setup global git configuration.
|
|
GIT_USERNAME="CarbonInfraBot"
|
|
git config --global user.email "infra-role@carbon-lang.dev"
|
|
git config --global user.name "$GIT_USERNAME"
|
|
|
|
declare -A MIRRORS
|
|
MIRRORS["utils/vim"]="vim-carbon-lang"
|
|
MIRRORS["utils/textmate"]="carbon.tmbundle"
|
|
|
|
for dir in "${!MIRRORS[@]}"; do
|
|
SRC_DIR="$dir"
|
|
DEST_REPO="${MIRRORS[$SRC_DIR]}"
|
|
DEST_REPO_URL="https://$GIT_USERNAME:$API_TOKEN_GITHUB@github.com/carbon-language/$DEST_REPO.git"
|
|
DEST_CLONE_DIR="$(mktemp -d)"
|
|
|
|
git clone --single-branch "$DEST_REPO_URL" "$DEST_CLONE_DIR"
|
|
cd "$DEST_CLONE_DIR"
|
|
|
|
# Print out the destination repository to help with debugging failures in
|
|
# GitHub's actions.
|
|
ls -al
|
|
|
|
# Remove all the existing files to rebuild it from scratch. We ignore when
|
|
# this matches no files to handle freshly created repositories. Also print the
|
|
# status afterward for debugging.
|
|
git rm --ignore-unmatch -r .
|
|
git status
|
|
|
|
# Restore the license file. The mirrors use the Apache 2.0 license, which is
|
|
# compatible with our license but excludes the LLVM exception.
|
|
git checkout HEAD LICENSE
|
|
|
|
# Copy the basic framework from the origin repository.
|
|
cp "$ORIGIN_DIR/.gitignore" \
|
|
"$ORIGIN_DIR/CODE_OF_CONDUCT.md" \
|
|
.
|
|
|
|
# Copy the mirrored directory. We use `rsync` to get a more reliable way of
|
|
# handling the mirroring of the contents of a directory. We also make this
|
|
# verbose to help with debugging action failures on GitHub.
|
|
rsync -av "$ORIGIN_DIR/$SRC_DIR/" .
|
|
|
|
# Add back all the files now, and print the status for debugging.
|
|
git add -A
|
|
git status
|
|
|
|
# See if there is anything to commit and push. This works the same way as
|
|
# diff(1) and so exits zero when there are no changes.
|
|
if ! git diff --cached --quiet; then
|
|
# Commit the new state.
|
|
git commit -F- <<EOF
|
|
Sync $DEST_REPO to carbon-language/carbon-lang@$COMMIT_SHA
|
|
|
|
$COMMIT_SUMMARY
|
|
EOF
|
|
git log
|
|
|
|
# Push the new commit.
|
|
git push
|
|
fi
|
|
|
|
# Cleanup.
|
|
cd "$ORIGIN_DIR"
|
|
rm -rf "$DEST_CLONE_DIR"
|
|
done
|