.github/workflows/release.yml
name: Release
on:
release:
types: [created]
jobs:
deploy:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- name: set-up-python
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: install-dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine bumpversion
- name: checkout-release-branch
run: |
git config --local user.email ${{ secrets.GH_MAIL }}
git config --local user.name ${{ secrets.GH_USER }}
NEW_VERSION=$(git describe --tags | cut -d - -f 1 | cut -c2-)
CURR_VERSION=$(cat setup.cfg | grep 'current_version = ' | cut -d '=' -f 2 | cut -c 2-6)
if [[ $(echo $NEW_VERSION | cut -d '.' -f 1 ) != $(echo $CURR_VERSION | cut -d '.' -f 1) ]]; then bumpversion major;
elif [[ $(echo $NEW_VERSION | cut -d '.' -f 2 ) != $(echo $CURR_VERSION | cut -d '.' -f 2) ]]; then bumpversion minor;
elif [[ $(echo $NEW_VERSION | cut -d '.' -f 3 ) != $(echo $CURR_VERSION | cut -d '.' -f 3) ]]; then bumpversion patch;
fi
BRANCH_NAME="release/$NEW_VERSION"
echo $BRANCH_NAME
echo "::set-output name=new_branch::$BRANCH_NAME"
echo "::set-output name=version::$NEW_VERSION"
git checkout -b $BRANCH_NAME
REPO="LUXROBO/pymodi"
IMPORT="import sys; from json import loads as l;"
READ="response = l(sys.stdin.read()); body = response['body'];"
PRINT="[print(line) for line in body.splitlines() if line and line[0].isdigit()]"
CONTENT=$(curl --silent https://api.github.com/repos/$REPO/releases/latest | python -c "$IMPORT $READ $PRINT")
TODAY=$(python -c "from datetime import date; print(str(date.today()))")
HISTORY_FILE="HISTORY.md"
echo "$NEW_VERSION ($TODAY)" >> $HISTORY_FILE
echo "--" >> $HISTORY_FILE
echo -e "$CONTENT" >> $HISTORY_FILE
echo "" >> $HISTORY_FILE
git add .
git commit -m "Release $NEW_VERSION"
git push --set-upstream origin $BRANCH_NAME
id: checkout_branch
- name: create-pr-to-master
uses: repo-sync/pull-request@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_branch: ${{ steps.checkout_branch.outputs.new_branch }}
pr_title: "Merge new release to master branch"
- name: create-pr-to-develop
uses: repo-sync/pull-request@master
with:
destination_branch: "develop"
github_token: ${{ secrets.GITHUB_TOKEN }}
source_branch: ${{ steps.checkout_branch.outputs.new_branch }}
pr_title: "Merge new release to develop branch"
- name: build-and-publish-to-pypi
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload --skip-existing dist/*
- name: login-to-ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.LUXROBO_TOKEN }}
- name: build-and-push-docker-image
uses: docker/build-push-action@v2
with:
push: true
tags: ghcr.io/luxrobo/pymodi:${{ steps.checkout_branch.outputs.version }}
- name: send-release-email
uses: dawidd6/action-send-mail@v2.2.0
with:
server_address: smtp-mail.outlook.com
server_port: 587
username: ${{ secrets.MAIL_USERNAME }}
password: ${{ secrets.MAIL_PASSWORD }}
subject: PyMODI ${{ steps.checkout_branch.outputs.version }} is released!!
body: file://HISTORY.md
to: tech@luxrobo.com
from: PyMODI
- name: notify-ms-teams-channel
uses: jdcargile/ms-teams-notification@v1.2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
ms-teams-webhook-uri: ${{ secrets.TEAMS_WEBHOOK }}
notification-summary: PyMODI ${{ steps.checkout_branch.outputs.version }} is released!
notification-color: 17a2b8
timezone: Korea/Seoul