-
Notifications
You must be signed in to change notification settings - Fork 58
178 lines (158 loc) · 7.28 KB
/
release-and-pypi-publish.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
################################################################################################################
#
# This GitHub Action workflow automates several processes for the 'fastlane_bot' Python project.
# It consists of four main jobs: version bumping, release creation, changelog generation, and PyPi package publishing.
#
# 1. Version Bumping ('bump_version'): This job automatically increments the minor version of the project, as defined in 'fastlane_bot/__init__.py'.
# This is done using 'bumpversion', a Python library for version bumping.
#
# 2. Release Creation ('release'): Upon successful version bumping, a new GitHub release is created,
# using the incremented version number as the release's tag.
#
# 3. Changelog Generation ('generate_changelog'): After the creation of the new release,
# this job generates a changelog that provides a record of changes made to the project, including new features, bug fixes, and more.
# The generation is handled by the 'github-changelog-generator-action' GitHub Action.
#
# 4. PyPi Package Publishing ('publish'): The final job publishes the new version of the project to PyPi,
# making the new version accessible via pip install. This job is executed after the successful completion of all previous jobs,
# ensuring that all changes are included in the published package.
#
# (c) Copyright Bprotocol foundation 2023.
# Licensed under MIT
#
################################################################################################################
name: Bump Version, Generate Changelog, Create Release, Publish, and Restart Jobs
on:
push:
branches:
- main
jobs:
combined_job:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.bump_version_and_set_output.outputs.new_version }}
changelog: ${{ steps.generate.outputs.changelog }}
version_changes: ${{ steps.extract_changes.outputs.version_changes }}
steps:
# Checkout
- name: Checkout code
uses: actions/checkout@v2
# Check commit message
- id: check
run: |
MESSAGE=$(git log -1 --pretty=%B)
if [[ "$MESSAGE" == *"[skip ci]"* ]]; then
echo "::set-output name=skip::true"
else
echo "::set-output name=skip::false"
fi
# If commit message doesn't contain "[skip ci]", continue to the next steps
- name: Set up Python
if: steps.check.outputs.skip != 'true'
uses: actions/setup-python@v2
with:
python-version: 3.9
- uses: actions/setup-node@v3
if: steps.check.outputs.skip != 'true'
with:
node-version: 16
- name: Install Ganesh-CLI
if: steps.check.outputs.skip != 'true'
run: npm install -g ganache
- name: Install Dependencies
if: steps.check.outputs.skip != 'true'
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt --force-reinstall
pip install bumpversion
env:
TENDERLY_FORK: '${{ secrets.TENDERLY_FORK }}'
WEB3_ALCHEMY_PROJECT_ID: '${{ secrets.WEB3_ALCHEMY_PROJECT_ID }}'
ETHERSCAN_TOKEN: '${{ secrets.ETHERSCAN_TOKEN }}'
- name: Bump version and set output
if: steps.check.outputs.skip != 'true'
id: bump_version_and_set_output
run: |
CURRENT_VERSION=$(python -c "import fastlane_bot; print(fastlane_bot.__version__)")
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
MINOR=$(echo $CURRENT_VERSION | cut -d. -f2)
PATCH=$(echo $CURRENT_VERSION | cut -d. -f3)
NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
echo new_version=$NEW_VERSION >> $GITHUB_OUTPUT
BRANCH_NAME="version-bump-$NEW_VERSION-run-$GITHUB_RUN_NUMBER"
sed -i "s/$CURRENT_VERSION/$NEW_VERSION/" fastlane_bot/__init__.py
git checkout main
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add fastlane_bot/__init__.py
git commit -m "Bump version [skip ci]"
- name: Generate changelog
if: steps.check.outputs.skip != 'true'
uses: heinrichreimer/[email protected]
with:
token: ${{ secrets.GH_TOKEN }}
output: 'CHANGELOG.md'
configureSections: '{"Merged pull requests": {"labels": ["pull-request","Merge pull request"]}, "Fixed bugs": {"labels": ["bug","bugfix"]}, "Implemented enhancements": {"labels": ["enhancement","feature"]}, "Closed issues": {"labels": ["closed-issue"]}}'
bugsLabel: 'Fixed bugs'
enhancementLabel: 'Implemented enhancements'
issuesLabel: 'Closed issues'
prLabel: 'Merged pull requests'
compareLink: true
addSections: '{"Security fixes": {"labels": ["security"]}, "Breaking changes": {"labels": ["breaking"]}}'
- name: Commit changelog update
if: steps.check.outputs.skip != 'true'
run: |
git checkout main
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add CHANGELOG.md
git commit --allow-empty -m "Update changelog [skip ci]"
# push to main branch using CasperWA/push-protected@v2 action
- name: Push to protected branch
if: steps.check.outputs.skip != 'true'
uses: CasperWA/push-protected@v2
with:
token: ${{ secrets.GH_TOKEN }}
branch: main
- name: Create Release
if: steps.check.outputs.skip != 'true'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: v${{ steps.bump_version_and_set_output.outputs.new_version }}
release_name: Release v${{ steps.bump_version_and_set_output.outputs.new_version }}
body: ${{ steps.extract_changes.outputs.version_changes }}
draft: false
prerelease: false
- name: Create .env file
run: |
echo TENDERLY_FORK=$TENDERLY_FORK > .env
echo WEB3_ALCHEMY_PROJECT_ID=$WEB3_ALCHEMY_PROJECT_ID >> .env
echo ETHERSCAN_TOKEN=$ETHERSCAN_TOKEN >> .env
echo DEFAULT_MIN_PROFIT_BNT=$DEFAULT_MIN_PROFIT_BNT >> .env
echo ETH_PRIVATE_KEY_BE_CAREFUL=$ETH_PRIVATE_KEY_BE_CAREFUL >> .env
echo TENDERLY_FORK_ID=$TENDERLY_FORK_ID >> .env
env:
TENDERLY_FORK: '${{ secrets.TENDERLY_FORK }}'
TENDERLY_FORK_ID: '${{ secrets.TENDERLY_FORK }}'
WEB3_ALCHEMY_PROJECT_ID: '${{ secrets.WEB3_ALCHEMY_PROJECT_ID }}'
ETHERSCAN_TOKEN: '${{ secrets.ETHERSCAN_TOKEN }}'
DEFAULT_MIN_PROFIT_BNT: '${{ secrets.DEFAULT_MIN_PROFIT_BNT }}'
ETH_PRIVATE_KEY_BE_CAREFUL: '${{ secrets.ETH_PRIVATE_KEY_BE_CAREFUL }}'
- name: Install package
run: |
python setup.py install
- name: Build package
run: python setup.py sdist
- name: Build wheel
run: |
pip install wheel
python setup.py bdist_wheel
find dist -type f ! -name "*.whl" -exec rm -f {} +
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.FASTLANE_PYPI_API_TOKEN }}
repository-url: https://upload.pypi.org/legacy/