Skip to content

chore(deps): bump the actions-update group with 1 update (#377) #922

chore(deps): bump the actions-update group with 1 update (#377)

chore(deps): bump the actions-update group with 1 update (#377) #922

Workflow file for this run

name: CI
on:
push:
branches:
- "master"
pull_request:
release:
types: [published]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
name: Test
runs-on: ubuntu-latest
outputs:
environment: ${{ steps.setVersion.outputs.environment }}
version: ${{ steps.setVersion.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set timezone
run: sudo timedatectl set-timezone 'Asia/Shanghai'
- name: Set up Python
uses: he0119/setup-python@main
with:
python-version: "3.11"
- name: Install prerequisites
run: |
poetry config installer.modern-installation false
poetry install
- name: Run tests
run: poetry run pytest --cov=src --cov-report xml -n auto
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
- name: Set build version
id: setVersion
run: |
VERSION=$(poetry version -s)
COMMIT_ID=$(git rev-parse --short HEAD)
if [[ "${{github.event_name}}" == "release" && "${{github.event.action}}" == "published" ]]; then
echo "environment=prod" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
else
echo "environment=dev" >> $GITHUB_OUTPUT
echo "version=$VERSION-git.$COMMIT_ID" >> $GITHUB_OUTPUT
fi
docker:
name: Docker
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set version
run: sed -ri "s#SENTRY_RELEASE=version#SENTRY_RELEASE=$VERSION#g" Dockerfile
env:
VERSION: ${{ needs.test.outputs.version }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: he0119/coolqbot
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy_dev:
name: Deploy Dev
runs-on: ubuntu-latest
environment: dev
needs: docker
if: ${{ github.event_name != 'pull_request' }}
steps:
- name: Tailscale
uses: tailscale/github-action@4e4c49acaa9818630ce0bd7a564372c17e33fb4d
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:ci
- name: Deploy to server
run: tailscale ssh ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} "${{ secrets.COOLQBOT_ROOT }}/deploy.sh"
deploy_prod:
name: Deploy Prod
runs-on: ubuntu-latest
environment: prod
needs: docker
if: ${{ github.event_name == 'release' && github.event.action == 'published' }}
steps:
- name: Deploy to server
uses: appleboy/ssh-action@55dabf81b49d4120609345970c91507e2d734799
with:
host: ${{ secrets.SSH_HOST }}
port: ${{ secrets.SSH_PORT }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script_stop: true
script: sudo ${{ secrets.COOLQBOT_ROOT }}/deploy.sh
sentry_release:
name: Sentry Release
runs-on: ubuntu-latest
needs: [test, docker]
if: github.event_name != 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create Sentry release
uses: getsentry/action-release@v1
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
with:
environment: ${{ needs.test.outputs.environment }}
version: ${{ needs.test.outputs.version }}