-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathpost_draft_release_published.yaml
More file actions
118 lines (116 loc) · 4.97 KB
/
Copy pathpost_draft_release_published.yaml
File metadata and controls
118 lines (116 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
name: Post Draft Release Published
on:
release:
types:
## pre-release and stable release
#- published
## stable release only
- released
run-name: Post ${{ github.event.release.name }}
jobs:
pypi-release:
permissions:
# write permission is required to upload build artifacts as release assets
contents: write
# Use the oldest supported version to build, just in case there are issues
# for our case, this doesn't matter that much, since the build is for 3.x
strategy:
matrix:
include:
- py_ver: "3.10"
runs-on: ubuntu-latest
env:
PY_VER: ${{matrix.py_ver}}
TWINE_USERNAME: ${{secrets.twine_username}}
TWINE_PASSWORD: ${{secrets.twine_password}}
TWINE_TEST_USERNAME: ${{secrets.twine_test_username}}
TWINE_TEST_PASSWORD: ${{secrets.twine_test_password}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
# Full history + tags so hatch-vcs can derive the version from the
# release tag. The checked-out ref is the tag itself, so the build
# reports exactly X.Y.Z — no version.py bump or follow-up PR needed.
fetch-depth: 0
- name: Set up Python ${{matrix.py_ver}}
uses: actions/setup-python@v5
with:
python-version: ${{matrix.py_ver}}
# Merging build and release steps just for the simplicity,
# since datajoint-python doesn't have platform specific dependencies or binaries,
# and the build process is fairly fast, so removed upload/download artifacts
- name: Build package
id: build
run: |
python -m pip install build
python -m build .
echo "DJ_WHEEL_PATH=$(ls dist/datajoint-*.whl)" >> $GITHUB_ENV
echo "DJ_SDIST_PATH=$(ls dist/datajoint-*.tar.gz)" >> $GITHUB_ENV
echo "NEW_VERSION=${{github.event.release.resolved_version}}" >> $GITHUB_ENV
- name: Publish package
id: publish
env:
RELEASE_NAME: ${{ github.event.release.name }}
run: |
export HOST_UID=$(id -u)
if [[ "$RELEASE_NAME" =~ ^Test ]]; then
LATEST_PYPI=$(curl -s https://test.pypi.org/pypi/datajoint/json | jq -r '.info.version')
echo "TEST_PYPI=true" >> $GITHUB_ENV
export TWINE_REPOSITORY="testpypi"
export TWINE_USERNAME=${TWINE_TEST_USERNAME}
export TWINE_PASSWORD=${TWINE_TEST_PASSWORD}
else
LATEST_PYPI=$(curl -s https://pypi.org/pypi/datajoint/json | jq -r '.info.version')
echo "TEST_PYPI=false" >> $GITHUB_ENV
export TWINE_REPOSITORY="pypi"
fi
# Check if the new version is different from the latest on PyPI, avoid re-uploading error
if [ "$NEW_VERSION" != "$LATEST_PYPI" ]; then
docker compose run --build --quiet-pull \
-e TWINE_USERNAME=${TWINE_USERNAME} \
-e TWINE_PASSWORD=${TWINE_PASSWORD} \
-e TWINE_REPOSITORY=${TWINE_REPOSITORY} \
app sh -c "pip install twine && python -m twine upload dist/*"
else
echo "::warning::Latest version $LATEST_PYPI on $TWINE_REPOSITORY is the new version $NEW_VERSION"
fi
# Upload package as release assets
- name: Upload pip wheel asset to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
upload_url: ${{github.event.release.upload_url}}
asset_path: ${{env.DJ_WHEEL_PATH}}
asset_name: pip-datajoint-${{ github.event.release.tag_name }}.whl
asset_content_type: application/zip
- name: Upload pip sdist asset to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
upload_url: ${{github.event.release.upload_url}}
asset_path: ${{env.DJ_SDIST_PATH}}
asset_name: pip-datajoint-${{ github.event.release.tag_name }}.tar.gz
asset_content_type: application/gzip
- name: Post release notification to Slack
if: ${{ env.TEST_PYPI == 'false' }}
uses: slackapi/slack-github-action@v2.0.0
with:
webhook: ${{ secrets.SLACK_WEBHOOK_URL }}
webhook-type: incoming-webhook
payload: |
{
"text": "*New Release Published!* :tada: \n*Repository:* ${{ github.repository }}\n*Version:* ${{ github.event.release.tag_name }}\n*URL:* ${{ github.event.release.html_url }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"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>"
}
}
]
}