From acc80074eaada61370ef375fe60cb51a64ca7a5a Mon Sep 17 00:00:00 2001 From: spdis Date: Wed, 26 Nov 2025 18:00:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8[ci]=E8=A7=A6=E5=8F=91?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci.yml | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .gitea/workflows/ci.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..5078307 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,57 @@ +name: CI + +on: + push: + branches: + - Django + workflow_dispatch: + +concurrency: + group: ci-${{ github.ref }} + cancel-in-progress: true + +jobs: + docker-ci: + if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && contains(github.event.head_commit.message, '[ci]')) + runs-on: ubuntu-latest + timeout-minutes: 40 + env: + DJANGO_SECRET_KEY: ${{ secrets.DJANGO_SECRET_KEY }} + DJANGO_DEBUG: "False" + DJANGO_ALLOWED_HOSTS: "127.0.0.1,localhost" + IMAGE_NAME: achievement_inputing_ci + ES_IMAGE: docker.elastic.co/elasticsearch/elasticsearch:7.17.9 + NET_NAME: ci-net + steps: + - name: Prepare Docker network + run: | + docker network inspect "$NET_NAME" >/dev/null 2>&1 || docker network create "$NET_NAME" + - name: Start Elasticsearch + run: | + docker run -d --rm --name es --network "$NET_NAME" -p 9200:9200 \ + -e discovery.type=single-node \ + -e xpack.security.enabled=false \ + -e ES_JAVA_OPTS="-Xms512m -Xmx512m" \ + "$ES_IMAGE" + - name: Wait for Elasticsearch + run: | + for i in $(seq 1 60); do + if curl -sf http://localhost:9200 >/dev/null; then exit 0; fi + sleep 1 + done + exit 1 + - name: Build application image + run: | + docker build -t "$IMAGE_NAME" -f Dockerfile . + - name: Run checks and tests + run: | + docker run --rm --network "$NET_NAME" \ + -e DJANGO_SECRET_KEY="$DJANGO_SECRET_KEY" \ + -e DJANGO_DEBUG="$DJANGO_DEBUG" \ + -e DJANGO_ALLOWED_HOSTS="$DJANGO_ALLOWED_HOSTS" \ + -e ELASTICSEARCH_URL="http://es:9200" \ + "$IMAGE_NAME" \ + sh -lc "python manage.py migrate --noinput && python manage.py check --deploy && python -m compileall . && python manage.py collectstatic --noinput && python manage.py test" + - name: Stop Elasticsearch + run: | + docker rm -f es || true