1- # LocalStack specific workflow to implement a fully-integrated continuous integration pipeline for our fork
1+ # LocalStack specific workflow to implement a fully-integrated continuous integration pipeline for Moto-Ext
22# - Rebase this fork based on the latest commit on `main` of upstream
3- # - Build a Python source and wheel distribution of moto-ext with deterministic versioning
4- # - Publish the distributions to PyPi
5- # - Tag the commit in this fork with the new version
6- # - Create a GitHub release for the new version
73
8- name : Sync / Release moto-ext
4+ name : Sync moto-ext with upstream
95
106on :
11- schedule :
12- - cron : 0 5 * * MON
137 workflow_dispatch :
148 inputs :
159 dry_run :
16- description : ' Dry Run? '
10+ description : ' Dry run '
1711 default : true
1812 required : true
1913 type : boolean
2014
21- # limit concurrency to 1
15+ # Limit concurrency to 1
2216concurrency :
2317 group : ${{ github.workflow }}
2418
2519jobs :
26- sync-build-release- moto-ext :
20+ sync-moto-ext :
2721 runs-on : ubuntu-latest
28- environment :
29- name : pypi
30- url : https://pypi.org/project/moto-ext/
3122 permissions :
3223 contents : write
3324 id-token : write
@@ -50,35 +41,35 @@ jobs:
5041 git config --global user.name 'LocalStack Bot'
5142 git config --global user.email 'localstack-bot@users.noreply.github.com'
5243 git remote set-url origin https://git:${{ secrets.PRO_ACCESS_TOKEN }}@github.com/${{ github.repository }}
53-
44+
5445 # make sure to switch to the `localstack` branch (default / main branch of this fork)
5546 git switch localstack
5647 # add moto upstream as remote
5748 git remote add upstream https://github.com/getmoto/moto.git
5849 # rebase with latest changes
5950 git pull
60-
51+
6152 # Create a custom merge driver which prefers everything from upstream _BUT_ the name and the URL
6253 mkdir -p $HOME/.local/bin
6354 cat > $HOME/.local/bin/git-prefer-theirs-name-url << EOF
6455 #!/bin/bash
6556 set -e
66-
57+
6758 base="\$1"
6859 local="\$2"
6960 remote="\$3"
70-
61+
7162 echo "Executing custom merge driver for base \$base, local \$local, remote \$remote."
72-
63+
7364 # Define keys to keep
7465 KEYS=("name" "url")
75-
66+
7667 # Read files into arrays
7768 mapfile -t REMOTE_LINES < "\$remote"
7869 mapfile -t LOCAL_LINES < "\$local"
79-
70+
8071 echo "merging \$local + \$local + \$remote ..."
81-
72+
8273 # Function to check if a line should be kept (matches any key)
8374 keep_line() {
8475 local line="\$1"
8778 done
8879 return 1
8980 }
90-
81+
9182 # keep key-matched lines from local, others from remote
9283 for i in "\${!LOCAL_LINES[@]}"; do
9384 if keep_line "\${REMOTE_LINES[i]}"; then
@@ -96,22 +87,22 @@ jobs:
9687 echo "\${LOCAL_LINES[i]}"
9788 fi
9889 done > "\$local"
99-
90+
10091 exit 0
10192 EOF
102-
93+
10394 # make the script executable and add it to the PATH
10495 chmod +x $HOME/.local/bin/git-prefer-theirs-name-url
10596 echo "$HOME/.local/bin" >> "$GITHUB_PATH"
106-
97+
10798 # add the merge driver to the git config
10899 cat >> .git/config << EOF
109-
100+
110101 [merge "git-prefer-theirs-name-url"]
111102 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
112103 driver = git-prefer-theirs-name-url %O %A %B
113104 EOF
114-
105+
115106 # define to use the custom merge driver for the setup.cfg
116107 cat > .gitattributes << EOF
117108 setup.cfg merge=git-prefer-theirs-name-url
@@ -121,75 +112,12 @@ jobs:
121112 run : |
122113 git fetch upstream
123114 git rebase -f upstream/master
124-
125- - name : Determine new version
126- run : |
127- echo "Determining new version..."
128- cat > setuptools.cfg << EOF
129- [tool.setuptools_scm]
130- local_scheme = "no-local-version"
131- version_scheme = "post-release"
132- EOF
133- python3 -m venv .venv
134- source .venv/bin/activate
135- python3 -m pip install setuptools_scm
136- NEW_VERSION=$(python3 -m setuptools_scm -c setuptools.cfg)
137- NEW_VERSION="${NEW_VERSION//dev/post}"
138- echo "New version is: $NEW_VERSION"
139- echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
140-
141- - name : Build Python distributions
142- # FYI: Checks in this script only work because the -e flag is enabled by default in GitHub actions
143- run : |
144- python3 -m pip install build
145-
146- echo "Setting new version in setup.cfg":
147- # make sure setup.cfg is not dirty yet
148- git diff --exit-code setup.cfg
149- sed -i -E 's/^(version\s*=\s*)("?)[^"]+("?)/\1\2'"$NEW_VERSION"'\3/' setup.cfg
150- # make sure setup.cfg is dirty now
151- ! git diff --exit-code setup.cfg
152-
153- echo "Building new version and tagging commit..."
154- python3 -m build
155-
156- - name : Tag successful build
157- run : |
158- git tag -a $NEW_VERSION -m $NEW_VERSION
159-
160- - name : Clean up
161- run : |
162- git reset --hard
163- git clean -df
164-
165- - name : Store built distributions
166- uses : actions/upload-artifact@v4
167- with :
168- name : moto-ext-dists
169- path : dist/*.*
170-
171- # publish the package before pushing the tag (this might fail if the version already exists on PyPI)
172- - name : Publish package distributions to PyPI
173- if : ${{ github.event.inputs.dry_run != 'true' }}
174- uses : pypa/gh-action-pypi-publish@release/v1
115+ git log --oneline --graph --abbrev-commit --max-count 20
175116
176117 - name : Push
177118 if : ${{ github.event.inputs.dry_run != 'true' }}
178119 run : |
179120 git push --force-with-lease
180- git push --atomic origin localstack $NEW_VERSION
121+ git push --atomic origin localstack
181122 env :
182123 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
183-
184- # Add a retry to avoid issues where the GH CLI fails
185- # because it does not yet detect the pushed tag.
186- - name : Create Release
187- uses : nick-fields/retry@v3
188- if : ${{ github.event.inputs.dry_run != 'true' }}
189- env :
190- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
191- with :
192- max_attempts : 5
193- retry_wait_seconds : 120
194- timeout_minutes : 5
195- command : gh release create $NEW_VERSION --repo localstack/moto --notes "automatic rebase sync and release"
0 commit comments