diff --git a/.github/workflows/sync-from-aptos-core.yaml b/.github/workflows/sync-from-aptos-core.yaml new file mode 100644 index 000000000..c4aa7d596 --- /dev/null +++ b/.github/workflows/sync-from-aptos-core.yaml @@ -0,0 +1,73 @@ +name: Sync from aptos-core + +on: + workflow_dispatch: + +permissions: + contents: read + id-token: write + +# env: + # GH_TOKEN: ${{ github.token }} + +jobs: + sync: + runs-on: runs-on,runner=2cpu-linux-x64,run-id=${{ github.run_id }} + steps: + # Set up the git credentials for the job (using the aptos-bot personal access token) + - uses: oleksiyrudenko/gha-git-credentials@v2.1.1 + with: + global: true + name: "aptos-bot" + token: ${{ secrets.APTOS_BOT_CLONE_GH_PAT }} + + # Reconfigure the git url and credentials such that calling 'git clone ' will work + - name: Set github url and credentials + run: | + /usr/bin/git config --global --add url."https://${{ secrets.APTOS_BOT_CLONE_GH_PAT }}:x-oauth-basic@github".insteadOf ssh://git@github + /usr/bin/git config --global --add url."https://${{ secrets.APTOS_BOT_CLONE_GH_PAT }}:x-oauth-basic@github".insteadOf https://github + /usr/bin/git config --global --add url."https://${{ secrets.APTOS_BOT_CLONE_GH_PAT }}:x-oauth-basic@github".insteadOf git@github + + - uses: bazel-contrib/setup-bazel@0.8.5 + with: + # Avoid downloading Bazel every time. + bazelisk-cache: true + # Store build cache per workflow. + disk-cache: ${{ github.workflow }} + # Share repository cache between workflows. + repository-cache: true + bazelisk-version: 1.x + + - name: Checkout copybara + uses: actions/checkout@v4 + with: + repository: google/copybara + path: copybara + ref: cdfcc084dd39774abd9b712e00064c7a0092ff7b + + - name: Build copybara + working-directory: copybara + run: | + set -x + bazel build //java/com/google/copybara:copybara_deploy.jar + cp bazel-bin/java/com/google/copybara/copybara_deploy.jar /usr/local/bin/ + cat <<'EOF' > /usr/local/bin/copybara + #!/bin/bash -e + + java -jar /usr/local/bin/copybara_deploy.jar "$@" + EOF + + chmod +x /usr/local/bin/copybara + + - name: Checkout aptos-framework + uses: actions/checkout@v4 + with: + path: aptos-framework + + - name: Sync all branches + working-directory: aptos-framework + run: | + set -x + PATH=$PATH:/usr/local/bin/ + ./sync.sh + diff --git a/README.md b/README.md deleted file mode 100644 index 4c1408c37..000000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -# aptos-framework \ No newline at end of file diff --git a/copy.bara.sky.template b/copy.bara.sky.template new file mode 100644 index 000000000..2b8c074dc --- /dev/null +++ b/copy.bara.sky.template @@ -0,0 +1,31 @@ +def foo(ctx): + for change in ctx.changes.current: + print(change) + +core.workflow( + name = "push_move_libraries_direct", + origin = git.github_origin( + url = "https://github.com/aptos-labs/aptos-core.git", + ref = "PLACEHOLDER_BRANCH", + ), + destination = git.github_destination( + url = "https://github.com/aptos-labs/aptos-framework.git", + push = "PLACEHOLDER_BRANCH", + ), + mode = "ITERATIVE", + origin_files = glob([ + "aptos-move/framework/move-stdlib/**", + "aptos-move/framework/aptos-framework/**", + "aptos-move/framework/aptos-names/**", + "aptos-move/framework/aptos-stdlib/**", + "aptos-move/framework/aptos-token/**", + "aptos-move/framework/aptos-token-objects/**", + ]), + destination_files = glob(["**"]), + authoring = authoring.pass_thru("Victor "), + transformations = [ + core.move("aptos-move/framework", ""), + + core.dynamic_transform(impl = foo, params = {}), + ], +) diff --git a/sync.sh b/sync.sh new file mode 100755 index 000000000..87afb9c9a --- /dev/null +++ b/sync.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -ex +set -o pipefail + +SOURCE_REPO_URL="https://github.com/aptos-labs/aptos-core.git" +DESTINATION_REPO_URL="https://github.com/aptos-labs/aptos-framework.git" +COPYBARA_CONFIG="copy.bara.sky.template" +BRANCH_PREFIX="aptos_release_" +EXACT_BRANCH_NAMES=("mainnet") + +# Fetch all branches from the source repository +branches=$(git ls-remote --heads $SOURCE_REPO_URL | awk '{print $2}' | sed 's|refs/heads/||') + +# Iterate over each branch and run Copybara for branches with the specified prefix or exact name +for branch in $branches; do + if [[ $branch == $BRANCH_PREFIX* ]] || [[ " ${EXACT_BRANCH_NAMES[@]} " =~ " ${branch} " ]]; then + echo "Syncing branch: $branch" + + # Create a temporary Copybara config with the current branch + sed "s/PLACEHOLDER_BRANCH/$branch/g" $COPYBARA_CONFIG > copy.bara.sky + + # Run Copybara with the temporary config + copybara migrate copy.bara.sky push_move_libraries_direct --init-history --force + + # Clean up the temporary config + rm copy.bara.sky + fi +done