Release moto-ext #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # LocalStack specific workflow to implement a fully-integrated continuous integration pipeline for Moto-Ext | |
| # - Guess next patch semantic version | |
| # - Build source and wheel distributions | |
| # - Publish the distributions to PyPi | |
| # - Tag the commit with the new version | |
| # - Create a GitHub release for the new version | |
| name: Release moto-ext | |
| on: | |
| schedule: | |
| - cron: 0 5 * * MON | |
| 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: | |
| build-release-moto-ext: | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/project/moto-ext/ | |
| 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: Determine new version | |
| run: | | |
| echo "Determining new version..." | |
| # Only bump PATCH semver because Moto-Ext is frozen against all MAJOR and MINOR changes | |
| cat > setuptools.cfg << EOF | |
| [tool.setuptools_scm] | |
| local_scheme = "no-local-version" | |
| version_scheme = "python-simplified-semver" | |
| EOF | |
| python3 -m venv .venv | |
| source .venv/bin/activate | |
| python3 -m pip install setuptools_scm | |
| NEW_VERSION=$(python3 -m setuptools_scm -c setuptools.cfg) | |
| NEW_VERSION="${NEW_VERSION//.dev[0-9]/}" | |
| echo "New version is: $NEW_VERSION" | |
| echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
| - name: Build Python distributions | |
| # FYI: Checks in this script only work because the -e flag is enabled by default in GitHub actions | |
| run: | | |
| python3 -m pip install build | |
| echo "Setting new version in setup.cfg": | |
| # make sure setup.cfg is not dirty yet | |
| git diff --exit-code setup.cfg | |
| sed -i -E 's/^(version\s*=\s*)("?)[^"]+("?)/\1\2'"$NEW_VERSION"'\3/' setup.cfg | |
| # make sure setup.cfg is dirty now | |
| ! git diff --exit-code setup.cfg | |
| echo "Building distributions" | |
| python3 -m build | |
| - name: Create and push tag | |
| if: ${{ github.event.inputs.dry_run != 'true' }} | |
| run: | | |
| git tag -a $NEW_VERSION -m $NEW_VERSION | |
| git push --tags origin localstack | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Clean up | |
| run: | | |
| git reset --hard | |
| git clean -df | |
| - name: Upload distributions | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: moto-ext-dists | |
| path: dist/*.* | |
| # publish the package before pushing the tag (this might fail if the version already exists on PyPI) | |
| - name: Publish package distributions to PyPI | |
| if: ${{ github.event.inputs.dry_run != 'true' }} | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| # Add a retry to avoid issues where the GH CLI fails because it does not yet detect the pushed tag. | |
| - name: Create Release | |
| uses: nick-fields/retry@v3 | |
| if: ${{ github.event.inputs.dry_run != 'true' }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| max_attempts: 5 | |
| retry_wait_seconds: 120 | |
| timeout_minutes: 5 | |
| command: gh release create $NEW_VERSION --repo localstack/moto --notes "automatic release" |