Deploy #52
Workflow file for this run
This file contains hidden or 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" | |
| on: | |
| push: | |
| branches: ["master"] | |
| pull_request: | |
| branches: ["master"] | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| env: # Or as an environment variable | |
| BRANCH: master | |
| DIRECTORY: /opt/jbond | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Python | |
| # This is the version of the action for setting up Python, not the Python version. | |
| uses: actions/setup-python@v5 | |
| with: | |
| # Semantic version range syntax or exact version of a Python version | |
| python-version: '3.x' | |
| # Optional - x64 or x86 architecture, defaults to x64 | |
| architecture: 'x64' | |
| - name: Set up Python libs | |
| run: | | |
| python3 -m ensurepip | |
| pip3 install aiogram | |
| - name: install ssh keys | |
| # check this thread to understand why its needed: | |
| # <https://stackoverflow.com/a/70447517> | |
| run: | | |
| install -m 600 -D /dev/null ~/.ssh/id_rsa | |
| echo "${{ secrets.JBOND_SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
| cat ~/.ssh/id_rsa | |
| ssh-keyscan -H ${{ secrets.JBOND_SSH_HOST }} > ~/.ssh/known_hosts | |
| - name: clone | |
| run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "rm -rf $DIRECTORY && git clone https://github.com/andrevis/jbond.git $DIRECTORY" | |
| - name: checkout-pull | |
| run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "cd $DIRECTORY && git checkout $BRANCH && git pull origin $BRANCH" | |
| - name: stop service | |
| run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "systemctl stop jbond.service && systemctl disable jbond.service" | |
| - name: set token | |
| run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "echo ${{ secrets.JBOND_BOT_TOKEN }} > $DIRECTORY/token" | |
| - name: setup service | |
| run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "cp -f $DIRECTORY/misc/jbond.service /usr/lib/systemd/system/" | |
| - name: enable service | |
| run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "systemctl daemon-reload && systemctl enable jbond.service && systemctl restart jbond.service" | |
| - name: setup logrotate | |
| run: ssh ${{ secrets.JBOND_SSH_USER }}@${{ secrets.JBOND_SSH_HOST }} "cp -f $DIRECTORY/misc/jbond_logrotate /etc/logrotate.d/ && systemctl restart crond" | |
| - name: cleanup keys | |
| if: always() | |
| run: rm -rf ~/.ssh/id_rsa |