|
| 1 | +name: Build Release and Upload PyPi Package |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "master" ] |
| 6 | + |
| 7 | +#permissions: |
| 8 | +# contents: read |
| 9 | + |
| 10 | +jobs: |
| 11 | + build_and_publish: |
| 12 | + |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v3 |
| 17 | + - name: Set up Python |
| 18 | + uses: actions/setup-python@v3 |
| 19 | + with: |
| 20 | + python-version: '3.x' |
| 21 | + |
| 22 | + - name: Update Release Number |
| 23 | + run: | |
| 24 | + set -e |
| 25 | + |
| 26 | + # Retrieve the current release number |
| 27 | + current_release=$(cat VERSION) |
| 28 | + |
| 29 | + # If major version required uncomment below row |
| 30 | + # current_release='<major_version_number>' |
| 31 | +
|
| 32 | + # Increment the release number |
| 33 | + new_release=$(echo $current_release | awk -F. -v OFS=. '{$NF++;print}') |
| 34 | +
|
| 35 | + # Set the new release number as an environment variable |
| 36 | + echo "NEW_RELEASE=${new_release}" >> $GITHUB_ENV |
| 37 | + |
| 38 | + # Change version number on files |
| 39 | + sed -i -e 's/'$current_release'/'$new_release'/g' setup.py iyzipay/iyzipay_resource.py VERSION pyproject.toml |
| 40 | +
|
| 41 | + - name: Github Tasks |
| 42 | + run: | |
| 43 | + set -e |
| 44 | + git config user.name "iyzico-ci" |
| 45 | + git config user.email [email protected] |
| 46 | + git add . |
| 47 | + git commit -m "Automatic commit by iyzico-ci v${{env.NEW_RELEASE}}" |
| 48 | + git push origin master |
| 49 | + git tag -a v${{env.NEW_RELEASE}} -m "Automatic tag by iyzico-ci v${{env.NEW_RELEASE}}" |
| 50 | + git push origin v${{env.NEW_RELEASE}} |
| 51 | + |
| 52 | + - name: Github Release |
| 53 | + run: | |
| 54 | + # Use the new release version in release creation step |
| 55 | + echo "Creating release ${{env.NEW_RELEASE}}..." |
| 56 | + result=$( curl -# -XPOST -H "Authorization: token ${{secrets.TOKEN_GITHUB}}" -H "Content-Type: application/json" -H "Accept:application/json" --data-binary '{"tag_name": "v${{env.NEW_RELEASE}}","target_commitish": "master","name": "iyzipay-python ${{env.NEW_RELEASE}}","body": "version ${{env.NEW_RELEASE}}","draft": false,"prerelease": false}' https://api.github.com/repos/iyzico/iyzipay-python/releases ) |
| 57 | + echo $result |
| 58 | + echo "GitHub release ${{env.NEW_RELEASE}} created!" |
| 59 | + |
| 60 | + - name: Install dependencies |
| 61 | + run: | |
| 62 | + python -m pip install --upgrade pip |
| 63 | + pip install build |
| 64 | + - name: Build package |
| 65 | + run: python -m build |
| 66 | + - name: Publish package |
| 67 | + uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 |
| 68 | + with: |
| 69 | + user: __token__ |
| 70 | + password: ${{ secrets.TOKEN_PYPI }} |
0 commit comments