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

Create actions for deployment #132

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Deployment Workflow

on:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
submodules: recursive

- name: Setup Environment
run: |
pip install jinja2
generate/generate-python.py --output-dir=brping
git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
git fetch origin deployment
git config user.email "[email protected]"
git config user.name "BlueRobotics-CI"

- name: install and test
run: |
echo "installing package..."
pip install . --user

echo "testing message api..."
python brping/pingmessage.py


- name: Generate and Commit Files
run: |
ci/deploy.sh

- name: Commit Changes
run: |
git commit -m "update autogenerated files for $(git rev-parse HEAD@{2})" || exit 0

- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: deployment
47 changes: 47 additions & 0 deletions .github/workflows/deploy_to_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Deploy to PyPI

on:
push:
tags:
- 'v*.*.*' # This will trigger the workflow only when a tag that matches the pattern is pushed

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
submodules: recursive

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Check Tag and setup.py Version Match
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
SETUP_VERSION=$(grep -oE "version='([^']+)" setup.py | grep -oE '[^=]+$')
if [[ "$TAG_VERSION" != "$SETUP_VERSION" ]]; then
echo "Tag version $TAG_VERSION does not match setup.py version $SETUP_VERSION."
exit 1
fi

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install jinja2 setuptools wheel
generate/generate-python.py --output-dir=brping

- name: Build package
run: |
python setup.py sdist bdist_wheel

- name: Build and Publish
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
distributions: "sdist bdist_wheel"
23 changes: 1 addition & 22 deletions ci/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@
# source helper functions
source ci/ci-functions.sh

# thank you https://stackoverflow.com/a/47441734
# this is requried to be able to checkout branches after fetching
test git config remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
test git fetch origin deployment

# TODO make test() work with | pipe
cat ci/deploy-whitelist | xargs git add -f
# commit generated files if necessary, it's ok if commit fails
git commit -m temporary-commit
git commit -m "temporary commit"
# move to deployment branch
test git checkout deployment
test rm -rf *
Expand All @@ -22,19 +17,3 @@ cat ci/deploy-whitelist | xargs git checkout HEAD@{1}
test git --no-pager diff --staged
# unstage the whitelist
test git rm -f ci/deploy-whitelist

if [ "${TRAVIS}" == "true" ]; then
test git config user.email "[email protected]"
test git config user.name "BlueRobotics-CI"
fi

git commit -m "update autogenerated files for $(git rev-parse HEAD@{2})" || return 0

# deploy
if [ ! -z ${TRAVIS_PULL_REQUEST} ] && [ ${TRAVIS_PULL_REQUEST} == "false" ]; then
echob "Updating deployment branch.."
test git remote set-url origin https://${GITHUB_TOKEN}@github.com/bluerobotics/ping-python
test git push origin
else
echob "PR detected, no deployment will be done."
fi