-
Notifications
You must be signed in to change notification settings - Fork 14
154 lines (132 loc) · 4.84 KB
/
Copy pathpublish.yml
File metadata and controls
154 lines (132 loc) · 4.84 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
153
154
name: Publish on PR merge
on:
pull_request:
types: [opened, synchronize, reopened, labeled, closed]
branches:
- master
permissions:
contents: write
id-token: write
pull-requests: write
jobs:
update-version-and-changelog:
# Run only when a release label is added (not on every push)
if: |
github.event.action == 'labeled' &&
github.event.pull_request.merged == false && (
contains(github.event.pull_request.labels.*.name, 'release:major') ||
contains(github.event.pull_request.labels.*.name, 'release:minor') ||
contains(github.event.pull_request.labels.*.name, 'release:patch')
)
runs-on: ubuntu-latest
steps:
- name: Check out PR branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install tools
run: |
pip install bump-my-version build pandoc
sudo apt-get update
sudo apt-get install -y pandoc
cargo install git-cliff
- name: Set up Git user
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Determine version bump type
id: bump
run: |
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'release:major') }}" == "true" ]]; then
echo "type=major" >> $GITHUB_OUTPUT
elif [[ "${{ contains(github.event.pull_request.labels.*.name, 'release:minor') }}" == "true" ]]; then
echo "type=minor" >> $GITHUB_OUTPUT
else
echo "type=patch" >> $GITHUB_OUTPUT
fi
- name: Bump version
run: bump-my-version bump ${{ steps.bump.outputs.type }}
env:
BMV_ALLOW_DIRTY: "true"
- name: Extract version
id: version
run: |
VERSION=$(bump-my-version show current)
echo "Extracted version: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Generate changelog
run: |
git cliff -o CHANGELOG.md
echo "Generated changelog for version ${{ steps.version.outputs.version }}"
- name: Update HISTORY.rst
run: |
# Convert CHANGELOG.md to rst and prepend to HISTORY.rst
if [ -f CHANGELOG.md ]; then
pandoc CHANGELOG.md -f markdown -t rst -o CHANGELOG.rst
# Prepend new changelog to HISTORY.rst
if [ -f HISTORY.rst ]; then
cat HISTORY.rst CHANGELOG.rst > HISTORY_temp.rst
mv HISTORY_temp.rst HISTORY.rst
echo "Updated HISTORY.rst with version ${{ steps.version.outputs.version }}"
else
mv CHANGELOG.rst HISTORY.rst
echo "Created HISTORY.rst"
fi
fi
- name: Commit and push changes to PR branch
run: |
git add .
git commit -m "chore: bump version to ${{ steps.version.outputs.version }} and update changelog [skip ci]" || echo "No changes to commit"
git push origin HEAD:${{ github.head_ref }}
publish-after-merge:
# Run only after PR is merged with release labels
if: |
github.event.pull_request.merged == true && (
contains(github.event.pull_request.labels.*.name, 'release:major') ||
contains(github.event.pull_request.labels.*.name, 'release:minor') ||
contains(github.event.pull_request.labels.*.name, 'release:patch')
)
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
- name: Install tools
run: pip install bump-my-version build
- name: Extract version
id: version
run: |
VERSION=$(bump-my-version show current)
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.version.outputs.version }}
name: v${{ steps.version.outputs.version }}
body_path: CHANGELOG.md
generate_release_notes: false
- name: Build package
run: python -m build
- name: Publish to TestPyPI
id: test-pypi
uses: pypa/gh-action-pypi-publish@v1.13.0
with:
repository-url: https://test.pypi.org/legacy/
skip-existing: true
attestations: false
- name: Publish to PyPI
if: steps.test-pypi.outcome == 'success'
uses: pypa/gh-action-pypi-publish@v1.13.0
with:
skip-existing: true