Skip to content

feat: sync dev configs from secrets #535

feat: sync dev configs from secrets

feat: sync dev configs from secrets #535

Workflow file for this run

name: Docker testing
on:
push:
# Publish `dev` as Docker `testing` image.
branches:
- dev
env:
IMAGE_NAME: sysblokbot
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v2
with:
ref: dev
- name: Python Style Checker
working-directory: ${{ github.workspace }}
run: |
pip3 install --upgrade pip
export PATH="$HOME/.local/bin:$PATH"
pip3 install pycodestyle
pycodestyle . --max-line-length 100
- name: Notify us about failure
if: ${{ failure() }}
env:
TELEGRAM_TEST_TOKEN: ${{ secrets.TELEGRAM_TEST_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
run: |
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"parse_mode": "markdown", "chat_id": "${{ env.TELEGRAM_ERROR_CHAT_ID }}", "text": "[github CI] pycodestyle [failed](https://github.com/sysblok/sysblokbot/actions/runs/${{github.run_id}})" \
}' \
https://api.telegram.org/bot${{env.TELEGRAM_TEST_TOKEN}}/sendMessage
# - name: Python Pytest Github Action
# uses: fylein/python-pytest-github-action@v2
# with:
# args: apt-get update && apt-get install -y git && pip3 install -e . && pip3 install -r requirements.txt && pytest tests/unit
- name: Notify us about failure
if: ${{ failure() }}
env:
TELEGRAM_TEST_TOKEN: ${{ secrets.TELEGRAM_TEST_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
run: |
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"parse_mode": "markdown", "chat_id": "${{ env.TELEGRAM_ERROR_CHAT_ID }}", "text": "[github CI] unit tests [failed](https://github.com/sysblok/sysblokbot/actions/runs/${{github.run_id}})" \
}' \
https://api.telegram.org/bot${{env.TELEGRAM_TEST_TOKEN}}/sendMessage
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: dev
- name: Generate build args
id: args
run: |
echo "::set-output name=commit_hash::$(git rev-parse HEAD)"
echo "::set-output name=commit_hash_short::$(git rev-parse --short HEAD)"
- name: Publish to Github Packages Registry with cache
uses: whoan/docker-build-with-cache-action@v5
env:
IMAGE_NAME: ${{ env.IMAGE_NAME }}
COMMIT_HASH: "${{ steps.args.outputs.commit_hash }}"
COMMIT_HASH_SHORT: "${{ steps.args.outputs.commit_hash_short }}"
with:
image_name: ${{ github.repository }}/${{ env.IMAGE_NAME }}
registry: docker.pkg.github.com
username: sysblok
password: ${{ secrets.GITHUB_TOKEN }}
dockerfile: Dockerfile
image_tag: testing
build_extra_args: "--build-arg=COMMIT_HASH --build-arg=COMMIT_HASH_SHORT"
- name: Notify us about failure
if: ${{ failure() }}
env:
TELEGRAM_TEST_TOKEN: ${{ secrets.TELEGRAM_TEST_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
run: |
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"parse_mode": "markdown", "chat_id": "${{ env.TELEGRAM_ERROR_CHAT_ID }}", "text": "[github CI] build [failed](https://github.com/sysblok/sysblokbot/actions/runs/${{github.run_id}})" \
}' \
https://api.telegram.org/bot${{env.TELEGRAM_TEST_TOKEN}}/sendMessage
- name: Deploy package to digitalocean
uses: appleboy/ssh-action@master
env:
GITHUB_USERNAME: sysblok
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
IMAGE_NAME: ${{ env.IMAGE_NAME }}
ROOT_DIR: /home/${{ secrets.MASTER_DO_USER }}/testing
TELEGRAM_TEST_TOKEN: ${{ secrets.TELEGRAM_TEST_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
UPTRACE_DSN: ${{ secrets.UPTRACE_DSN }}
CONFIG: ${{ secrets.CONFIG }}
CONFIG_GS: ${{ secrets.CONFIG_GS }}
with:
host: ${{ secrets.MASTER_HOST }}
username: ${{ secrets.MASTER_DO_USER }}
passphrase: ${{ secrets.MASTER_DO_SSH_KEY_PASSWORD }}
key: ${{ secrets.MASTER_DO_SSH_KEY }}
port: ${{ secrets.MASTER_PORT }}
envs: GITHUB_USERNAME, GITHUB_TOKEN, IMAGE_NAME, ROOT_DIR, TELEGRAM_TEST_TOKEN, TELEGRAM_ERROR_CHAT_ID, UPTRACE_DSN, CONFIG, CONFIG_GS
script: |
export CONTAINER_ID=$(docker ps -aq --filter name=testing)
export IMAGE_ID=$(docker images -aq --filter reference='docker.pkg.github.com/sysblok/sysblokbot/sysblokbot:testing')
docker stop --time=30 $CONTAINER_ID
docker rm $CONTAINER_ID
docker rmi $IMAGE_ID
docker login docker.pkg.github.com -u $GITHUB_USERNAME -p $GITHUB_TOKEN
touch ${{ env.ROOT_DIR }}/sysblokbot.sqlite
touch ${{ env.ROOT_DIR }}/strings.sqlite
touch ${{ env.ROOT_DIR }}/board_credentials.json
touch ${{ env.ROOT_DIR }}/config_override.json
touch ${{ env.ROOT_DIR }}/config_gs.json
echo ${{ env.CONFIG }} > ${{ env.ROOT_DIR }}/config_override.json
echo ${{ env.CONFIG_GS }} > ${{ env.ROOT_DIR }}/config_gs.json
docker run -dit --name sysblokbot-testing \
--env APP_SOURCE="testing" --restart unless-stopped \
--env TELEGRAM_ERROR_CHAT_ID="${{ env.TELEGRAM_ERROR_CHAT_ID }}" \
--env UPTRACE_DSN="${{ env.UPTRACE_DSN }}" \
--env TELEGRAM_TOKEN="${{ env.TELEGRAM_TEST_TOKEN }}" \
-v ${{ env.ROOT_DIR }}/config_override.json:/app/config_override.json \
-v ${{ env.ROOT_DIR }}/config_gs.json:/app/config_gs.json \
-v ${{ env.ROOT_DIR }}/sysblokbot.sqlite:/app/sysblokbot.sqlite \
-v ${{ env.ROOT_DIR }}/strings.sqlite:/app/strings.sqlite \
-v ${{ env.ROOT_DIR }}/persistent_storage.pickle:/app/persistent_storage.pickle \
-v ${{ env.ROOT_DIR }}/board_credentials.json:/app/board_credentials.json \
docker.pkg.github.com/sysblok/sysblokbot/${{ env.IMAGE_NAME }}:testing
- name: Notify us about failure
if: ${{ failure() }}
env:
TELEGRAM_TEST_TOKEN: ${{ secrets.TELEGRAM_TEST_TOKEN }}
TELEGRAM_ERROR_CHAT_ID: ${{ secrets.TELEGRAM_ERROR_CHAT_ID }}
run: |
curl -X POST \
-H 'Content-Type: application/json' \
-d '{"parse_mode": "markdown", "chat_id": "${{ env.TELEGRAM_ERROR_CHAT_ID }}", "text": "[github CI] deploy [failed](https://github.com/sysblok/sysblokbot/actions/runs/${{github.run_id}})" \
}' \
https://api.telegram.org/bot${{env.TELEGRAM_TEST_TOKEN}}/sendMessage
# integration_tests:
# needs: push
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# with:
# ref: dev
# - name: Integration tests
# uses: fylein/python-pytest-github-action@v2
# env:
# CONFIG_OVERRIDE: ${{ secrets.CONFIG_OVERRIDE_TESTING }}
# with:
# args: |
# apt-get update && apt-get install -y git && \
# pip3 install -e . && pip3 install -r requirements.txt && \
# pytest tests/integration -vs