-
Notifications
You must be signed in to change notification settings - Fork 1
125 lines (120 loc) · 4.24 KB
/
release.yml
File metadata and controls
125 lines (120 loc) · 4.24 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
---
# this file is *not* meant to cover or endorse the use of GitHub Actions, but
# rather to help make automated releases for this project
name: Upload Python Package
on: # yamllint disable-line rule:truthy
push:
branches:
- main
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
# all history is needed to crawl it properly
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install build dependencies
run: |
if [ -f requirements-deploy.txt ]; then pip install -r requirements-deploy.txt; fi
- name: Update changelog with snippets
run: |
changelog-generator \
changelog changelog.md \
--snippets=.snippets \
--in-place
- name: Extract latest version from changelog
run: |
changelog2version \
--changelog_file changelog.md \
--print \
--debug \
--pretty \
--output changelog.json
- name: Update package.json file
run: |
upy-package \
--setup_file setup.py \
--package_changelog_file changelog.md \
--package_file package.json \
--pretty \
--create
- name: Update version.py file
run: |
changelog2version \
--changelog_file changelog.md \
--version_file be_upy_blink/version.py \
--version_file_type py \
--debug
- name: Build package
run: |
python setup.py sdist
rm dist/*.orig
# sdist call create non conform twine files *.orig, remove them
- name: Test built package
run: |
twine check dist/*.tar.gz
- name: Create release branch
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
LATEST_CHANGELOG_VERSION=$(jq -r '.info.version' changelog.json)
echo "LATEST_CHANGELOG_VERSION: ${LATEST_CHANGELOG_VERSION}"
echo "changelog.json file:"
cat changelog.json
DESIRED_BRANCH="release/${LATEST_CHANGELOG_VERSION}"
echo "DESIRED_BRANCH: ${DESIRED_BRANCH}"
set +e
git ls-remote \
--exit-code \
--heads \
origin ${DESIRED_BRANCH} >/dev/null 2>&1
EXIT_CODE=$?
set -e
echo "EXIT_CODE: ${EXIT_CODE}"
if [[ ${EXIT_CODE} == '0' ]]; then
echo "Git branch '${DESIRED_BRANCH}' exists on remote"
git checkout release/${LATEST_CHANGELOG_VERSION}
elif [[ ${EXIT_CODE} == '2' ]]; then
echo "Git branch '${DESIRED_BRANCH}' does not exist on remote"
git checkout -b release/${LATEST_CHANGELOG_VERSION}
fi
git diff > diff.log
echo "Diff in repo"
cat diff.log
if [[ $(git status --porcelain --untracked-files=no | wc -l) -gt 0 ]]; then
echo "changed files available"
git add package.json changelog.md be_upy_blink/version.py
git status
git commit -m "chore: files for release ${LATEST_CHANGELOG_VERSION}"
git push -u origin release/${LATEST_CHANGELOG_VERSION}
else
echo "nothing new to commit and push"
fi
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1.13
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip_existing: true
verbose: true
print_hash: true
- name: 'Create changelog based release'
uses: brainelectronics/changelog-based-release@v1.1.0
with:
# note you'll typically need to create a personal access token
# with permissions to create releases in the other repo
# or you set the "contents" permissions to "write" as in this example
changelog-path: changelog.md
tag-name-prefix: ''
tag-name-extension: ''
release-name-prefix: ''
release-name-extension: ''
draft-release: true
prerelease: false