From fd4e854e7c66377b569334522e78eb963b7cb8b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Sat, 13 Sep 2025 17:50:52 +0200 Subject: [PATCH] aa --- .gitea/workflows/build.yml | 98 +++++++++++++++++++++++++------------- 1 file changed, 64 insertions(+), 34 deletions(-) diff --git a/.gitea/workflows/build.yml b/.gitea/workflows/build.yml index 35b8eb3..c50e348 100644 --- a/.gitea/workflows/build.yml +++ b/.gitea/workflows/build.yml @@ -3,11 +3,6 @@ name: BuildApp on: workflow_dispatch: {} -# (opcjonalnie; jeśli coś krzyczy w Twojej wersji Gitei, usuń całą sekcję concurrency) -concurrency: - group: build-${{ github.ref }} - cancel-in-progress: false - jobs: build-frontend: runs-on: ubuntu-latest @@ -115,47 +110,82 @@ jobs: path: build/webapi if-no-files-found: error retention-days: 7 - - name: Diagnose mounts - run: | - set -e - mount | grep runner-cache || true - ls -la /runner-cache || true - echo "MARKER $(date -Iseconds)" | tee /runner-cache/__ok.txt - store-artifacts: + + publish-build: runs-on: ubuntu-latest needs: [build-frontend, build-backend] - if: ${{ success() }} steps: - - name: Download frontend artifacts + - uses: https://github.com/actions/checkout@v4 + + - name: Tools + run: | + set -euo pipefail + apt-get update -y + apt-get install -y jq unzip zip curl + + - name: Download frontend uses: https://github.com/actions/download-artifact@v3 with: name: frontend - path: frontend + path: ./release/frontend - - name: Download webapi artifacts + - name: Download backend uses: https://github.com/actions/download-artifact@v3 with: name: webapi - path: webapi + path: ./release/webapi - - name: Store artifacts locally on runner + - name: Zip artifacts + run: | + (cd release/frontend && zip -r ../DiunaBI-Morska-Frontend.zip .) + (cd release/webapi && zip -r ../DiunaBI-Morska-WebApi.zip .) + ls -la release + + - name: Create or update release (tag build-main-latest) + id: rel env: - BUILD_DIR: /runner-cache/builds/${{ github.run_id }} + API: "https://code.bim-it.pl/api/v1" + OWNER: "${{ github.repository_owner }}" + REPO: "${{ github.event.repository.name }}" + TOKEN: "${{ secrets.GITEATOKEN }}" run: | set -euo pipefail - mkdir -p "$BUILD_DIR" - cp -r webapi "$BUILD_DIR/" - cp -r frontend "$BUILD_DIR/" - mkdir -p /runner-cache/builds - ln -sfn "$BUILD_DIR" /runner-cache/builds/latest + TAG="build-main-latest" + # spróbuj pobrać release po tagu + if curl -sfSL -H "Authorization: token $TOKEN" "$API/repos/$OWNER/$REPO/releases/tags/$TAG" -o rel.json; then + ID=$(jq -r '.id' rel.json) + else + DATA=$(jq -n --arg tag "$TAG" --arg name "Latest build for main" \ + --arg sha "${{ github.sha }}" '{tag_name:$tag,name:$name,target_commitish:$sha,prerelease:true,draft:false}') + curl -sfSL -H "Authorization: token $TOKEN" -H "Content-Type: application/json" \ + -d "$DATA" "$API/repos/$OWNER/$REPO/releases" -o rel.json + ID=$(jq -r '.id' rel.json) + fi + echo "id=$ID" >> $GITHUB_OUTPUT - { - echo "BUILD_TIME=$(date -Iseconds)" - echo "COMMIT_SHA=${GITHUB_SHA}" - echo "BRANCH=${GITHUB_REF_NAME}" - echo "BUILD_ID=${GITHUB_RUN_ID}" - } > "$BUILD_DIR/build-info.txt" - - echo "Build artifacts stored in: $BUILD_DIR" - ls -la "$BUILD_DIR/" - echo "Symlink 'latest' -> $(readlink -f /runner-cache/builds/latest)" + - name: Upload assets + env: + API: "https://code.bim-it.pl/api/v1" + OWNER: "${{ github.repository_owner }}" + REPO: "${{ github.event.repository.name }}" + TOKEN: "${{ secrets.GITEATOKEN }}" + RID: "${{ steps.rel.outputs.id }}" + run: | + set -euo pipefail + upload () { + local file="$1" name="$2" + # usuń asset o tej nazwie jeśli istnieje (unikniemy duplikatów) + curl -sfSL -H "Authorization: token $TOKEN" "$API/repos/$OWNER/$REPO/releases/$RID/assets" -o assets.json + OLD_ID=$(jq -r --arg n "$name" '.[] | select(.name==$n) | .id' assets.json) + if [ -n "$OLD_ID" ] && [ "$OLD_ID" != "null" ]; then + curl -sfSL -X DELETE -H "Authorization: token $TOKEN" \ + "$API/repos/$OWNER/$REPO/releases/$RID/assets/$OLD_ID" >/dev/null || true + fi + # wgraj nowy plik + curl -sfSL -H "Authorization: token $TOKEN" \ + -H "Content-Type: multipart/form-data" \ + -F "attachment=@${file}" \ + "$API/repos/$OWNER/$REPO/releases/$RID/assets?name=${name}" >/dev/null + } + upload "release/DiunaBI-Morska-Frontend.zip" "DiunaBI-Morska-Frontend.zip" + upload "release/DiunaBI-Morska-WebApi.zip" "DiunaBI-Morska-WebApi.zip" \ No newline at end of file