Skip to content

Sync moto-ext with upstream #62

Sync moto-ext with upstream

Sync moto-ext with upstream #62

Workflow file for this run

# LocalStack specific workflow to implement a fully-integrated continuous integration pipeline for Moto-Ext
# - Rebase this fork based on the latest commit on `main` of upstream
name: Sync moto-ext with upstream
on:
workflow_dispatch:
inputs:
dry_run:
description: 'Dry run'
default: true
required: true
type: boolean
# TODO: remove
pull_request:
# Limit concurrency to 1
concurrency:
group: ${{ github.workflow }}
jobs:
sync-moto-ext:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: localstack
persist-credentials: false
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Configure Git
run: |
# Configure git
git config --global user.name 'LocalStack Bot'
git config --global user.email 'localstack-bot@users.noreply.github.com'
git remote set-url origin https://git:${{ secrets.PRO_ACCESS_TOKEN }}@github.com/${{ github.repository }}
# make sure to switch to the `localstack` branch (default / main branch of this fork)
git switch localstack
# add moto upstream as remote
git remote add upstream https://github.com/getmoto/moto.git
# rebase with latest changes
git pull
# Create a custom merge driver which prefers everything from upstream _BUT_ the name and the URL
mkdir -p $HOME/.local/bin
cat > $HOME/.local/bin/git-prefer-theirs-name-url << EOF
#!/bin/bash
set -e
base="\$1"
local="\$2"
remote="\$3"
echo "Executing custom merge driver for base \$base, local \$local, remote \$remote."
# Define keys to keep
KEYS=("name" "url")
# Read files into arrays
mapfile -t REMOTE_LINES < "\$remote"
mapfile -t LOCAL_LINES < "\$local"
echo "merging \$local + \$local + \$remote ..."
# Function to check if a line should be kept (matches any key)
keep_line() {
local line="\$1"
for key in "\${KEYS[@]}"; do
[[ "\$line" == *"\$key"* ]] && return 0
done
return 1
}
# keep key-matched lines from local, others from remote
for i in "\${!LOCAL_LINES[@]}"; do
if keep_line "\${REMOTE_LINES[i]}"; then
echo "\${REMOTE_LINES[i]}"
else
echo "\${LOCAL_LINES[i]}"
fi
done > "\$local"
exit 0
EOF
# make the script executable and add it to the PATH
chmod +x $HOME/.local/bin/git-prefer-theirs-name-url
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
# add the merge driver to the git config
cat >> .git/config << EOF
[merge "git-prefer-theirs-name-url"]
name = A driver which resolves merge conflicts on a setup.cfg such that it always takes the local name and url, and everything else from upstream
driver = git-prefer-theirs-name-url %O %A %B
EOF
# define to use the custom merge driver for the setup.cfg
cat > .gitattributes << EOF
setup.cfg merge=git-prefer-theirs-name-url
EOF
- name: Rebase localstack branch with latest master from upstream
run: |
git fetch upstream
git rebase -f upstream/master
- name: Push
if: ${{ github.event.inputs.dry_run != 'true' }}
run: |
git push --force-with-lease
git push --atomic origin localstack
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}