Skip to content

Commit da5ff9f

Browse files
Decouple sync and release actions
1 parent dfd2db0 commit da5ff9f

File tree

2 files changed

+141
-93
lines changed

2 files changed

+141
-93
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,24 @@
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

106
on:
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
2216
concurrency:
2317
group: ${{ github.workflow }}
2418

2519
jobs:
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 '[email protected]'
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"
@@ -87,7 +78,7 @@ jobs:
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"

.github/workflows/ci_release.yml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# LocalStack specific workflow to implement a fully-integrated continuous integration pipeline for Moto-Ext
2+
# - Guess next patch semantic version
3+
# - Build source and wheel distributions
4+
# - Publish the distributions to PyPi
5+
# - Tag the commit with the new version
6+
# - Create a GitHub release for the new version
7+
8+
name: Release moto-ext
9+
10+
on:
11+
schedule:
12+
- cron: 0 5 * * MON
13+
workflow_dispatch:
14+
inputs:
15+
dry_run:
16+
description: 'Dry run'
17+
default: true
18+
required: true
19+
type: boolean
20+
21+
# Limit concurrency to 1
22+
concurrency:
23+
group: ${{ github.workflow }}
24+
25+
jobs:
26+
build-release-moto-ext:
27+
runs-on: ubuntu-latest
28+
environment:
29+
name: pypi
30+
url: https://pypi.org/project/moto-ext/
31+
permissions:
32+
contents: write
33+
id-token: write
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
with:
38+
fetch-depth: 0
39+
ref: localstack
40+
persist-credentials: false
41+
42+
- name: Setup Python
43+
uses: actions/setup-python@v6
44+
with:
45+
python-version: '3.13'
46+
47+
- name: Guess new version
48+
run: |
49+
echo "Guessing new version..."
50+
# Only bump PATCH semver because Moto-Ext is frozen against all MAJOR and MINOR changes
51+
cat > setuptools.cfg << EOF
52+
[tool.setuptools_scm]
53+
local_scheme = "no-local-version"
54+
version_scheme = "python-simplified-semver"
55+
EOF
56+
python3 -m venv .venv
57+
source .venv/bin/activate
58+
python3 -m pip install setuptools_scm
59+
set -x # TODO Remove
60+
NEW_VERSION=$(python3 -m setuptools_scm -c setuptools.cfg)
61+
NEW_VERSION="${NEW_VERSION//.dev[0-9]/}"
62+
echo "New version is: $NEW_VERSION"
63+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
64+
65+
- name: Ensure guessed version does not exist
66+
run: |
67+
! git rev-parse $NEW_VERSION || { echo "A tag for $NEW_VERSION already exists" ; exit 1; }
68+
69+
- name: Build Python distributions
70+
# FYI: Checks in this script only work because the -e flag is enabled by default in GitHub actions
71+
run: |
72+
python3 -m pip install build
73+
74+
# make sure setup.cfg is not dirty yet
75+
git diff --exit-code setup.cfg
76+
77+
echo "Setting new version in setup.cfg":
78+
sed -i -E 's/^(version\s*=\s*)("?)[^"]+("?)/\1\2'"$NEW_VERSION"'\3/' setup.cfg
79+
80+
# make sure setup.cfg is dirty now
81+
! git diff --exit-code setup.cfg
82+
83+
echo "Building distributions"
84+
python3 -m build
85+
86+
- name: Create and push tag
87+
if: ${{ github.event.inputs.dry_run != 'true' }}
88+
run: |
89+
git tag -a $NEW_VERSION -m $NEW_VERSION
90+
git push --tags origin localstack
91+
env:
92+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
94+
- name: Clean up
95+
run: |
96+
git reset --hard
97+
git clean -df
98+
99+
- name: Upload distributions
100+
uses: actions/upload-artifact@v4
101+
with:
102+
name: moto-ext-dists
103+
path: dist/*.*
104+
105+
# publish the package before pushing the tag (this might fail if the version already exists on PyPI)
106+
- name: Publish package distributions to PyPI
107+
if: ${{ github.event.inputs.dry_run != 'true' }}
108+
uses: pypa/gh-action-pypi-publish@release/v1
109+
110+
# Add a retry to avoid issues where the GH CLI fails because it does not yet detect the pushed tag.
111+
- name: Create Release
112+
uses: nick-fields/retry@v3
113+
if: ${{ github.event.inputs.dry_run != 'true' }}
114+
env:
115+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
116+
with:
117+
max_attempts: 5
118+
retry_wait_seconds: 120
119+
timeout_minutes: 5
120+
command: gh release create $NEW_VERSION --repo localstack/moto --notes "automatic release"

0 commit comments

Comments
 (0)