-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (112 loc) · 3.92 KB
/
autorelease.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Auto Release
on:
push:
branches:
- "main"
workflow_dispatch:
inputs:
bump-version:
description: 'Automatically increase patch version (true|false)'
default: 'true'
required: false
release-type:
description: 'Type of release (patch|minor|major)'
default: 'patch'
required: false
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
env:
VERSION_FILE: python/flame/config.py
MODULE_CODE: flame/*
PYPI_PUBLISH: 1
jobs:
release:
runs-on: ubuntu-latest
if: github.repository == 'hesa/foss-licenses'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Sanity checks
run: |
if [ "${{ env.PYPI_PUBLISH }}" = "1" ] && [ -z "${{ secrets.PYPI_API_TOKEN }}" ]; then
echo "::error ::secrets.PYPI_API_TOKEN needs to be set for this action"
exit 1
fi
if [ -z "${{ secrets.TOKEN }}" ]; then
echo "::error ::secrets.TOKEN needs to be set for this action"
exit 1
fi
if [ "${{ github.event_name == 'workflow_dispatch' }}" = "true" ]; then
if [ -z "${{ github.event.inputs.release-type }}" ]; then
echo "::error ::release-type cannot be empty"
exit 1
fi
fi
- name: Check if relevant for release
uses: dorny/paths-filter@v3.0.0
id: code-changes
with:
filters: |
relevant-for-release:
- 'requirements.txt'
- '${{ env.MODULE_CODE }}'
- name: Check if we need to release
id: release-needed
run: |
do_release=0
do_bump=0
[ "${{ steps.code-changes.outputs.relevant-for-release == 'true' }}" = "true" ] && do_release=1
if [ "${{ github.event_name == 'workflow_dispatch' }}" = "true" ]; then
do_release=1
[ "${{ github.event.inputs.bump-version }}" = "true" ] && do_bump=1
fi
if [ "${{ github.event_name == 'workflow_dispatch' }}" = "true" ]; then
echo RELEASE_TYPE="${{ github.event.inputs.release-type }}" >> $GITHUB_OUTPUT
else
echo RELEASE_TYPE="patch" >> $GITHUB_OUTPUT
fi
if [ $do_release -eq 1 ] || [ $do_bump -eq 1 ]; then
echo DO_RELEASE=true >> $GITHUB_OUTPUT
else
echo DO_RELEASE=false >> $GITHUB_OUTPUT
fi
- name: Install dependencies
if: steps.release-needed.outputs.DO_RELEASE == 'true'
run: |
cd python
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Bump version
id: version-bump
run: |
cd python
pip install -r requirements-dev.txt
cd ..
echo "Bump version: bump2version --list ${{ steps.release-needed.outputs.RELEASE_TYPE }} ${{ env.VERSION_FILE }} >> $GITHUB_OUTPUT"
bump2version --list ${{ steps.release-needed.outputs.RELEASE_TYPE }} ${{ env.VERSION_FILE }} >> $GITHUB_OUTPUT
- name: Build
if: steps.release-needed.outputs.DO_RELEASE == 'true'
run: |
cd python
python3 setup.py build sdist bdist_wheel --universal
- name: Commit new version
if: steps.release-needed.outputs.DO_RELEASE == 'true'
uses: actions-x/commit@v6
with:
files: ${{ env.VERSION_FILE }} .bumpversion.cfg
message: 'Release ${{ steps.version-bump.outputs.new_version }}'
- name: Create new release
if: steps.release-needed.outputs.DO_RELEASE == 'true'
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.version-bump.outputs.new_version }}
generateReleaseNotes: true
token: ${{ secrets.TOKEN }}
- name: Publish package
if: steps.release-needed.outputs.DO_RELEASE == 'true' && env.PYPI_PUBLISH == '1'
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: python/dist
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}