Skip to content

Update CI/CD

Update CI/CD #37

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches:
# - dev.20230419 # debug
- master
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up Python 3.7
uses: actions/setup-python@v3
with:
python-version: 3.7
- name: Install pipenv
run: |
python -m pip install --upgrade pip
python -m pip install pipenv
- name: Check for file changes
id: file_check
run: |
if git diff --name-only HEAD^ | grep -q ".py$"; then
echo "::set-output name=updated::true"
else
echo "::set-output name=updated::false"
fi
- name: Install dependencies and lock
if: steps.file_check.outputs.updated == 'true'
run: |
pipenv install --dev
pipenv lock
- name: Create version file
run: |
COMMIT_ID=$(git rev-parse --short HEAD)
echo "__version__ = '$(TZ='Asia/Shanghai' date +'%Y%m%d').$COMMIT_ID'" > utils/__version__.py
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push Docker image
if: steps.file_check.outputs.updated == 'true'
uses: docker/build-push-action@v2
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: yha8897/keyword_alert_bot:latest
- name: Create release
if: steps.file_check.outputs.updated == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=$(python -c "from utils.__version__ import __version__; print(__version__)")
echo $VERSION
gh release create $VERSION