add sls #51
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: CI/CD Pipeline | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
jobs: | |
build-and-test: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest, macos-latest] | |
python-version: ["3.12"] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set PYTHONPATH for Linux/macOS | |
if: runner.os != 'Windows' | |
run: | | |
echo "PYTHONPATH=$(pwd)" >> $GITHUB_ENV | |
- name: Set PYTHONPATH for Windows | |
if: runner.os == 'Windows' | |
run: | | |
$env:PYTHONPATH = "$(pwd)" | |
echo "PYTHONPATH=$env:PYTHONPATH" >> $env:GITHUB_ENV | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install modules | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install flask pytest pytest-cov | |
- name: Run tests | |
run: | | |
pytest --cov=redirect_flask_app tests/ | |
deploy: | |
needs: build-and-test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Deploy to server | |
run: | | |
ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USER }}@${{ secrets.SSH_ADDRESS }} <<EOF | |
git clone https://github.com/Freezepop/mifi_dev.git; cd mifi_dev || cd mifi_dev | |
git pull origin master | |
sudo apt update -y | |
sudo apt install python3 python3-pip -y | |
pip3 install flask pytest pytest-cov | |
sudo apt autoremove -y | |
sudo cp redirect_flask_app/flask-redirect.service /etc/systemd/system | |
sudo cp redirect_flask_app/redirect_flask_app.py /opt; sudo chmod 755 /opt/redirect_flask_app.py | |
sudo systemctl daemon-reload; sudo systemctl enable --now flask-redirect.service | |
sudo systemctl status flask-redirect.service --no-pager | |
EOF |