Skip to content

Merge pull request #33 from bancorprotocol/bugfix/rate_limiter #7

Merge pull request #33 from bancorprotocol/bugfix/rate_limiter

Merge pull request #33 from bancorprotocol/bugfix/rate_limiter #7

################################################################################################################
#
# 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, and Publish
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
brownie networks import ./brownie-config.yaml true
brownie networks delete mainnet
brownie networks add "Ethereum Mainnet" "mainnet" host="https://eth-mainnet.alchemyapi.io/v2/$WEB3_ALCHEMY_PROJECT_ID" chainid=1
brownie networks set_provider alchemy
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 + 1)).${PATCH}"
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 "action@github.com"
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/github-changelog-generator-action@v2.3
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 "action@github.com"
git config --local user.name "GitHub Action"
git add CHANGELOG.md
git commit -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
- 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/