Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding github action for automating releases #390

Merged
merged 13 commits into from
Oct 24, 2023
50 changes: 50 additions & 0 deletions .github/workflows/test_release_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build, Test, Publish Github and PyPI Releases

on:
workflow_dispatch:

jobs:
publish_github_release_and_pypi:
runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install pip and pipenv
run: |
python -m pip install --root-user-action=ignore --upgrade pip
pip install --root-user-action=ignore pipenv
make venv
- name: Build Release tar.gz
run: |
pipenv run python setup.py sdist
- name: Install Build and Run PAT Tests
run: |
pipenv run pip install --root-user-action=ignore dist/panther_analysis_tool-*.tar.gz
pipenv run make test
- name: Create Github Release
run: |
export NEW_VERSION=$(cat VERSION)
git config user.name "dac-bot"
git config user.email "dac-bot@panther.com"
gh release create v$NEW_VERSION -t v$NEW_VERSION
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish to PyPI
run: |
pipenv run twine upload dist/*
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
56 changes: 56 additions & 0 deletions .github/workflows/version_bump_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Version Bump PR

on:
workflow_dispatch:
inputs:
bump_type:
description: 'Version Bump Type (major, minor, patch)'
required: true
default: 'minor'

jobs:
version_bump_pr:
runs-on: ubuntu-latest

steps:
- name: Check out the repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Bump version
id: bump_version
run: |
BUMP_TYPE="${{ github.event.inputs.bump_type }}"
case "$BUMP_TYPE" in
major)
NEW_VERSION=$(cat VERSION | awk -F. '{printf "%d.0.0", $1+1}')
;;
minor)
NEW_VERSION=$(cat VERSION | awk -F. '{printf "%s.%d.0", $1, $2+1}')
;;
patch)
NEW_VERSION=$(cat VERSION | awk -F. '{printf "%s.%s.%d", $1, $2, $3+1}')
;;
*)
echo "Error: Invalid bump type"
exit 1
;;
esac
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo $NEW_VERSION > VERSION
sed -i "s/VERSION_STRING: Final = \"[0-9]*\.[0-9]*\.[0-9]*\"/VERSION_STRING: Final = \"$NEW_VERSION\"/" panther_analysis_tool/constants.py
- name: Create Branch and Pull Request
run: |
NEW_VERSION="${{ steps.bump_version.outputs.new_version }}"
git config user.name "dac-bot"
git config user.email "dac-bot@panther.com"
git checkout -b "$NEW_VERSION"
git commit -a -m "Bump version to $NEW_VERSION"
git push --set-upstream origin "$NEW_VERSION"
gh pr create -t "Version bump to v$NEW_VERSION"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}