-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
182 lines (165 loc) · 6.18 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
name: 'WIPAC Dev Py Setup'
description: 'GitHub Action Package for Automating Python-Package Setup'
inputs:
# REQUIRED
python_min:
description: 'Minimum required Python version'
required: true # needs to be explicitly checked
# OPTIONAL (python)
python_max:
description: 'Maximum supported Python version. If not provided, the most recent Python version will be used.'
required: false
default: ''
# OPTIONAL (packaging)
package_dirs:
description: "Space-separated list of directories to release. If not provided, all packages in the repository's root directory will be used."
required: false
default: ''
exclude_dirs:
description: "Space-separated list of directories to exclude from release, relative to the repository's root directory."
required: false
default: 'test tests doc docs resource resources example examples'
# OPTIONAL (releases)
pypi_name:
description: 'Name of the PyPI package'
required: false
default: ''
patch_without_tag:
description: 'Whether to make a patch release even if the commit message does not explicitly warrant one'
required: false
default: 'True'
# OPTIONAL (meta)
keywords:
description: 'Space-separated list of keywords'
required: false
default: ''
author:
description: 'Author of the package (required if the package is intended to be hosted on PyPI)'
required: false
default: ''
author_email:
description: 'Email of the package author (required if the package is intended to be hosted on PyPI)'
required: false
default: ''
# OPTIONAL (git)
git_committer_name:
description: 'Name used for "git config user.name"'
required: false
default: github-actions
git_committer_email:
description: 'Email used for "git config user.email"'
required: false
default: github-actions@github.com
# outputs:
# random-number:
# description: "Random number"
# value: ${{ steps.random-number-generator.outputs.random-id }}
runs:
using: "composite"
steps:
- name: check required inputs
run: |
if [ -z "${{ inputs.python_min }}" ]; then
echo "required input not provided: python_min"
exit 1
fi
shell: bash
- uses: actions/setup-python@v4
with:
python-version: '3.12' # NOTE: update, someday.
- name: Is this most recent commit? It won't be if action was reran
run: |
git fetch &> /dev/null
if [[ $(git status -sb | grep behind) ]]; then
echo "IS_GIT_BEHIND=true" >> $GITHUB_ENV
echo "this commit is not most recent on this branch -- rest of action will be skipped"
fi
shell: bash
- name: check for deprecated features
if: env.IS_GIT_BEHIND != 'true'
run: |
if [[ -f setup.cfg ]]; then
echo " "
echo "WIPACrepo/wipac-dev-py-setup-action no longer supports 'setup.cfg'"
echo "Migration Steps:"
echo " 1. Manually move attributes from [wipac:cicd_setup_builder]"
echo " section to WIPACrepo/wipac-dev-py-setup-action's 'with' block."
echo " See https://github.com/WIPACrepo/wipac-dev-py-setup-action#inputs"
echo " 2. Migrate any non-autogenerated configuration to 'pyproject.toml', "
echo " then delete 'setup.cfg'. If there is no non-autogenerated"
echo " configuration, simply delete 'setup.cfg'."
echo " 3. Re-run this action!"
exit 1
fi
shell: bash
- name: Git config
if: env.IS_GIT_BEHIND != 'true'
run: |
git config user.name ${{ inputs.git_committer_name }}
git config user.email ${{ inputs.git_committer_email }}
shell: bash
- name: Build pyproject.toml + README.md (and commit)
if: env.IS_GIT_BEHIND != 'true'
run: |
set -e
sudo apt-get update
python -m venv action_venv
. action_venv/bin/activate
pip3 install -r ${{ github.action_path }}/requirements.txt
# Build!
set -x
# NOTE: when an arg is a list, don't quote it
python3 ${{ github.action_path }}/pyproject_toml_builder.py \
--toml pyproject.toml \
--github-full-repo $GITHUB_REPOSITORY \
--token ${{ github.token }} \
--python-min "${{ inputs.python_min }}" \
--keywords ${{ inputs.keywords }} \
--python-max "${{ inputs.python_max }}" \
--package-dirs ${{ inputs.package_dirs }} \
--exclude-dirs ${{ inputs.exclude_dirs }} \
--pypi-name "${{ inputs.pypi_name }}" \
--patch-without-tag "${{ inputs.patch_without_tag }}" \
--author "${{ inputs.author }}" \
--author-email "${{ inputs.author_email }}"
set +x
# format (inc. sorting sections)
pip install toml-sort
toml-sort --in-place --ignore-case pyproject.toml
cat pyproject.toml
rm -rf action_venv
# Commits
git add pyproject.toml
git commit -m "<bot> update pyproject.toml" || true
git add README.md || true
git commit -m "<bot> update README.md" || true
shell: bash
- name: Add py.typed file(s) (and commit)
if: env.IS_GIT_BEHIND != 'true'
run: |
python -c '
import os, sys
from pathlib import Path
sys.path.append(os.path.abspath("${{ github.action_path }}"))
from find_packages import iterate_dirnames
for pkg_dname in iterate_dirnames(Path("."), "${{ inputs.exclude_dirs }}".split()):
print(pkg_dname)
fpath = Path(pkg_dname) / "py.typed"
print(fpath)
fpath.touch() # create if needed!
'
git add . # won't error if nothing to add
git commit -m "<bot> add py.typed file(s)" || true
shell: bash
- name: Push changes
if: env.IS_GIT_BEHIND != 'true'
run: |
status=`git status 2>&1 | tee`
ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
if [ "$ahead" -eq "1" ]; then
echo "no changes needed"
exit 0
fi
git push
echo "changes pushed"
shell: bash