fixed publish workflow #9
Workflow file for this run
This file contains 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
name: Publish Python Package | |
on: | |
push: | |
tags: | |
- "v*.*.*" | |
jobs: | |
check-tag-from-main-branch: | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v4.1.1 | |
- name: Check if tag is on main branch | |
run: | | |
if [[ $(git branch -r --contains ${{ github.ref }}) =~ "main" ]]; then | |
echo "Tag is on main branch" | |
else | |
echo "Tag is not on main branch" | |
exit 1 | |
fi | |
check-version-already-exist: | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v4.1.1 | |
- name: Set up Python | |
uses: actions/setup-python@v5.1.0 | |
with: | |
python-version: 3.10.4 | |
- name: Install Poetry | |
uses: snok/install-poetry@v1.3.4 | |
with: | |
version: 1.5.0 | |
virtualenvs-create: false | |
- name: Check if version already exists | |
run: | | |
PACKAGE_VERSION=$(poetry version -s) | |
STATUS_CODE=$(curl -o /dev/null -s -w "%{http_code}\n" https://pypi.org/project/dddesign/$PACKAGE_VERSION/) | |
if [ "$STATUS_CODE" -eq 200 ]; then | |
echo "Version $PACKAGE_VERSION already exists" | |
exit 1 | |
else | |
echo "Version $PACKAGE_VERSION doesn't exists" | |
fi | |
linters: | |
runs-on: ubuntu-20.04 | |
steps: | |
- uses: actions/checkout@v4.1.1 | |
- uses: ./.github/actions/linters | |
tests: | |
runs-on: ubuntu-20.04 | |
strategy: | |
matrix: | |
python-version: [ "3.8", "3.9", "3.10" ] | |
pydantic-version: [ "1.10" ] | |
steps: | |
- uses: actions/checkout@v4.1.1 | |
- uses: ./.github/actions/tests | |
with: | |
python-version: ${{ matrix.python-version }} | |
pydantic-version: ${{ matrix.pydantic-version }} | |
build: | |
runs-on: ubuntu-20.04 | |
needs: | |
- check-tag-from-main-branch | |
- check-version-already-exist | |
- linters | |
- tests | |
steps: | |
- uses: actions/checkout@v4.1.1 | |
- name: Set up Python | |
uses: actions/setup-python@v5.1.0 | |
with: | |
python-version: 3.10.4 | |
- name: Install Poetry | |
uses: snok/install-poetry@v1.3.4 | |
with: | |
version: 1.5.0 | |
virtualenvs-create: false | |
- name: Build release distributions | |
run: poetry build | |
- name: Store the distribution packages | |
uses: actions/upload-artifact@v4.3.1 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
publish-package: | |
runs-on: ubuntu-20.04 | |
needs: | |
- build | |
environment: | |
name: pypi | |
url: https://pypi.org/p/dddesign | |
permissions: | |
id-token: write | |
steps: | |
- name: Download all the dists | |
uses: actions/download-artifact@v4.1.4 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
- name: Publish release distributions | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
github-release: | |
name: Sign the Python distribution with Sigstore and upload them to GitHub Release | |
needs: | |
- publish-package | |
runs-on: ubuntu-20.04 | |
permissions: | |
contents: write | |
id-token: write | |
steps: | |
- name: Download all the dists | |
uses: actions/download-artifact@v4.1.4 | |
with: | |
name: python-package-distributions | |
path: dist/ | |
- name: Sign the dists with Sigstore | |
uses: sigstore/gh-action-sigstore-python@v2.1.1 | |
with: | |
inputs: >- | |
./dist/*.tar.gz | |
./dist/*.whl | |
- name: Create GitHub Release | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: >- | |
gh release create | |
'${{ github.ref_name }}' | |
--repo '${{ github.repository }}' | |
--notes "" | |
- name: Upload artifact signatures to GitHub Release | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
run: >- | |
gh release upload | |
'${{ github.ref_name }}' dist/** | |
--repo '${{ github.repository }}' |