relase
This commit is contained in:
@@ -1,96 +1,59 @@
|
||||
name: ReleaseApp (auto from latest successful BuildApp)
|
||||
name: ReleaseApp (JS finder + download)
|
||||
|
||||
on:
|
||||
workflow_dispatch: {} # Manual trigger with ZERO inputs
|
||||
workflow_dispatch: {}
|
||||
|
||||
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
|
||||
# Comma-separated artifact names that must exist
|
||||
REQUIRED_ARTIFACTS: frontend,webapi
|
||||
# How many recent successful runs to scan
|
||||
SCAN_LIMIT: "100"
|
||||
|
||||
steps:
|
||||
- name: Checkout (for tag context only)
|
||||
- name: Checkout
|
||||
uses: https://github.com/actions/checkout@v4
|
||||
|
||||
- name: Install tools
|
||||
- name: Use Node.js 20
|
||||
uses: https://github.com/actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
|
||||
- name: Install unzip (for extraction)
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y jq zip
|
||||
sudo apt-get install -y unzip
|
||||
|
||||
# 1) Find latest successful run of "BuildApp" via REST API (/api/v1 ... /actions/tasks)
|
||||
- name: Find latest successful BuildApp run
|
||||
id: find_run
|
||||
shell: bash
|
||||
- name: Resolve latest run that exposes required artifacts
|
||||
id: resolve
|
||||
env:
|
||||
GITEA_PAT: ${{ secrets.GITEA_PAT }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
node .gitea/scripts/getLatestRunWithArtifacts.js
|
||||
echo "Resolved run_id: $(cat .gitea/.cache/run_id)"
|
||||
|
||||
# NOTE: /api/v1 is the correct REST base for Gitea.
|
||||
RESP="$(curl -fsSL \
|
||||
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
|
||||
"$GITEA_BASE_URL/api/v1/repos/$OWNER/$REPO/actions/tasks?limit=100")"
|
||||
|
||||
# Try to match by various fields (workflow.name in newer versions, fallbacks otherwise)
|
||||
RUN_JSON="$(jq -r --arg W "$WORKFLOW_NAME" '
|
||||
.workflow_runs
|
||||
| map(
|
||||
select(
|
||||
(.status=="completed") and
|
||||
(.conclusion=="success") and
|
||||
(
|
||||
(.workflow.name? // .workflow_name? // .display_title? // "") == $W
|
||||
)
|
||||
)
|
||||
)
|
||||
| sort_by(.run_number // .id)
|
||||
| reverse
|
||||
| .[0]
|
||||
' <<< "$RESP")"
|
||||
|
||||
if [[ -z "$RUN_JSON" || "$RUN_JSON" == "null" ]]; then
|
||||
echo "No successful run found for workflow name: $WORKFLOW_NAME"
|
||||
echo "Available runs (debug):"
|
||||
echo "$RESP" | jq -r '.workflow_runs[] | {id, status, conclusion, display_title, workflow_name: .workflow_name, wname: .workflow.name}'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
RUN_ID="$(jq -r '.id // .run_id' <<< "$RUN_JSON")"
|
||||
HEAD_SHA="$(jq -r '.head_sha // .head_commit?.id // empty' <<< "$RUN_JSON")"
|
||||
|
||||
echo "run_id=$RUN_ID" >> "$GITHUB_OUTPUT"
|
||||
echo "head_sha=$HEAD_SHA" >> "$GITHUB_OUTPUT"
|
||||
echo "Latest successful $WORKFLOW_NAME run: $RUN_ID ($HEAD_SHA)"
|
||||
|
||||
# 2) Download artifacts using GUI-style URLs
|
||||
# These URLs serve ZIPs directly. Authorization via token MAY or MAY NOT work depending on instance config.
|
||||
# If it fails with 302/403, consider using a community download action as a fallback.
|
||||
- name: Download 'frontend' artifact (GUI URL)
|
||||
shell: bash
|
||||
- name: Download frontend artifact
|
||||
env:
|
||||
GITEA_PAT: ${{ secrets.GITEA_PAT }}
|
||||
ARTIFACT_NAME: frontend
|
||||
RUN_ID: ${{ steps.resolve.outputs.run_id }}
|
||||
OUTPUT_DIR: artifacts/frontend
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p artifacts/frontend
|
||||
# -L to follow redirects; --fail-with-body to fail on non-2xx
|
||||
curl -LfS --fail-with-body \
|
||||
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
|
||||
"$GITEA_BASE_URL/$OWNER/$REPO/actions/runs/${{ steps.find_run.outputs.run_id }}/artifacts/frontend" \
|
||||
-o frontend.zip
|
||||
unzip -q frontend.zip -d artifacts/frontend
|
||||
rm -f frontend.zip
|
||||
node .gitea/scripts/downloadArtifactByName.js
|
||||
|
||||
- name: Download 'webapi' artifact (GUI URL)
|
||||
shell: bash
|
||||
- name: Download webapi artifact
|
||||
env:
|
||||
GITEA_PAT: ${{ secrets.GITEA_PAT }}
|
||||
ARTIFACT_NAME: webapi
|
||||
RUN_ID: ${{ steps.resolve.outputs.run_id }}
|
||||
OUTPUT_DIR: artifacts/webapi
|
||||
run: |
|
||||
set -euo pipefail
|
||||
mkdir -p artifacts/webapi
|
||||
curl -LfS --fail-with-body \
|
||||
-H "Authorization: token ${{ secrets.GITEA_PAT }}" \
|
||||
"$GITEA_BASE_URL/$OWNER/$REPO/actions/runs/${{ steps.find_run.outputs.run_id }}/artifacts/webapi" \
|
||||
-o webapi.zip
|
||||
unzip -q webapi.zip -d artifacts/webapi
|
||||
rm -f webapi.zip
|
||||
node .gitea/scripts/downloadArtifactByName.js
|
||||
|
||||
- name: Show artifact structure
|
||||
run: |
|
||||
@@ -99,32 +62,4 @@ jobs:
|
||||
echo "::endgroup::"
|
||||
echo "::group::webapi"
|
||||
ls -laR artifacts/webapi || true
|
||||
echo "::endgroup::"
|
||||
|
||||
# 3) Package artifacts as ZIPs for the 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) Auto-generate tag/title and create the release on Gitea
|
||||
- name: Generate tag and title
|
||||
id: meta
|
||||
run: |
|
||||
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 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
|
||||
echo "::endgroup::"
|
||||
Reference in New Issue
Block a user