From 7b9eb6d0fdfcb9b3b62437f404104df8654f5981 Mon Sep 17 00:00:00 2001 From: Florian Date: Fri, 27 Nov 2026 10:01:39 +0100 Subject: [PATCH] Moved build process to one that automatically picks a local runner if available, re-enabled automatic building --- .gitea/workflows/build-local.yaml | 63 ------------------------------- .gitea/workflows/build.yaml | 36 +++++++++++++++++- 2 files changed, 35 insertions(+), 64 deletions(-) delete mode 100644 .gitea/workflows/build-local.yaml diff --git a/.gitea/workflows/build-local.yaml b/.gitea/workflows/build-local.yaml deleted file mode 100644 index 10ece77..0000000 --- a/.gitea/workflows/build-local.yaml +++ /dev/null @@ -1,63 +0,0 @@ -name: Build & Publish to GHCR via local build - -on: - workflow_dispatch: - -env: - GHCR_ORG: gansejunge - IMAGE_NAME: app-notifications-backend-pull-notifications - IMAGE_PATH: ghcr.io/gansejunge/app-notifications-backend-pull-notifications - OPS_ORG: notifier - OPS_REPO: ops-deployment - OPS_BRANCH_BASE: main - OPS_PATH: backend-pull-notifications/deployment.yaml - -jobs: - build: - runs-on: local - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Log in to GHCR - run: echo "${{ secrets.GHCR_TOKEN }}" | docker login ghcr.io -u ${{ secrets.GHCR_USERNAME }} --password-stdin - - - name: Get Latest Tag - id: get_tag - run: | - BASE64_TOKEN=$(echo "${{ secrets.GHCR_TOKEN }}" | base64) - LATEST_TAG=$(curl -s -H "Authorization: Bearer $BASE64_TOKEN" \ - https://ghcr.io/v2/${{ env.GHCR_ORG }}/${{ env.IMAGE_NAME }}/tags/list \ - | jq -r '.tags | map(select(test("^[0-9]+$"))) | map(tonumber) | max // 0') - NEXT_TAG=$((LATEST_TAG + 1)) - echo "latest=$LATEST_TAG" >> $GITHUB_OUTPUT - echo "next=$NEXT_TAG" >> $GITHUB_OUTPUT - - - name: Build and Push Docker Image - run: | - docker build \ - --build-arg COMMIT_ID=$(echo "${{ github.sha }}" | cut -c1-7) \ - -t ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} . - docker push ghcr.io/gansejunge/${{ env.IMAGE_NAME }}:${{ steps.get_tag.outputs.next }} - - - name: Clone ops-deployment repo - uses: actions/checkout@v4 - with: - repository: notifier/ops-deployment - path: ./ops-deployment - token: ${{ secrets.BOT_TOKEN }} - - - name: Update backend-pull-notificationsdeployment - working-directory: ./ops-deployment - run: | - NEW_TAG=${{ steps.get_tag.outputs.next }} - NEW_IMAGE="${{ env.IMAGE_PATH }}:$NEW_TAG" - git config user.name "automation-bot" - git config user.email "dev@gansejunge.com" - - sed -i "s|ghcr.io/$GHCR_ORG/$IMAGE_NAME:[0-9]\+|$NEW_IMAGE|g" "$OPS_PATH" - - COMMIT_URL="https://git.gansejunge.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA}" - git add $OPS_PATH - git commit -m "Update backend-pull-notifications image to version $NEW_TAG" -m "Linked build commit: $COMMIT_URL" - git push origin $OPS_BRANCH_BASE diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index 2878838..2678111 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -1,6 +1,8 @@ name: Build & Publish to GHCR on: + push: + branches: [main] workflow_dispatch: env: @@ -13,8 +15,40 @@ env: OPS_PATH: backend-pull-notifications/deployment.yaml jobs: - build: + select-runner: runs-on: ubuntu-latest + outputs: + runner: ${{ steps.pick.outputs.runner }} + steps: + - name: Check if local runner is online + id: pick + env: + API_TOKEN: ${{ secrets.GET_AVAILABLE_RUNNERS_API_TOKEN }} + API_URL: ${{ github.server_url }}/api/v1/admin/actions/runners + run: | + RUNNER="ubuntu-latest" + + RESPONSE=$(curl -fsS --max-time 15 \ + -H "Authorization: token ${API_TOKEN}" \ + "${API_URL}" || echo "") + + if [ -n "$RESPONSE" ]; then + ONLINE=$(echo "$RESPONSE" | jq '[.runners[]? + | select(.status != "offline") + | select(any(.labels[]?; .name == "local"))] | length') + if [ "${ONLINE:-0}" -gt 0 ]; then + RUNNER="local" + fi + else + echo "Runner API not reachable, falling back to ubuntu-latest" + fi + + echo "Selected runner: $RUNNER" + echo "runner=$RUNNER" >> "$GITHUB_OUTPUT" + + build: + needs: select-runner + runs-on: ${{ needs.select-runner.outputs.runner }} steps: - name: Checkout uses: actions/checkout@v4