From ba432051e5226cf0e5d03b481a46d2efa3f6db91 Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 8 Nov 2026 13:34:09 +0000 Subject: [PATCH] Add .gitea/workflows/ci.yml --- .gitea/workflows/ci.yml | 141 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 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..dc49af0 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,141 @@ +name: ci + +on: + schedule: + - cron: "*/5 * * * *" + workflow_dispatch: + inputs: + branch: + description: "Force-build this mirror branch at its current head (blank = normal poll)" + required: false + default: "" + +concurrency: + group: ci-${{ github.repository }} + cancel-in-progress: false + +env: + # Change to your org and repo names + TEMPLATES_REPO: your-org/cicd-templates + TEMPLATES_REF: main # pin to a tag (e.g. v1) once stable + +jobs: + detect: + runs-on: ubuntu-latest # change to your self-hosted runner label + outputs: + matrix: ${{ steps.detect.outputs.matrix }} + count: ${{ steps.detect.outputs.count }} + steps: + - name: Checkout CI repo + uses: actions/checkout@v4 + with: + token: ${{ secrets.CI_TOKEN }} + + - name: Install deps + run: pip install --quiet pyyaml + + - name: Find new commits on mirror branches + id: detect + env: + GITEA_URL: ${{ vars.GITEA_URL || github.server_url }} + CI_TOKEN: ${{ secrets.CI_TOKEN }} + FORCE_BRANCH: ${{ inputs.branch }} + run: python3 scripts/detect.py + + - name: Commit baseline state + run: | + git config user.name "ci-bot" + git config user.email "ci-bot@localhost" + git add state 2>/dev/null || true + if ! git diff --cached --quiet; then + git commit -m "ci: baseline branch state" + git push origin HEAD:refs/heads/main + fi + + build: + needs: detect + if: needs.detect.outputs.count != '0' + runs-on: ubuntu-latest # change to your self-hosted runner label + strategy: + fail-fast: false + max-parallel: 1 + matrix: ${{ fromJSON(needs.detect.outputs.matrix) }} + env: + APP: ${{ matrix.app }} + LANGUAGE: ${{ matrix.language }} + BRANCH: ${{ matrix.branch }} + SHA: ${{ matrix.sha }} + TAG_MODE: ${{ matrix.tag }} + DEPLOY_ENV: ${{ matrix.deploy }} + REGISTRY: ${{ matrix.registry }} + SRC_DIR: ${{ github.workspace }}/src + CI_DIR: ${{ github.workspace }}/ci + TEMPLATES_DIR: ${{ github.workspace }}/templates + steps: + - name: Checkout CI repo (config and state) + uses: actions/checkout@v4 + with: + token: ${{ secrets.CI_TOKEN }} + path: ci + + - name: Checkout cicd-templates + uses: actions/checkout@v4 + with: + repository: ${{ env.TEMPLATES_REPO }} + ref: ${{ env.TEMPLATES_REF }} + token: ${{ secrets.CI_TOKEN }} + path: templates + + - name: Checkout mirrored app repo + uses: actions/checkout@v4 + with: + repository: ${{ matrix.mirror_repo }} + ref: ${{ matrix.sha }} + token: ${{ secrets.CI_TOKEN }} + fetch-depth: 0 + path: src + + - name: Test + if: matrix.script_test != '' + run: bash "templates/${{ matrix.script_test }}" + + - name: Build + if: matrix.script_build != '' + run: bash "templates/${{ matrix.script_build }}" + + - name: Build and push image + if: matrix.push_image && matrix.script_image != '' + env: + REGISTRY_USER: ${{ secrets.REGISTRY_USER }} + REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }} + run: bash "templates/${{ matrix.script_image }}" + + - name: Tag + if: matrix.tag != 'none' && matrix.script_tag != '' + env: + CI_TOKEN: ${{ secrets.CI_TOKEN }} + run: bash "templates/${{ matrix.script_tag }}" + + - name: Deploy + if: matrix.deploy != 'none' && matrix.script_deploy != '' + env: + KUBECONFIG_B64: ${{ secrets.KUBECONFIG_B64 }} + run: bash "templates/${{ matrix.script_deploy }}" + + - name: Record built SHA + # Runs even when the build failed, so a broken commit is not retried every 5 minutes. + # Re-run it with workflow_dispatch and the branch input after fixing. + if: always() + working-directory: ci + run: | + f="state/$(echo "${{ matrix.branch }}" | sed 's#/#__#g').sha" + git config user.name "ci-bot" + git config user.email "ci-bot@localhost" + mkdir -p state + for i in 1 2 3 4 5; do + echo "${{ matrix.sha }}" > "$f" + git add "$f" + git commit -m "ci: ${{ matrix.branch }} at ${{ matrix.sha }}" || break + if git pull --rebase origin main && git push origin HEAD:refs/heads/main; then break; fi + sleep 3 + done \ No newline at end of file