Fixed low contamination issue in RANK #101
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
# 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, 'bump') && github.actor == 'KulikDM' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Increment version number | |
run: | | |
printf "Reading the current version from the file\n" | |
current_version=$(grep -oP "__version__ = '\K(\d+\.\d+\.\d+)" pythresh/version.py) | |
if [[ -z $current_version ]]; then | |
current_version="0.0.0" | |
printf "\nIssue fetching current version $current_version\n" | |
exit 1 | |
fi | |
printf "\nIncrementing the version number\n" | |
IFS='.' read -r -a version_parts <<< "$current_version" | |
patch=$(( ${version_parts[2]} + 1 )) | |
printf "\nHandling version part overflow\n" | |
if (( patch > 9 )); then | |
patch=0 | |
minor=$(( ${version_parts[1]} + 1 )) | |
if (( minor > 9 )); then | |
minor=0 | |
major=$(( ${version_parts[0]} + 1 )) | |
else | |
major=${version_parts[0]} | |
fi | |
else | |
minor=${version_parts[1]} | |
major=${version_parts[0]} | |
fi | |
new_version="${major}.${minor}.$patch" | |
printf "\nUpdating the file with the new version number\n" | |
sed -i "s/__version__ = '${current_version}'/__version__ = '${new_version}'/" pythresh/version.py | |
echo "new_version=$new_version" >> $GITHUB_ENV | |
echo "WORK_DIR=$(pwd)" >> $GITHUB_ENV | |
printf "\nNew version updated from $current_version to $new_version\n" | |
- name: Validate new PyPi version | |
run: | | |
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" | |
- name: Commit and push changes | |
env: | |
GIT_USER: ${{ secrets.GIT_USER }} | |
GIT_EMAIL: ${{ secrets.GIT_EMAIL }} | |
GIT_TOKEN: ${{ secrets.GIT_TOKEN }} | |
run: | | |
printf "Preparing to commit\n" | |
git config --global user.name $GIT_USER | |
git config --global user.email $GIT_EMAIL | |
git commit -a -m "Updated to version ${{ env.new_version }}" | |
printf "\nPushing the changes to the repository\n" | |
git push origin main | |
printf "\nNew version commited\n" | |
sleep 1m | |
- name: Publish to PyPI | |
env: | |
TWINE_USERNAME: __token__ | |
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} | |
run: | | |
printf "Preparing to install dependancies\n" | |
python -m pip install --upgrade pip setuptools wheel twine | |
python setup.py sdist | |
printf "\nPackage created locally\n" | |
twine upload dist/* | |
printf "\nNew PyPi release created\n" | |
sleep 10m | |
- name: Validate new Conda version | |
run: | | |
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"'"[0].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_EMAIL: ${{ secrets.GIT_EMAIL }} | |
GIT_TOKEN: ${{ secrets.GIT_TOKEN }} | |
run: | | |
printf "Preparing to clone feedstock repository\n" | |
git config --global user.name $GIT_USER | |
git config --global user.email $GIT_EMAIL | |
git clone https://$GIT_USER:[email protected]/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: | | |
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" |