release: patch license issue #145
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
| # This workflow will increment the release version number | |
| # Validates new version | |
| # Publishes to PyPi | |
| # Validates new release | |
| # Publishes to Conda | |
| # Creates new GitHub release | |
| name: Publish Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| release: | |
| if: contains(github.event.head_commit.message, 'release') && github.actor == 'KulikDM' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.GIT_TOKEN }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v6 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies | |
| run: | | |
| set -euo pipefail | |
| pip install --upgrade pip setuptools wheel | |
| pip install bump-my-version build twine | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name "${{ secrets.GIT_USER }}" | |
| git config --global user.email "${{ secrets.GIT_EMAIL }}" | |
| - name: Bump version | |
| run: | | |
| set -euo pipefail | |
| COMMIT_MSG="${{ github.event.head_commit.message }}" | |
| echo "Commit message: $COMMIT_MSG" | |
| if [[ "$COMMIT_MSG" =~ patch ]]; then | |
| BUMP_TYPE="patch" | |
| elif [[ "$COMMIT_MSG" =~ minor ]]; then | |
| BUMP_TYPE="minor" | |
| elif [[ "$COMMIT_MSG" =~ major ]]; then | |
| BUMP_TYPE="major" | |
| else | |
| echo "No bump type found, defaulting to patch." | |
| BUMP_TYPE="patch" | |
| fi | |
| echo "Bumping version type: $BUMP_TYPE" | |
| bump-my-version bump "$BUMP_TYPE" \ | |
| --no-tag \ | |
| --commit \ | |
| --message "Bump version: {current_version} → {new_version} [skip ci]" | |
| - name: Push version bump | |
| run: | | |
| set -euo pipefail | |
| git push --follow-tags | |
| new_version=$(PYTHONPATH=. python -c "import pythresh; print(pythresh.__version__)") | |
| echo "new_version=$new_version" >> $GITHUB_ENV | |
| echo "WORK_DIR=$(pwd)" >> $GITHUB_ENV | |
| - name: Validate new PyPi version | |
| run: | | |
| set -euo pipefail | |
| printf "Getting lastest pypi information\n" | |
| url="https://pypi.org/pypi/pythresh/json" | |
| current_pypi_version=$(curl -s "$url" | jq -r '.info.version') | |
| printf "\nValidating version update\n" | |
| if [ "$current_pypi_version" == "${{ env.new_version }}" ]; then | |
| printf "\nCurrent PyPi version $current_pypi_version matches ${{ env.new_version }}\n" | |
| exit 1 | |
| fi | |
| printf "\nNew version validated\n" | |
| sleep 1m | |
| - name: Publish to PyPI | |
| env: | |
| TWINE_USERNAME: __token__ | |
| TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| printf "Preparing to install dependancies\n" | |
| python -m build | |
| printf "\nPackage created locally\n" | |
| twine check --strict dist/* | |
| printf "\nChecks passed\n" | |
| twine upload --verbose dist/* | |
| printf "\nNew PyPi release created\n" | |
| sleep 10m | |
| - name: Validate new Conda version | |
| run: | | |
| set -euo pipefail | |
| printf "Getting lastest pypi information\n" | |
| url="https://pypi.org/pypi/pythresh/json" | |
| latest_version=$(curl -s "$url" | jq -r '.info.version') | |
| latest_sha256=$(curl -s "$url" | jq -r '.releases."'"$latest_version"'"[] | select(.packagetype == "sdist") | .digests.sha256') | |
| echo "Validating version update" | |
| if [ "$latest_version" != "${{ env.new_version }}" ]; then | |
| printf "\nNew Conda version $latest_version does not match new PyPi version ${{ env.new_version }}\n" | |
| exit 1 | |
| fi | |
| echo "latest_version=$latest_version" >> $GITHUB_ENV | |
| echo "latest_sha256=$latest_sha256" >> $GITHUB_ENV | |
| printf "\nNew PyPi version validated\n" | |
| - name: Update Conda feedstock repository | |
| env: | |
| GIT_USER: ${{ secrets.GIT_USER }} | |
| GIT_TOKEN: ${{ secrets.GIT_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| printf "Preparing to clone feedstock repository\n" | |
| git clone https://$GIT_USER:$GIT_TOKEN@github.com/conda-forge/pythresh-feedstock.git | |
| cd pythresh-feedstock | |
| printf "\nReading the original meta.yaml file\n" | |
| meta_yaml=$(cat recipe/meta.yaml) | |
| printf "\nUpdating the version and sha256\n" | |
| updated_meta_yaml=$(echo "{% set name = \"pythresh\" %}" && echo "{% set version = \"${{ env.latest_version }}\" %}" && tail -n +3 recipe/meta.yaml | sed -E "s/sha256: .*$/sha256: ${{ env.latest_sha256 }}/") | |
| printf "\nWriting the updated meta.yaml file\n" | |
| echo "$updated_meta_yaml" > recipe/meta.yaml | |
| printf "\nCommitting the changes\n" | |
| git add recipe/meta.yaml | |
| git commit -m "Update to version ${{ env.latest_version }}" | |
| printf "\nPushing the changes to the repository" | |
| git push origin main | |
| printf "\nNew Conda release created\n" | |
| - name: Create GitHub release | |
| env: | |
| GIT_TOKEN: ${{ secrets.GIT_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| printf "Preparing to create new GitHub release\n" | |
| cd "${{ env.WORK_DIR }}" | |
| TAG_NAME="v${{ env.latest_version }}" | |
| RELEASE_TITLE=$TAG_NAME | |
| printf "\nCreating release notes\n" | |
| RELEASE_NOTES="## What's Changed"$'\n' | |
| while IFS= read -r line; do | |
| RELEASE_NOTES+="* $line"$'\n' | |
| done < <(grep -A 1 "v<${{ env.latest_version }}>," CHANGES.txt | grep -o -- "-- .*" | sed -e "s/^-- //") | |
| RELEASE_NOTES=$(echo "$RELEASE_NOTES" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g') | |
| printf "\nPosting new release\n" | |
| JSON_DATA="{ \"tag_name\": \"$TAG_NAME\", \"name\": \"$RELEASE_TITLE\", \"body\": \"$RELEASE_NOTES\", \"draft\": false, \"prerelease\": false }" | |
| curl -X POST "https://api.github.com/repos/KulikDM/pythresh/releases" \ | |
| -H "Content-Type: application/json" \ | |
| -H "Authorization: Bearer $GIT_TOKEN" \ | |
| -d "$JSON_DATA" | |
| printf "\nNew release posted succesfully\n" |