From 03d3444e1d0c60a02e361eac8e67a23885a512cf Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 15:12:42 +0100 Subject: [PATCH 01/12] test --- .github/workflows/publish.yaml | 185 +++++++++++++++++++++------------ 1 file changed, 121 insertions(+), 64 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 4932ed4..fa6e42c 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -6,81 +6,138 @@ name: Upload Python Package on: + push: + release: - types: [created] + types: published jobs: - deploy: + check-version: + name: check version runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set env - run: | - echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" | tee -a $GITHUB_ENV - echo "BRANCH=$( \ - git branch -r --contains ${GITHUB_REF} \ - | grep -v HEAD \ - | sed -n 's/ *origin\/\(.*\)/\1/p' \ - )" | tee -a $GITHUB_ENV - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.x' - cache: pip - - name: Install dependencies - run: | - pip install build twine - - name: get infos from Tag - run: | - echo "RELEASE_TAG=${RELEASE_TAG}" - if [[ $RELEASE_TAG =~ (([0-9]+)\.([0-9]+)\.([0-9]+))([-./]dev([0-9]+))?$ ]] - then - echo "VERSION=${BASH_REMATCH[0]}" | tee -a $GITHUB_ENV - echo "VERSION_MAJOR=${BASH_REMATCH[2]}" | tee -a $GITHUB_ENV - echo "VERSION_MINOR=${BASH_REMATCH[3]}" | tee -a $GITHUB_ENV - echo "VERSION_PATCH=${BASH_REMATCH[4]}" | tee -a $GITHUB_ENV - echo "VERSION_DEV=${BASH_REMATCH[6]}" | tee -a $GITHUB_ENV - else - echo "INVALID_TAG=True" | tee -a $GITHUB_ENV - fi - - name: Fail on invalid Tag - if: ${{ env.INVALID_TAG }} - uses: actions/github-script@v6 - with: - script: core.setFailed('Invalid Tag name used with this release!') - - - name: Write Version to pyproject.toml - run: | - sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml - - name: Build sdist and bdist_wheel - run: | - python -m build - - name: publish to PyPi + + - name: get versions + id: get env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + RELEASE_TAG: ${{ github.ref_name }} run: | - twine upload dist/* + # echo "NEW_VERSION=${RELEASE_TAG#v*}" | tee -a $GITHUB_OUTPUT + echo "NEW_VERSION=4.2.1" | tee -a $GITHUB_OUTPUT + OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version) + echo "OLD_VERSION=${OLD_VERSION}" | tee -a $GITHUB_OUTPUT - - name: increment development version - if: ${{ env.VERSION_DEV }} - run: | - v=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH-dev$((VERSION_DEV+1)) - sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml - - name: increment patch version - if: ${{ !env.VERSION_DEV }} + - name: validate version + shell: python run: | - v=$VERSION_MAJOR.$VERSION_MINOR.$((VERSION_PATCH+1))-dev0 - sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml - - name: commit new version-number - uses: stefanzweifel/git-auto-commit-action@v4 - with: - branch: ${{ env.BRANCH }} - create_branch: true - commit_message: "increment version after release" + from sys import exit + from packaging import version + + new_version = version.parse("${{ steps.get.outputs.NEW_VERSION }}") + old_version = version.parse("${{ steps.get.outputs.OLD_VERSION }}") + + if not new_version > old_version: + print(f"::error::New version '{new_version}' not greatet than '{old_version}'") + exit(1) + + outputs: + version: ${{ steps.get.outputs.NEW_VERSION }} + + + commit: + name: write version and tag + runs-on: ubuntu-latest + needs: check-version + permissions: + contents: write + + env: + VERSION: ${{ needs.check-version.outputs.version }} + steps: + - name: update pyproject.toml + run: sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml + - name: commit version + run: git commit --all -m "release v$Version" + - name: update tag + run: git tag -f "v$VERSION" + - name: push updates + run: git push --tags -f + + + # deploy: + # runs-on: ubuntu-latest + + # steps: + # - name: Checkout + # uses: actions/checkout@v3 + # with: + # fetch-depth: 0 + # - name: Set env + # run: | + # echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" | tee -a $GITHUB_ENV + # echo "BRANCH=$( \ + # git branch -r --contains ${GITHUB_REF} \ + # | grep -v HEAD \ + # | sed -n 's/ *origin\/\(.*\)/\1/p' \ + # )" | tee -a $GITHUB_ENV + # - name: Set up Python + # uses: actions/setup-python@v4 + # with: + # python-version: '3.x' + # cache: pip + # - name: Install dependencies + # run: | + # pip install build twine + # - name: get infos from Tag + # run: | + # echo "RELEASE_TAG=${RELEASE_TAG}" + # if [[ $RELEASE_TAG =~ (([0-9]+)\.([0-9]+)\.([0-9]+))([-./]dev([0-9]+))?$ ]] + # then + # echo "VERSION=${BASH_REMATCH[0]}" | tee -a $GITHUB_ENV + # echo "VERSION_MAJOR=${BASH_REMATCH[2]}" | tee -a $GITHUB_ENV + # echo "VERSION_MINOR=${BASH_REMATCH[3]}" | tee -a $GITHUB_ENV + # echo "VERSION_PATCH=${BASH_REMATCH[4]}" | tee -a $GITHUB_ENV + # echo "VERSION_DEV=${BASH_REMATCH[6]}" | tee -a $GITHUB_ENV + # else + # echo "INVALID_TAG=True" | tee -a $GITHUB_ENV + # fi + # - name: Fail on invalid Tag + # if: ${{ env.INVALID_TAG }} + # uses: actions/github-script@v6 + # with: + # script: core.setFailed('Invalid Tag name used with this release!') + + # - name: Write Version to pyproject.toml + # run: | + # sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml + # - name: Build sdist and bdist_wheel + # run: | + # python -m build + # - name: publish to PyPi + # env: + # TWINE_USERNAME: __token__ + # TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + # run: | + # twine upload dist/* + + # - name: increment development version + # if: ${{ env.VERSION_DEV }} + # run: | + # v=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH-dev$((VERSION_DEV+1)) + # sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml + # - name: increment patch version + # if: ${{ !env.VERSION_DEV }} + # run: | + # v=$VERSION_MAJOR.$VERSION_MINOR.$((VERSION_PATCH+1))-dev0 + # sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml + # - name: commit new version-number + # uses: stefanzweifel/git-auto-commit-action@v4 + # with: + # branch: ${{ env.BRANCH }} + # create_branch: true + # commit_message: "increment version after release" From 5c7b4a83f0b1e5293b0c06b55b4079bdacac1582 Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 15:20:42 +0100 Subject: [PATCH 02/12] dev version --- .github/workflows/publish.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index fa6e42c..b6c66ce 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -28,7 +28,7 @@ jobs: RELEASE_TAG: ${{ github.ref_name }} run: | # echo "NEW_VERSION=${RELEASE_TAG#v*}" | tee -a $GITHUB_OUTPUT - echo "NEW_VERSION=4.2.1" | tee -a $GITHUB_OUTPUT + echo "NEW_VERSION=4.2.0-dev1" | tee -a $GITHUB_OUTPUT OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version) echo "OLD_VERSION=${OLD_VERSION}" | tee -a $GITHUB_OUTPUT @@ -55,10 +55,11 @@ jobs: needs: check-version permissions: contents: write - env: VERSION: ${{ needs.check-version.outputs.version }} steps: + - name: Checkout + uses: actions/checkout@v3 - name: update pyproject.toml run: sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml - name: commit version From 8849a31be2c7436b2064ea12510ed750a1e82837 Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 15:22:43 +0100 Subject: [PATCH 03/12] older version --- .github/workflows/publish.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index b6c66ce..c971141 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -28,7 +28,7 @@ jobs: RELEASE_TAG: ${{ github.ref_name }} run: | # echo "NEW_VERSION=${RELEASE_TAG#v*}" | tee -a $GITHUB_OUTPUT - echo "NEW_VERSION=4.2.0-dev1" | tee -a $GITHUB_OUTPUT + echo "NEW_VERSION=4.1.0" | tee -a $GITHUB_OUTPUT OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version) echo "OLD_VERSION=${OLD_VERSION}" | tee -a $GITHUB_OUTPUT From ea2bdfd76c6531903c368358020261dc91938aa9 Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 15:24:14 +0100 Subject: [PATCH 04/12] newer --- .github/workflows/publish.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index c971141..5146f3e 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -28,7 +28,7 @@ jobs: RELEASE_TAG: ${{ github.ref_name }} run: | # echo "NEW_VERSION=${RELEASE_TAG#v*}" | tee -a $GITHUB_OUTPUT - echo "NEW_VERSION=4.1.0" | tee -a $GITHUB_OUTPUT + echo "NEW_VERSION=4.2.1" | tee -a $GITHUB_OUTPUT OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version) echo "OLD_VERSION=${OLD_VERSION}" | tee -a $GITHUB_OUTPUT @@ -63,7 +63,10 @@ jobs: - name: update pyproject.toml run: sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml - name: commit version - run: git commit --all -m "release v$Version" + env: + USER: github-actions[bot] + EMAIL: github-actions[bot]@users.noreply.github.com + run: git -c user.name="$USER" -c user.email="$EMAIL" commit --all -m "release v$Version" - name: update tag run: git tag -f "v$VERSION" - name: push updates From 14bc7618ea68f274a5b8988197eaa77a31ade047 Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 16:15:56 +0100 Subject: [PATCH 05/12] test --- .github/workflows/publish.yaml | 159 ++++++++++++++++----------------- 1 file changed, 78 insertions(+), 81 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 5146f3e..6d3fa39 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -14,13 +14,11 @@ on: jobs: - check-version: - name: check version + check-version: # --------------------------------------------------------------------- runs-on: ubuntu-latest - steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: get versions id: get @@ -49,8 +47,7 @@ jobs: version: ${{ steps.get.outputs.NEW_VERSION }} - commit: - name: write version and tag + tag: # ------------------------------------------------------------------------------- runs-on: ubuntu-latest needs: check-version permissions: @@ -59,89 +56,89 @@ jobs: VERSION: ${{ needs.check-version.outputs.version }} steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 + - name: update pyproject.toml - run: sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml + run: sed -i -r 's/^(version = ).*$/\1"$VERSION"/' pyproject.toml + - name: commit version env: USER: github-actions[bot] EMAIL: github-actions[bot]@users.noreply.github.com - run: git -c user.name="$USER" -c user.email="$EMAIL" commit --all -m "release v$Version" + run: git -c user.name="$USER" -c user.email="$EMAIL" commit --all -m "release v$VERSION" + - name: update tag run: git tag -f "v$VERSION" + - name: push updates run: git push --tags -f + outputs: + ref: v${{ env.VERSION }} + - # deploy: - # runs-on: ubuntu-latest - - # steps: - # - name: Checkout - # uses: actions/checkout@v3 - # with: - # fetch-depth: 0 - # - name: Set env - # run: | - # echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" | tee -a $GITHUB_ENV - # echo "BRANCH=$( \ - # git branch -r --contains ${GITHUB_REF} \ - # | grep -v HEAD \ - # | sed -n 's/ *origin\/\(.*\)/\1/p' \ - # )" | tee -a $GITHUB_ENV - # - name: Set up Python - # uses: actions/setup-python@v4 - # with: - # python-version: '3.x' - # cache: pip - # - name: Install dependencies - # run: | - # pip install build twine - # - name: get infos from Tag - # run: | - # echo "RELEASE_TAG=${RELEASE_TAG}" - # if [[ $RELEASE_TAG =~ (([0-9]+)\.([0-9]+)\.([0-9]+))([-./]dev([0-9]+))?$ ]] - # then - # echo "VERSION=${BASH_REMATCH[0]}" | tee -a $GITHUB_ENV - # echo "VERSION_MAJOR=${BASH_REMATCH[2]}" | tee -a $GITHUB_ENV - # echo "VERSION_MINOR=${BASH_REMATCH[3]}" | tee -a $GITHUB_ENV - # echo "VERSION_PATCH=${BASH_REMATCH[4]}" | tee -a $GITHUB_ENV - # echo "VERSION_DEV=${BASH_REMATCH[6]}" | tee -a $GITHUB_ENV - # else - # echo "INVALID_TAG=True" | tee -a $GITHUB_ENV - # fi - # - name: Fail on invalid Tag - # if: ${{ env.INVALID_TAG }} - # uses: actions/github-script@v6 - # with: - # script: core.setFailed('Invalid Tag name used with this release!') - - # - name: Write Version to pyproject.toml - # run: | - # sed -i "s/version = \".*\"$/version = \"$VERSION\"/" pyproject.toml - # - name: Build sdist and bdist_wheel - # run: | - # python -m build - # - name: publish to PyPi - # env: - # TWINE_USERNAME: __token__ - # TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} - # run: | - # twine upload dist/* - - # - name: increment development version - # if: ${{ env.VERSION_DEV }} - # run: | - # v=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH-dev$((VERSION_DEV+1)) - # sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml - # - name: increment patch version - # if: ${{ !env.VERSION_DEV }} - # run: | - # v=$VERSION_MAJOR.$VERSION_MINOR.$((VERSION_PATCH+1))-dev0 - # sed -i "s/version = \".*\"$/version = \"$v\"/" pyproject.toml - # - name: commit new version-number - # uses: stefanzweifel/git-auto-commit-action@v4 - # with: - # branch: ${{ env.BRANCH }} - # create_branch: true - # commit_message: "increment version after release" + deploy: # --------------------------------------------------------------------------- + runs-on: ubuntu-latest + needs: tag + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.x' + cache: pip + + - name: Install dependencies + run: pip install build twine + + - name: Build sdist and bdist_wheel + run: python -m build + + # - name: publish to PyPi + # env: + # TWINE_USERNAME: __token__ + # TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} + # run: twine upload dist/* + + + increment: # ------------------------------------------------------------------------- + runs-on: ubuntu-latest + needs: deploy + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: get versions + id: get + shell: pyhton + run: | + from sys import exit + from os import environ + from packaging import version + ver = version.parse("${{ github.ref_name }}") + if ver.dev is not None: + new_ver = f"{ver.base_version}-dev{ver.dev +1}" + else: + new_ver = ".".join([ver.major, ver.minor, ver.micro +1]) + "-dev0" + with open(environ.get("GITHUB_OUTPUT"), "a") as fp: + towrite = f"NEW_VERSION={new_ver}" + print(towrite) + fp.write(towrite + "\n") + + - name: update pyproject.toml + env: + VERSION: ${{ steps.get.outputs.NEW_VERSION }} + run: sed -i -r 's/^(version = ).*$/\1"$VERSION"/' pyproject.toml + + - name: commit version + env: + USER: github-actions[bot] + EMAIL: github-actions[bot]@users.noreply.github.com + run: git -c user.name="$USER" -c user.email="$EMAIL" commit --all -m "increment version after release" + + - name: push updates + run: git push From 14908533cee419cbe92304a0dfd1cc5b330ae39b Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 16:40:03 +0100 Subject: [PATCH 06/12] more tests --- .github/workflows/publish.yaml | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 6d3fa39..ccdda51 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -22,13 +22,7 @@ jobs: - name: get versions id: get - env: - RELEASE_TAG: ${{ github.ref_name }} - run: | - # echo "NEW_VERSION=${RELEASE_TAG#v*}" | tee -a $GITHUB_OUTPUT - echo "NEW_VERSION=4.2.1" | tee -a $GITHUB_OUTPUT - OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version) - echo "OLD_VERSION=${OLD_VERSION}" | tee -a $GITHUB_OUTPUT + run: echo "OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version)" | tee -a $GITHUB_OUTPUT - name: validate version shell: python @@ -36,7 +30,7 @@ jobs: from sys import exit from packaging import version - new_version = version.parse("${{ steps.get.outputs.NEW_VERSION }}") + new_version = version.parse("${{ github.ref_name }}") old_version = version.parse("${{ steps.get.outputs.OLD_VERSION }}") if not new_version > old_version: @@ -73,9 +67,6 @@ jobs: - name: push updates run: git push --tags -f - outputs: - ref: v${{ env.VERSION }} - deploy: # --------------------------------------------------------------------------- runs-on: ubuntu-latest @@ -96,6 +87,11 @@ jobs: - name: Build sdist and bdist_wheel run: python -m build + - uses: actions/upload-artifact@v3 + with: + name: dist + path: dist/ + # - name: publish to PyPi # env: # TWINE_USERNAME: __token__ @@ -106,15 +102,22 @@ jobs: increment: # ------------------------------------------------------------------------- runs-on: ubuntu-latest needs: deploy - permissions: - contents: write steps: - name: Checkout uses: actions/checkout@v4 + with: + ref: ${{ needs.tag.outputs.ref }} + fetch-depth: 3 + + - name: get branch + run: | + git fetch + git branch tmp --track $(git log --pretty='%D' | grep -o -m1 "fork/[^']*") + git checkout tmp - name: get versions id: get - shell: pyhton + shell: python run: | from sys import exit from os import environ From 8f0a305265a90002f1b50cc866501e639e81ceb4 Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 16:49:00 +0100 Subject: [PATCH 07/12] tmp --- .github/workflows/publish.yaml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index ccdda51..c3b0bea 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -22,15 +22,19 @@ jobs: - name: get versions id: get - run: echo "OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version)" | tee -a $GITHUB_OUTPUT + run: | + echo "NEW_VERSION=$(echo '${{ github.ref_name }}' | cut -2-)" | tee -a $GITHUB_OUTPUT + echo "OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version)" | tee -a $GITHUB_OUTPUT - name: validate version + id: valid shell: python run: | from sys import exit from packaging import version - new_version = version.parse("${{ github.ref_name }}") + # new_version = version.parse("${{ steps.get.outputs.NEW_VERSION }}") + new_version = version.parse("4.2.1") # TODO: remove old_version = version.parse("${{ steps.get.outputs.OLD_VERSION }}") if not new_version > old_version: From dc1357edfa4f63c40c7a5019f21527867839b531 Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 18:01:00 +0100 Subject: [PATCH 08/12] more tests --- .github/workflows/publish.yaml | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index c3b0bea..e2a18c0 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -22,8 +22,9 @@ jobs: - name: get versions id: get + # echo "NEW_VERSION=$(echo '${{ github.ref_name }}' | cut -c2-)" | tee -a $GITHUB_OUTPUT run: | - echo "NEW_VERSION=$(echo '${{ github.ref_name }}' | cut -2-)" | tee -a $GITHUB_OUTPUT + echo "NEW_VERSION=$(echo 'v4.2.1' | cut -c2-)" | tee -a $GITHUB_OUTPUT echo "OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version)" | tee -a $GITHUB_OUTPUT - name: validate version @@ -33,8 +34,7 @@ jobs: from sys import exit from packaging import version - # new_version = version.parse("${{ steps.get.outputs.NEW_VERSION }}") - new_version = version.parse("4.2.1") # TODO: remove + new_version = version.parse("${{ steps.get.outputs.NEW_VERSION }}") old_version = version.parse("${{ steps.get.outputs.OLD_VERSION }}") if not new_version > old_version: @@ -110,15 +110,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - ref: ${{ needs.tag.outputs.ref }} fetch-depth: 3 - - name: get branch - run: | - git fetch - git branch tmp --track $(git log --pretty='%D' | grep -o -m1 "fork/[^']*") - git checkout tmp - - name: get versions id: get shell: python @@ -126,11 +119,12 @@ jobs: from sys import exit from os import environ from packaging import version - ver = version.parse("${{ github.ref_name }}") + # ver = version.parse("${{ github.ref_name }}") + ver = version.parse("4.2.1") if ver.dev is not None: new_ver = f"{ver.base_version}-dev{ver.dev +1}" else: - new_ver = ".".join([ver.major, ver.minor, ver.micro +1]) + "-dev0" + new_ver = f"{ver.major}.{ver.minor}.{ver.micro +1}-dev0" with open(environ.get("GITHUB_OUTPUT"), "a") as fp: towrite = f"NEW_VERSION={new_ver}" print(towrite) @@ -148,4 +142,4 @@ jobs: run: git -c user.name="$USER" -c user.email="$EMAIL" commit --all -m "increment version after release" - name: push updates - run: git push + run: git push origin "HEAD:$(git log --pretty='%D' | grep -oPm1 '(?<=origin/).*')" From e40d9196567fb78daf2abf6d016d9a9d8ab91b8a Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 18:32:21 +0100 Subject: [PATCH 09/12] test release --- .github/workflows/publish.yaml | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index e2a18c0..f429ab5 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -6,8 +6,6 @@ name: Upload Python Package on: - push: - release: types: published @@ -22,9 +20,8 @@ jobs: - name: get versions id: get - # echo "NEW_VERSION=$(echo '${{ github.ref_name }}' | cut -c2-)" | tee -a $GITHUB_OUTPUT run: | - echo "NEW_VERSION=$(echo 'v4.2.1' | cut -c2-)" | tee -a $GITHUB_OUTPUT + echo "NEW_VERSION=$(echo '${{ github.ref_name }}' | cut -c2-)" | tee -a $GITHUB_OUTPUT echo "OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version)" | tee -a $GITHUB_OUTPUT - name: validate version @@ -33,10 +30,8 @@ jobs: run: | from sys import exit from packaging import version - new_version = version.parse("${{ steps.get.outputs.NEW_VERSION }}") old_version = version.parse("${{ steps.get.outputs.OLD_VERSION }}") - if not new_version > old_version: print(f"::error::New version '{new_version}' not greatet than '{old_version}'") exit(1) @@ -57,7 +52,7 @@ jobs: uses: actions/checkout@v4 - name: update pyproject.toml - run: sed -i -r 's/^(version = ).*$/\1"$VERSION"/' pyproject.toml + run: sed -i -r "s/^(version = ).*$/\1\"$VERSION\"/" pyproject.toml - name: commit version env: @@ -80,7 +75,7 @@ jobs: uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.x' cache: pip @@ -119,8 +114,7 @@ jobs: from sys import exit from os import environ from packaging import version - # ver = version.parse("${{ github.ref_name }}") - ver = version.parse("4.2.1") + ver = version.parse("${{ github.ref_name }}") if ver.dev is not None: new_ver = f"{ver.base_version}-dev{ver.dev +1}" else: @@ -133,7 +127,7 @@ jobs: - name: update pyproject.toml env: VERSION: ${{ steps.get.outputs.NEW_VERSION }} - run: sed -i -r 's/^(version = ).*$/\1"$VERSION"/' pyproject.toml + run: sed -i -r "s/^(version = ).*$/\1\"$VERSION\"/" pyproject.toml - name: commit version env: From 8ee35e881f5cf9fb30304cb1c0cded1b67ea79b4 Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 18:39:59 +0100 Subject: [PATCH 10/12] add fetching --- .github/workflows/publish.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index f429ab5..50d47f4 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -136,4 +136,6 @@ jobs: run: git -c user.name="$USER" -c user.email="$EMAIL" commit --all -m "increment version after release" - name: push updates - run: git push origin "HEAD:$(git log --pretty='%D' | grep -oPm1 '(?<=origin/).*')" + run: | + git fetch origin 'refs/heads/*:refs/remotes/origin/*' + git push origin "HEAD:$(git log --pretty='%D' | grep -oPm1 '(?<=origin/).*')" From 98cd1a48e0cbed71e6781ab3dbef68993c00002d Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 18:45:53 +0100 Subject: [PATCH 11/12] proper checkout --- .github/workflows/publish.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 50d47f4..a9a66a6 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -73,6 +73,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} - name: Set up Python uses: actions/setup-python@v5 @@ -105,6 +107,7 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: + ref: ${{ github.ref }} fetch-depth: 3 - name: get versions From 9163b9871f9a756f9a2005e2710205a1f12b4436 Mon Sep 17 00:00:00 2001 From: Jan Wille Date: Mon, 4 Nov 2024 19:13:14 +0100 Subject: [PATCH 12/12] fix linter --- .github/workflows/publish.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index a9a66a6..8b9db52 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -12,7 +12,7 @@ on: jobs: - check-version: # --------------------------------------------------------------------- + check-version: # -------------------------------------------------------------------- runs-on: ubuntu-latest steps: - name: Checkout @@ -22,7 +22,7 @@ jobs: id: get run: | echo "NEW_VERSION=$(echo '${{ github.ref_name }}' | cut -c2-)" | tee -a $GITHUB_OUTPUT - echo "OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json | jq -r .info.version)" | tee -a $GITHUB_OUTPUT + echo "OLD_VERSION=$(curl -s https://pypi.org/pypi/readchar/json |jq -r .info.version)" | tee -a $GITHUB_OUTPUT - name: validate version id: valid @@ -40,7 +40,7 @@ jobs: version: ${{ steps.get.outputs.NEW_VERSION }} - tag: # ------------------------------------------------------------------------------- + tag: # ------------------------------------------------------------------------------ runs-on: ubuntu-latest needs: check-version permissions: @@ -100,7 +100,7 @@ jobs: # run: twine upload dist/* - increment: # ------------------------------------------------------------------------- + increment: # ------------------------------------------------------------------------ runs-on: ubuntu-latest needs: deploy steps: