CI/CD Development #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: API CI/CD (Backend) | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- 'trails-viz-api/**' | |
pull_request: | |
branches: | |
- master | |
paths: | |
- 'trails-viz-api/**' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up python | |
uses: actions/setup-python@v3 | |
with: | |
python-version: '3.7' | |
- name: Install dependencies | |
run: | | |
set -e | |
python -m pip install --upgrade pip | |
pip install flake8 | |
pip install wheel | |
cd trails-viz-api | |
pip install -r requirements.txt | |
- name: Run flake8 and build project | |
run: | | |
set -e | |
cd trails-viz-api | |
flake8 . --count --max-line-length=119 --exclude trailsvizapi/__init__.py --show-source --statistics | |
python setup.py bdist_wheel | |
# - name: Upload build artifact # save the dist folder as an artifact | |
# if: github.event_name == 'push' | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: trails-viz-api-dist | |
# path: trails-viz-api/dist | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' # only deploy on push event | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# - name: Download build artifact # download the dist folder from build | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: trails-viz-api-dist | |
# path: trails-viz-api/dist | |
- name: Setup git user identity | |
run: | | |
git config --global user.name "outdoorrd-bot" | |
git config --global user.email "[email protected]" | |
- name: Update app version | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
set -e | |
commit_message=$(git log -1 --pretty=%B) # Get commit message | |
git checkout master | |
cd trails-viz-api/trailsvizapi | |
echo "Updating version..." | |
if [[ "$commit_message" == *"release=major"* ]]; then | |
bump2version major | |
elif [[ "$commit_message" == *"release=minor"* ]]; then | |
bump2version minor | |
elif [[ "$commit_message" == *"release=patch"* ]]; then | |
bump2version patch | |
else | |
bump2version patch | |
fi | |
# update the api version in __init__.py | |
# git checkout master | |
# cd trails-viz-api | |
# sed -i "s/__version__.*/__version__ = '$new_version'/" trailsvizapi/__init__.py | |
# cd .. | |
# echo "local version bump successful $new_version" | |
new_version=$(sed -n "s/__version__ = '\(.*\)'/\1/p" __init__.py) | |
git add trails-viz-api/trailsvizapi/__init__.py | |
git commit -m "Auto update version to $new_version" | |
echo "commited after version update" | |
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git | |
git push origin master | |
git tag "api-v$new_version" | |
git push origin --tags | |
echo "pushed new version to master" | |
- name: Deploy to Digital Ocean Droplet | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.DROPLET_IP }} | |
username: ${{ secrets.SSH_USERNAME }} # Update to use nginx user | |
key: ${{ secrets.DROPLET_SSH_KEY }} | |
script: | | |
cd trails-viz/ | |
git pull origin master | |
conda activate trails-viz-api | |
cd trails-viz-api/ | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
cd docker-conf/ | |
chmod +x ./start.sh | |
./start.sh |