From 036cb6006bc88efd345c9f7ca60ed29263ef2c17 Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Tue, 5 Sep 2023 16:43:12 -0300 Subject: [PATCH 1/2] CI: create deploy.yml --- .github/workflows/deploy.yml | 48 ++++++++++++++++++++++++++++++++++++ ci/deploy.sh | 23 +---------------- 2 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..32c3049d --- /dev/null +++ b/.github/workflows/deploy.yml @@ -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 "support@bluerobotics.com" + 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 diff --git a/ci/deploy.sh b/ci/deploy.sh index 5dea176b..62b1d5f8 100755 --- a/ci/deploy.sh +++ b/ci/deploy.sh @@ -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 * @@ -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 "support@bluerobotics.com" - 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 From 6cae6385197173ff9630350647fa49438b755d8e Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Tue, 5 Sep 2023 20:38:04 -0300 Subject: [PATCH 2/2] CI: create deployment for PYPi --- .github/workflows/deploy_to_pypi.yml | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/deploy_to_pypi.yml diff --git a/.github/workflows/deploy_to_pypi.yml b/.github/workflows/deploy_to_pypi.yml new file mode 100644 index 00000000..22f3fd83 --- /dev/null +++ b/.github/workflows/deploy_to_pypi.yml @@ -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/gh-action-pypi-publish@v1.8.10 + with: + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} + distributions: "sdist bdist_wheel"