Files
DiunaBI/.gitea/workflows/morskaRelease.yml
Michał Zieliński e0da58fb20 release1
2025-09-13 19:58:59 +02:00

126 lines
4.9 KiB
YAML

name: ReleaseApp (auto from latest successful BuildApp)
on:
workflow_dispatch: {} # Manual trigger with ZERO inputs
jobs:
release:
runs-on: ubuntu-latest
env:
# --- Adjust to your instance/repo if needed ---
GITEA_BASE_URL: https://code.bim-it.pl
OWNER: mz
REPO: DiunaBI
WORKFLOW_NAME: BuildApp
steps:
- name: Checkout (for tagging context only)
uses: https://github.com/actions/checkout@v4
- name: Install tools
run: |
sudo apt-get update
sudo apt-get install -y jq zip
# 1) Find latest successful run of "BuildApp"
- name: Find latest successful BuildApp run
id: find_run
shell: bash
run: |
# Fetch recent runs and filter client-side
RESP="$(curl -fsSL \
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
"$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/runs?limit=50")"
echo "$RESP" | jq . >/dev/null || { echo "Invalid JSON from API"; exit 1; }
RUN_JSON="$(echo "$RESP" | jq -r \
--arg W "$WORKFLOW_NAME" '
.workflow_runs
| map(select(.status=="completed" and .conclusion=="success" and .workflow.name==$W))
| sort_by(.id) | reverse | .[0]
')"
RUN_ID="$(echo "$RUN_JSON" | jq -r '.id')"
RUN_HEAD_SHA="$(echo "$RUN_JSON" | jq -r '.head_sha')"
if [[ -z "$RUN_ID" || "$RUN_ID" == "null" ]]; then
echo "No successful '$WORKFLOW_NAME' run found." >&2
exit 1
fi
echo "run_id=$RUN_ID" >> "$GITHUB_OUTPUT"
echo "head_sha=$RUN_HEAD_SHA" >> "$GITHUB_OUTPUT"
echo "Latest successful $WORKFLOW_NAME run: $RUN_ID ($RUN_HEAD_SHA)"
# 2) List and download artifacts "frontend" and "webapi" via Gitea API
- name: List artifacts for that run
id: list_artifacts
run: |
curl -fsSL \
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
"$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/runs/${{ steps.find_run.outputs.run_id }}/artifacts" \
| tee artifacts.json
# Fail early if neither artifact is present
(jq -e '.artifacts[] | select(.name=="frontend")' artifacts.json >/dev/null) || { echo "Artifact 'frontend' not found"; exit 1; }
(jq -e '.artifacts[] | select(.name=="webapi")' artifacts.json >/dev/null) || { echo "Artifact 'webapi' not found"; exit 1; }
- name: Download 'frontend' artifact (zip -> dir)
run: |
mkdir -p artifacts/frontend
ART_ID=$(jq -r '.artifacts[] | select(.name=="frontend") | .id' artifacts.json)
curl -fsSL \
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
"$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/artifacts/$ART_ID/zip" \
-o frontend.zip
unzip -q frontend.zip -d artifacts/frontend
rm -f frontend.zip
- name: Download 'webapi' artifact (zip -> dir)
run: |
mkdir -p artifacts/webapi
ART_ID=$(jq -r '.artifacts[] | select(.name=="webapi") | .id' artifacts.json)
curl -fsSL \
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
"$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/artifacts/$ART_ID/zip" \
-o webapi.zip
unzip -q webapi.zip -d artifacts/webapi
rm -f webapi.zip
- name: Show artifact structure
run: |
echo "::group::frontend"
ls -laR artifacts/frontend || true
echo "::endgroup::"
echo "::group::webapi"
ls -laR artifacts/webapi || true
echo "::endgroup::"
# 3) Package artifacts as ZIPs for release assets
- name: Package artifacts as ZIPs
run: |
mkdir -p build
(cd artifacts/frontend && zip -rq ../../build/frontend.zip .)
(cd artifacts/webapi && zip -rq ../../build/webapi.zip .)
ls -la build
# 4) Autogenerate tag and title, then create release + upload assets
- name: Generate tag and title
id: meta
run: |
# Tag format: vYYYYMMDD-HHMM-run{RUN_ID}
TAG="v$(date -u +%Y%m%d-%H%M)-run${{ steps.find_run.outputs.run_id }}"
TITLE="Release ${TAG}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "title=$TITLE" >> "$GITHUB_OUTPUT"
- name: Create Gitea release with assets
uses: https://gitea.com/actions/release-action@main
with:
api_key: ${{ secrets.GITEA_PAT }}
tag_name: ${{ steps.meta.outputs.tag }}
name: ${{ steps.meta.outputs.title }}
body: "Automated release generated from latest successful **${{ env.WORKFLOW_NAME }}** run (`run_id=${{ steps.find_run.outputs.run_id }}`, `commit=${{ steps.find_run.outputs.head_sha }}`)."
files: |
build/frontend.zip
build/webapi.zip