From 98c01477d153a7f67027ec1971502438fa5577e8 Mon Sep 17 00:00:00 2001 From: PSala Date: Wed, 4 Oct 2023 15:40:16 +0200 Subject: [PATCH] Add CIs auto bump and push pypi --- .bumpversion.cfg | 2 + .github/workflows/release.yml | 42 ++++++++++++++++++ .github/workflows/version.yml | 80 +++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 .bumpversion.cfg create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/version.yml diff --git a/.bumpversion.cfg b/.bumpversion.cfg new file mode 100644 index 0000000..88b98e4 --- /dev/null +++ b/.bumpversion.cfg @@ -0,0 +1,2 @@ +[bumpversion] +current_version = 0.10.1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..03e9fe0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +name: Upload package to PYPI + +on: + push: + tags: + - 'v[0-9]+\.[0-9]+\.[0-9]+-rc[0-9]+' + - 'v[0-9]+\.[0-9]+\.[0-9]+' + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + +permissions: + contents: write + discussions: write + +jobs: + build: + runs-on: [self-hosted, Keroberos] + steps: + - uses: actions/checkout@v3 + + - name: Get tag + id: tag + uses: dawidd6/action-get-tag@v1 + with: + strip_v: false + + - name: Creating a realease/pre-release + id: create_release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{steps.tag.outputs.tag}} + draft: false + prerelease: ${{ contains(github.ref, '-rc') }} + generate_release_notes: true + + - name: Publish a Python distribution to PyPI + if: ${{ contains(github.ref, '-rc') }} == false + uses: conchylicultor/pypi-build-publish@v1 + with: + pypi-token: ${{ secrets.PYPI_MASTER_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..a94ea97 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,80 @@ +name: BUMP Version +on: + push: + # For copy pase proposes, change this variable + branches: [ master ] + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + +env: + # For copy pase proposes, change this variable + VERSION_FILE: setup.py + HOME: /home/ci_repos + SCRIPTS_PATH: /home/ci_repos/ci_scripts + USER: ci_repos + +permissions: + actions: write + checks: write + contents: write + deployments: write + issues: write + pull-requests: write + statuses: read + +jobs: + bump-version: + runs-on: [self-hosted, Keroberos] + if: ${{ !startsWith(github.event.head_commit.message, 'Bump to v') }} + steps: + - uses: actions/checkout@v4 + - name: Update python packages + run: | + . $SCRIPTS_PATH/load_pyenv.sh + pyenv activate bump + pip install --upgrade bump2version + pip install --upgrade giscemultitools + + - name: Get PR info + env: + GITHUB_TOKEN: ${{ secrets.RO_GH_ACTIONS_TOKEN }} + run: | + . $SCRIPTS_PATH/load_pyenv.sh + pyenv activate bump + echo 'PR_INFO<> $GITHUB_ENV + gisce_github get-commits-sha-from-merge-commit --owner ${{ github.repository_owner }} --repository ${{ github.event.repository.name }} --sha ${{ github.sha }} >> $GITHUB_ENV + echo 'EOF' >> $GITHUB_ENV + + - name: Bump Version + run: | + . $SCRIPTS_PATH/load_pyenv.sh + pyenv activate bump + pr_labels=$( echo '${{ env.PR_INFO }}' | jq -r '.pullRequest.labels' ) + is_minor=false + is_major=false + is_patch=false + for label in echo $( echo $pr_labels | jq -r '.[].name' ); do + if [[ $label == 'minor' ]]; then + is_minor=true + elif [[ $label == 'major' ]]; then + is_major=true + elif [[ $label == 'patch' ]]; then + is_patch=true + fi + done + VERSION_TYPE=false + if [[ $is_major == true ]]; then + VERSION_TYPE="major" + elif [[ $is_minor == true ]]; then + VERSION_TYPE="minor" + elif [[ $is_patch == true ]]; then + VERSION_TYPE="patch" + fi + if [[ $VERSION_TYPE != false ]]; then + git config user.name Release Bot + git config user.email github-actions@github.com + bump2version $VERSION_TYPE --tag --commit -m "Bump to v{new_version}" $VERSION_FILE + git push origin master --tags + fi