|
| 1 | +name: Post Draft Release Published |
| 2 | + |
| 3 | +on: |
| 4 | + # Once draft release is released, trigger the docs release |
| 5 | + release: |
| 6 | + types: |
| 7 | + ## pre-release and stable release |
| 8 | + #- published |
| 9 | + ## stable release only |
| 10 | + - released |
| 11 | +run-name: Post ${{ github.event.release.name }} |
| 12 | + |
| 13 | +jobs: |
| 14 | + call-publish-docs: |
| 15 | + uses: ./.github/workflows/docs.yaml |
| 16 | + pypi-release: |
| 17 | + permissions: |
| 18 | + # write permission is required to update version.py |
| 19 | + contents: write |
| 20 | + pull-requests: write |
| 21 | + # Use the oldest supported version to build, just in case there are issues |
| 22 | + # for our case, this doesn't matter that much, since the build is for 3.x |
| 23 | + strategy: |
| 24 | + matrix: |
| 25 | + include: |
| 26 | + - py_ver: "3.9" |
| 27 | + runs-on: ubuntu-latest |
| 28 | + env: |
| 29 | + PY_VER: ${{matrix.py_ver}} |
| 30 | + TWINE_USERNAME: ${{secrets.twine_username}} |
| 31 | + TWINE_PASSWORD: ${{secrets.twine_password}} |
| 32 | + TWINE_TEST_USERNAME: ${{secrets.twine_test_username}} |
| 33 | + TWINE_TEST_PASSWORD: ${{secrets.twine_test_password}} |
| 34 | + steps: |
| 35 | + - name: Checkout repository |
| 36 | + uses: actions/checkout@v4 |
| 37 | + with: |
| 38 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 39 | + # new release needs the updated version.py |
| 40 | + - name: Update version.py |
| 41 | + run: | |
| 42 | + VERSION=$(echo "${{ github.event.release.name }}" | grep -oP '\d+\.\d+\.\d+') |
| 43 | + sed -i "s/^__version__ = .*/__version__ = \"$VERSION\"/" datajoint/version.py |
| 44 | + cat datajoint/version.py |
| 45 | + # Commit the changes |
| 46 | + BRANCH_NAME="update-version-$VERSION" |
| 47 | + git switch -c $BRANCH_NAME |
| 48 | + git config --global user.name "github-actions" |
| 49 | + git config --global user.email "github-actions@github.com" |
| 50 | + git add datajoint/version.py |
| 51 | + git commit -m "Update version.py to $VERSION" |
| 52 | + echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV |
| 53 | + - name: Update README.md badge |
| 54 | + run: | |
| 55 | + # commits since the last release |
| 56 | + NEW_HREF="https://github.com/datajoint/datajoint-python/compare/${{ github.event.release.tag_name }}...master" |
| 57 | + NEW_SRC="https://img.shields.io/github/commits-since/datajoint/datajoint-python/${{ github.event.release.tag_name }}?color=red" |
| 58 | + # Update href in the <a> tag |
| 59 | + sed -i 's|\(<a id="commit-since-release-link"[^>]*href="\)[^"]*\(".*\)|\1'"$NEW_HREF"'\2|' README.md |
| 60 | + # Update src in the <img> tag |
| 61 | + sed -i 's|\(<img id="commit-since-release-img"[^>]*src="\)[^"]*\(".*\)|\1'"$NEW_SRC"'\2|' README.md |
| 62 | + git add README.md |
| 63 | + git commit -m "Update README.md badge to ${{ github.event.release.tag_name }}" |
| 64 | + - name: Set up Python ${{matrix.py_ver}} |
| 65 | + uses: actions/setup-python@v5 |
| 66 | + with: |
| 67 | + python-version: ${{matrix.py_ver}} |
| 68 | + # Merging build and release steps just for the simplicity, |
| 69 | + # since datajoint-python doesn't have platform specific dependencies or binaries, |
| 70 | + # and the build process is fairly fast, so removed upload/download artifacts |
| 71 | + - name: Build package |
| 72 | + id: build |
| 73 | + run: | |
| 74 | + python -m pip install build |
| 75 | + python -m build . |
| 76 | + echo "DJ_WHEEL_PATH=$(ls dist/datajoint-*.whl)" >> $GITHUB_ENV |
| 77 | + echo "DJ_SDIST_PATH=$(ls dist/datajoint-*.tar.gz)" >> $GITHUB_ENV |
| 78 | + echo "NEW_VERSION=${{github.event.release.resolved_version}}" >> $GITHUB_ENV |
| 79 | + - name: Publish package |
| 80 | + id: publish |
| 81 | + env: |
| 82 | + RELEASE_NAME: ${{ github.event.release.name }} |
| 83 | + run: | |
| 84 | + export HOST_UID=$(id -u) |
| 85 | + if [[ "$RELEASE_NAME" =~ ^Test ]]; then |
| 86 | + LATEST_PYPI=$(curl -s https://test.pypi.org/pypi/datajoint/json | jq -r '.info.version') |
| 87 | + echo "TEST_PYPI=true" >> $GITHUB_ENV |
| 88 | + export TWINE_REPOSITORY="testpypi" |
| 89 | + export TWINE_USERNAME=${TWINE_TEST_USERNAME} |
| 90 | + export TWINE_PASSWORD=${TWINE_TEST_PASSWORD} |
| 91 | + else |
| 92 | + LATEST_PYPI=$(curl -s https://pypi.org/pypi/datajoint/json | jq -r '.info.version') |
| 93 | + echo "TEST_PYPI=false" >> $GITHUB_ENV |
| 94 | + export TWINE_REPOSITORY="pypi" |
| 95 | + fi |
| 96 | + # Check if the new version is different from the latest on PyPI, avoid re-uploading error |
| 97 | + if [ "$NEW_VERSION" != "$LATEST_PYPI" ]; then |
| 98 | + docker compose run --build --quiet-pull \ |
| 99 | + -e TWINE_USERNAME=${TWINE_USERNAME} \ |
| 100 | + -e TWINE_PASSWORD=${TWINE_PASSWORD} \ |
| 101 | + -e TWINE_REPOSITORY=${TWINE_REPOSITORY} \ |
| 102 | + app sh -c "pip install twine && python -m twine upload dist/*" |
| 103 | + else |
| 104 | + echo "::warning::Latest version $LATEST_PYPI on $TWINE_REPOSITORY is the new version $NEW_VERSION" |
| 105 | + fi |
| 106 | + # Upload package as release assets |
| 107 | + - name: Upload pip wheel asset to release |
| 108 | + uses: actions/upload-release-asset@v1 |
| 109 | + env: |
| 110 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 111 | + with: |
| 112 | + upload_url: ${{github.event.release.upload_url}} |
| 113 | + asset_path: ${{env.DJ_WHEEL_PATH}} |
| 114 | + asset_name: pip-datajoint-${{ github.event.release.tag_name }}.whl |
| 115 | + asset_content_type: application/zip |
| 116 | + - name: Upload pip sdist asset to release |
| 117 | + uses: actions/upload-release-asset@v1 |
| 118 | + env: |
| 119 | + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} |
| 120 | + with: |
| 121 | + upload_url: ${{github.event.release.upload_url}} |
| 122 | + asset_path: ${{env.DJ_SDIST_PATH}} |
| 123 | + asset_name: pip-datajoint-${{ github.event.release.tag_name }}.tar.gz |
| 124 | + asset_content_type: application/gzip |
| 125 | + - name: Create Pull Request |
| 126 | + env: |
| 127 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 128 | + run: | |
| 129 | + git push origin ${{ env.BRANCH_NAME }} |
| 130 | + gh pr create \ |
| 131 | + --title "[github-actions]Update version.py to ${{ github.event.release.name }}" \ |
| 132 | + --body "This PR updates \`version.py\` to match the latest release: ${{ github.event.release.name }}" \ |
| 133 | + --base master \ |
| 134 | + --head ${{ env.BRANCH_NAME }} \ |
| 135 | + --reviewer dimitri-yatsenko,yambottle,ttngu207 |
| 136 | + - name: Post release notification to Slack |
| 137 | + if: ${{ env.TEST_PYPI == 'false' }} |
| 138 | + uses: slackapi/slack-github-action@v2.0.0 |
| 139 | + with: |
| 140 | + webhook: ${{ secrets.SLACK_WEBHOOK_URL }} |
| 141 | + webhook-type: incoming-webhook |
| 142 | + payload: | |
| 143 | + { |
| 144 | + "text": "*New Release Published!* :tada: \n*Repository:* ${{ github.repository }}\n*Version:* ${{ github.event.release.tag_name }}\n*URL:* ${{ github.event.release.html_url }}", |
| 145 | + "blocks": [ |
| 146 | + { |
| 147 | + "type": "section", |
| 148 | + "text": { |
| 149 | + "type": "mrkdwn", |
| 150 | + "text": "*New Release Published!* :tada:\n*Repository:* ${{ github.repository }}\n*Version:* ${{ github.event.release.tag_name }}\n*URL:* <${{ github.event.release.html_url }}|View Release>" |
| 151 | + } |
| 152 | + } |
| 153 | + ] |
| 154 | + } |
0 commit comments