-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaction.yml
116 lines (104 loc) · 3.71 KB
/
action.yml
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
name: 'Python auto-release (PyPI & GitHub)'
author: 'Conchylicultor'
description: 'Auto-detect version increase, build and publish PyPI, tag and release on GitHub, parse `CHANGELOG.md`.'
branding:
icon: upload-cloud
color: orange
inputs:
pypi-token:
description: 'Token of the PyPI account publishing the project. If missing, PyPI release is skipped.'
required: false
default: 'skip' # Use sentinel value to error if user forgot to set the GitHub secret
gh-token:
description: 'Github action token. If missing, GitHub release is skipped.'
required: false
parse-changelog:
description: 'Parse the `CHANGELOG.md` (`keep a changelog`
format).'
required: false
default: false
pkg-name:
description: 'Name of the PyPI package (optional).'
required: false
path:
description: 'Root directory of the project (containing the `pyproject.toml`).'
default: '.'
required: false
git-ref:
description: 'Git ref (e.g. SHA or tag) (optional).'
required: false
default: '' # Use 'skip' to skip repository checkout
outputs:
version:
description: "Local project version detected (e.g. `'1.0.0'`)"
value: ${{ steps.compare-version.outputs.version }}
is-released:
description: "Whether a new release was triggered (`'true'` / `'false'`)"
value: ${{ steps.compare-version.outputs.should-release }}
runs:
using: "composite"
steps:
- if: inputs.git-ref != 'skip'
uses: actions/checkout@v3
with:
ref: ${{ inputs.git-ref }}
# Setup Python
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: pip install -e .
shell: bash
working-directory: ${{ inputs.path }}
- run: pip install packaging
shell: bash
working-directory: ${{ inputs.path }}
# Get the local and PyPI versions
# Check if local `__version__` < pip version
# Output: `compare-version.outputs.should-release`
- id: compare-version
run: |
python ${{github.action_path}}/src/compare_version.py \
--pkg_name="${{ inputs.pkg-name }}"
shell: bash
working-directory: ${{ inputs.path }}
- run: |
echo version=${{ steps.compare-version.outputs.version }}
echo should-release=${{ steps.compare-version.outputs.should-release }}
shell: bash
working-directory: ${{ inputs.path }}
# TODO(epot):
# * Could hardcode the version
# * Could auto-detect changelog and format ?
# Parse changelog before, so if there's failure, we don't end up
# in a bad state where PyPI is published but not GitHub
- if: |
inputs.parse-changelog == 'true'
&& steps.compare-version.outputs.should-release == 'true'
id: changelog
uses: mindsers/changelog-reader-action@v2
with:
path: ${{ inputs.path }}/CHANGELOG.md
# Publish the package (if local `__version__` < pip version)
- if: |
inputs.pypi-token != 'skip'
&& steps.compare-version.outputs.should-release == 'true'
uses: etils-actions/pypi-build-publish@v1
with:
pypi-token: ${{ inputs.pypi-token }}
path: ${{ inputs.path }}
# Use env indirection to support multi-lines variable
- if: steps.compare-version.outputs.should-release == 'true'
run: |
echo "release-body=$RELEASE_BODY"
env:
RELEASE_BODY: ${{ steps.changelog.outputs.changes }}
shell: bash
- if: |
inputs.gh-token
&& steps.compare-version.outputs.should-release == 'true'
uses: ncipollo/release-action@v1
with:
commit: ${{ github.sha }}
tag: v${{ steps.compare-version.outputs.version }}
token: ${{ inputs.gh-token }}
body: ${{ steps.changelog.outputs.changes }}