-
-
Notifications
You must be signed in to change notification settings - Fork 23
135 lines (120 loc) · 4.2 KB
/
release.yaml
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
name: Bump the version on merge
on:
pull_request:
types: [closed]
branches: [master]
workflow_dispatch:
inputs:
releaseType:
description: 'What kind of release is this?'
required: false
default: 'auto'
type: choice
options:
- 'auto'
- 'major'
- 'minor'
- 'patch'
- 'dev'
jobs:
version:
permissions:
id-token: write
pull-requests: read
contents: write
runs-on: ubuntu-latest
outputs:
release-kind: ${{ steps.release-kind.outputs.release-kind }}
package: ${{ steps.bump-version.outputs.package }}
tag-name: ${{ steps.bump-version.outputs.tag-name }}
steps:
- uses: actions/checkout@v4
name: Checkout the repository
with:
fetch-depth: 0
- name: Setup Python and Git
uses: ./.github/actions/setup-python-and-git
with:
python-version: '3.11'
- name: Install requirements
run: |
python -m pip install generate-changelog bump-my-version
- name: Generate the changelog and get the release hint
id: generate-changelog
run: |
RELEASE_KIND=$(generate-changelog --output release-hint)
echo "::notice::Suggested release type for this branch is: ${RELEASE_KIND}"
echo "RELEASE_KIND=$RELEASE_KIND" >> $GITHUB_ENV
- name: Override release kind on manual
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.releaseType != 'auto' }}
id: override-release-kind
run: |
echo "::notice::Overriding release type to ${{ github.event.inputs.releaseType }} since this was a manual trigger"
echo "RELEASE_KIND=${{ github.event.inputs.releaseType }}" >> $GITHUB_ENV
- name: Output release kind
id: release-kind
run: |
echo "release-kind=${{ env.RELEASE_KIND }}" >> $GITHUB_OUTPUT
- name: Get Pull Request Number
id: pr
run: |
PR_NUMBER=$(gh pr view --json number -q .number || echo "${{ github.event.number }}")
echo "pull_request_number=${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "::notice::PR_NUMBER is ${PR_NUMBER}"
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Bump version
id: bump-version
shell: bash
run: |
case "$RELEASE_KIND" in
major|minor|patch)
bump-my-version bump --allow-dirty --verbose "$RELEASE_KIND"
echo "TAG_NAME=$(bump-my-version show current_version)" >> $GITHUB_ENV
export "TAG_NAME=$(bump-my-version show current_version)"
git push
git push --tags
echo "PACKAGE=true" >> $GITHUB_ENV
export PACKAGE=true
;;
dev)
bump-my-version bump --allow-dirty --verbose --no-commit --no-tag "$RELEASE_KIND"
echo "PACKAGE=true" >> $GITHUB_ENV
export PACKAGE=true
;;
*)
echo "PACKAGE=false" >> $GITHUB_ENV
export PACKAGE=false
esac
echo "package=$PACKAGE" >> $GITHUB_OUTPUT
echo "tag-name=$TAG_NAME" >> $GITHUB_OUTPUT
- name: Package and upload artifacts
if: ${{ env.PACKAGE == 'true' }}
uses: ./.github/actions/package-and-upload-artifacts
with:
tag-name: ${{ env.TAG_NAME }}
release:
if: needs.version.outputs.package == 'true'
needs: version
runs-on: ubuntu-latest
permissions:
id-token: write
pull-requests: read
contents: write
steps:
- name: Download packages built by build-and-inspect-python-package
uses: actions/download-artifact@v4
with:
name: Packages
path: dist
- name: Download release notes
uses: actions/download-artifact@v4
with:
name: release-notes
- name: Create a GitHub release
uses: softprops/action-gh-release@v1
with:
files: dist/*
tag_name: "${{ needs.version.outputs.tag-name }}"
body_path: release-notes.md
- name: Upload package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1