-
-
Notifications
You must be signed in to change notification settings - Fork 144
131 lines (119 loc) · 3.72 KB
/
release.yml
File metadata and controls
131 lines (119 loc) · 3.72 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
name: release
# To release this package:
# 1. Update the version number and changelog in the source.
# Commit and push (to branch main or a vX.Y patch branch),
# and wait for tests to complete.
# 2. Tag with "vX.Y" or "vX.Y.Z": either create and push tag
# directly via git, or create and publish a GitHub release.
#
# This workflow will run in response to the new tag, and will:
# - Verify the source code and git tag version numbers match
# - Publish the package to PyPI
# - Create or update the release on GitHub
on:
push:
tags: ["v[0-9]*"]
workflow_dispatch:
permissions: {}
jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: read
outputs:
anchor: ${{ steps.version.outputs.anchor }}
tag: ${{ steps.version.outputs.tag }}
version: ${{ steps.version.outputs.version }}
steps:
- name: Get code
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: "3.14"
- name: Install build requirements
run: |
python -m pip install --upgrade build hatch twine
- name: Get version
# (This will end the workflow if git and source versions don't match.)
id: version
run: |
VERSION="$(python -m hatch version)"
TAG="v$VERSION"
GIT_TAG="$(git tag -l --points-at "$GITHUB_REF" 'v*')"
if [ "x$GIT_TAG" != "x$TAG" ]; then
echo "::error ::package version '$TAG' does not match git tag '$GIT_TAG'"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "anchor=${TAG//[^[:alnum:]]/-}" >> $GITHUB_OUTPUT
- name: Build distribution
run: |
rm -rf build dist django_anymail.egg-info
python -m build
- name: Check metadata
run: |
python -m twine check dist/*
- name: Upload build artifacts
uses: actions/upload-artifact@v7
with:
name: dist
path: dist/
retention-days: 7
publish:
needs: [build]
runs-on: ubuntu-22.04
environment:
name: pypi
url: https://pypi.org/p/django-anymail
permissions:
# Required for PyPI trusted publishing
id-token: write
steps:
- name: Download build artifacts
uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
release:
needs: [build, publish]
runs-on: ubuntu-22.04
permissions:
# `gh release` requires write permission on repo contents
contents: write
steps:
- name: Download build artifacts
uses: actions/download-artifact@v8
with:
name: dist
path: dist/
- name: Release to GitHub
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.build.outputs.tag }}
TITLE: ${{ needs.build.outputs.tag }}
NOTES: |
[Changelog](https://anymail.dev/en/stable/changelog/#${{ needs.build.outputs.anchor }})
run: |
if ! gh release edit "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--verify-tag \
--target "$GITHUB_SHA" \
--title "$TITLE" \
--notes "$NOTES"
then
gh release create "$TAG" \
--repo "$GITHUB_REPOSITORY" \
--verify-tag \
--target "$GITHUB_SHA" \
--title "$TITLE" \
--notes "$NOTES"
fi
gh release upload "$TAG" \
--repo "$GITHUB_REPOSITORY" \
./dist/*