-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathpost_draft_release_published.yaml
More file actions
152 lines (150 loc) · 6.79 KB
/
post_draft_release_published.yaml
File metadata and controls
152 lines (150 loc) · 6.79 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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 update version.py
contents: write
pull-requests: 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 }}
# new release needs the updated version.py
- name: Update version.py
run: |
VERSION=$(echo "${{ github.event.release.name }}" | grep -oP '\d+\.\d+\.\d+')
sed -i "s/^__version__ = .*/__version__ = \"$VERSION\"/" src/datajoint/version.py
cat src/datajoint/version.py
# Commit the changes
BRANCH_NAME="update-version-$VERSION"
git switch -c $BRANCH_NAME
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
git add src/datajoint/version.py
git commit -m "Update version.py to $VERSION"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Update README.md badge
run: |
# commits since the last release
NEW_HREF="https://github.com/datajoint/datajoint-python/compare/${{ github.event.release.tag_name }}...master"
NEW_SRC="https://img.shields.io/github/commits-since/datajoint/datajoint-python/${{ github.event.release.tag_name }}?color=red"
# Update href in the <a> tag
sed -i 's|\(<a id="commit-since-release-link"[^>]*href="\)[^"]*\(".*\)|\1'"$NEW_HREF"'\2|' README.md
# Update src in the <img> tag
sed -i 's|\(<img id="commit-since-release-img"[^>]*src="\)[^"]*\(".*\)|\1'"$NEW_SRC"'\2|' README.md
git add README.md
# Only commit if there are changes (handles re-runs gracefully)
git diff --cached --quiet README.md || git commit -m "Update README.md badge to ${{ github.event.release.tag_name }}"
- 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: Create Pull Request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git push origin ${{ env.BRANCH_NAME }}
gh pr create \
--title "[github-actions]Update version.py to ${{ github.event.release.name }}" \
--body "This PR updates \`version.py\` to match the latest release: ${{ github.event.release.name }}" \
--base master \
--head ${{ env.BRANCH_NAME }} \
--reviewer dimitri-yatsenko,drewyangdev,ttngu207
- 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>"
}
}
]
}