mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-25 11:03:55 +01:00
ci(release): stage Hash Bags desktop builds from one tag
This commit is contained in:
committed by
John Winter Murphy
parent
13a2908e8a
commit
9bb2a519ac
@@ -1,13 +1,9 @@
|
||||
name: Hash Bags Android build
|
||||
|
||||
# Triggers:
|
||||
# - push to dev/main (validate every commit)
|
||||
# - PRs targeting dev/main (gate merges)
|
||||
# - manual via workflow_dispatch
|
||||
on:
|
||||
# Manual-only for now. Trigger via Actions → "Hash Bags Android build"
|
||||
# → Run workflow when you want a build. workflow_dispatch runs as the
|
||||
# triggering user, so secrets are always available (unlike PR triggers).
|
||||
push:
|
||||
tags:
|
||||
- 'hash-bags-*-build*'
|
||||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
@@ -20,6 +16,8 @@ defaults:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
# Manual builds stay available. Signed tag builds require separate activation.
|
||||
if: github.event_name == 'workflow_dispatch' || vars.HASH_BAGS_ANDROID_RELEASE_TAGS == 'true'
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
# Same Cake-Labs prebuilt image used for Linux. Bundles Flutter 3.41.9,
|
||||
@@ -44,6 +42,24 @@ jobs:
|
||||
git config --global user.email "ci@suchsoftware.com"
|
||||
git config --global user.name "Hash Bags CI"
|
||||
|
||||
- name: Verify the canonical release tag
|
||||
if: github.event_name == 'push'
|
||||
run: |
|
||||
set -euo pipefail
|
||||
version=$(awk '/^version:/ {print $2; exit}' pubspec_description.yaml)
|
||||
expected_ref="refs/tags/hash-bags-${version%%+*}-build${version#*+}"
|
||||
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+\+[1-9][0-9]*$ ||
|
||||
"$GITHUB_REF" != "$expected_ref" ]]; then
|
||||
echo "The Android release tag must match the committed version and build number." >&2
|
||||
exit 1
|
||||
fi
|
||||
tags=$(git ls-remote https://github.com/Such-Software/hash-wallet.git "$expected_ref" "${expected_ref}^{}")
|
||||
canonical=$(awk -v ref="$expected_ref" '$2==ref { direct=$1 } $2==ref "^{}" { peeled=$1 } END { print peeled ? peeled : direct }' <<< "$tags")
|
||||
if [[ "$canonical" != "$GITHUB_SHA" ]]; then
|
||||
echo "The canonical GitHub tag does not point to the Android build commit." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ---- External prebuilt deps (same approach as Linux workflow) --------
|
||||
- name: Fetch prebuilt torch_dart
|
||||
run: |
|
||||
|
||||
@@ -322,16 +322,16 @@ jobs:
|
||||
# that did not happen. Release assets are the path that actually returns
|
||||
# bytes, and GitHub is where users are told to look.
|
||||
#
|
||||
# Both steps skip quietly without a token, so a fork or a local runner
|
||||
# does not fail a build over a credential it was never given.
|
||||
- name: Resolve the release tag
|
||||
id: reltag
|
||||
env:
|
||||
REQUESTED_RELEASE_TAG: ${{ github.event.inputs.release_tag }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ "${GITHUB_REF:-}" != "${GITHUB_REF#refs/tags/}" ]; then
|
||||
TAG="${GITHUB_REF#refs/tags/}"
|
||||
else
|
||||
TAG="${{ github.event.inputs.release_tag }}"
|
||||
TAG="$REQUESTED_RELEASE_TAG"
|
||||
fi
|
||||
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
||||
if [ -n "$TAG" ]; then echo "publishing to $TAG"; else echo "no tag; build only"; fi
|
||||
@@ -341,37 +341,4 @@ jobs:
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
|
||||
TAG: ${{ steps.reltag.outputs.tag }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "${GH_TOKEN:-}" ]; then
|
||||
echo "GH_RELEASE_TOKEN not set; skipping the GitHub upload"
|
||||
exit 0
|
||||
fi
|
||||
REPO="Such-Software/hash-wallet"
|
||||
API="https://api.github.com/repos/$REPO"
|
||||
AUTH="Authorization: Bearer $GH_TOKEN"
|
||||
FILE="build/linux/x64/release/Hash_Bags-x86_64.AppImage"
|
||||
[ -f "$FILE" ] || { echo "no AppImage to upload"; exit 1; }
|
||||
NAME="$(basename "$FILE")"
|
||||
code=$(curl -sS -o rel-gh.json -w '%{http_code}' -H "$AUTH" "$API/releases/tags/$TAG" || true)
|
||||
if [ "$code" != "200" ]; then
|
||||
echo "no GitHub release for $TAG (HTTP $code); skipping"
|
||||
exit 0
|
||||
fi
|
||||
# Fail rather than skip if there is no JSON parser. An upload that
|
||||
# quietly did not happen leaves a release page that looks finished
|
||||
# and a user with nothing to download.
|
||||
PY=""
|
||||
for c in python3 python; do command -v "$c" >/dev/null && { PY="$c"; break; }; done
|
||||
[ -n "$PY" ] || { echo "no python available to parse the release JSON"; exit 1; }
|
||||
ID=$($PY -c 'import json;print(json.load(open("rel-gh.json"))["id"])')
|
||||
# Replace a same-named asset from an earlier attempt, so a re-run does
|
||||
# not leave two that differ only by which build produced them.
|
||||
for oid in $($PY -c 'import json,sys;d=json.load(open("rel-gh.json"));print(" ".join(str(a["id"]) for a in d.get("assets",[]) if a["name"]==sys.argv[1]))' "$NAME"); do
|
||||
curl -sS -o /dev/null -X DELETE -H "$AUTH" "$API/releases/assets/$oid" || true
|
||||
done
|
||||
curl -sS --fail-with-body -o /dev/null -X POST -H "$AUTH" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary "@$FILE" \
|
||||
"https://uploads.github.com/repos/$REPO/releases/$ID/assets?name=$NAME"
|
||||
echo "uploaded $NAME to the GitHub release $TAG"
|
||||
run: python3 scripts/release/publish-desktop-asset.py "$TAG" "build/linux/x64/release/Hash_Bags-x86_64.AppImage"
|
||||
|
||||
@@ -65,11 +65,10 @@ jobs:
|
||||
timeout-minutes: 90
|
||||
env:
|
||||
APP_MACOS_TYPE: cakewallet
|
||||
# A tag push builds both lanes and uploads; a dispatch says what it wants.
|
||||
LANES: ${{ github.event.inputs.lanes || 'both' }}
|
||||
# Gitea hands a dispatch boolean over as a real false, which `|| 'true'`
|
||||
# would turn back into true; format() keeps it as the string 'false'.
|
||||
APP_STORE_UPLOAD: ${{ github.event_name == 'workflow_dispatch' && format('{0}', github.event.inputs.app_store_upload) || 'true' }}
|
||||
# Release tags produce the direct download. The Mac App Store has its own dispatch.
|
||||
LANES: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.lanes || 'developer-id' }}
|
||||
# Gitea passes a checkbox as a boolean. format() preserves an explicit false.
|
||||
APP_STORE_UPLOAD: ${{ github.event_name == 'workflow_dispatch' && format('{0}', github.event.inputs.app_store_upload) || 'false' }}
|
||||
KEYCHAIN: ${{ github.workspace }}/../hashbags-macos.keychain-db
|
||||
LANG: en_US.UTF-8
|
||||
LC_ALL: en_US.UTF-8
|
||||
@@ -496,12 +495,14 @@ jobs:
|
||||
|
||||
- name: Resolve the release tag
|
||||
id: reltag
|
||||
env:
|
||||
REQUESTED_RELEASE_TAG: ${{ github.event.inputs.release_tag }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ "${GITHUB_REF:-}" != "${GITHUB_REF#refs/tags/}" ]; then
|
||||
TAG="${GITHUB_REF#refs/tags/}"
|
||||
else
|
||||
TAG="${{ github.event.inputs.release_tag }}"
|
||||
TAG="$REQUESTED_RELEASE_TAG"
|
||||
fi
|
||||
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
||||
if [ -n "$TAG" ]; then echo "publishing to $TAG"; else echo "no tag; build only"; fi
|
||||
@@ -513,30 +514,7 @@ jobs:
|
||||
GH_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}
|
||||
TAG: ${{ steps.reltag.outputs.tag }}
|
||||
FILE: ${{ steps.package.outputs.zip }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ -z "${GH_TOKEN:-}" ]; then
|
||||
echo "GH_RELEASE_TOKEN not set; skipping the GitHub upload"
|
||||
exit 0
|
||||
fi
|
||||
REPO="Such-Software/hash-wallet"
|
||||
API="https://api.github.com/repos/$REPO"
|
||||
AUTH="Authorization: Bearer $GH_TOKEN"
|
||||
NAME="$(basename "$FILE")"
|
||||
code=$(curl -sS -o rel-gh.json -w '%{http_code}' -H "$AUTH" "$API/releases/tags/$TAG" || true)
|
||||
if [ "$code" != "200" ]; then
|
||||
echo "no GitHub release for $TAG (HTTP $code); skipping"
|
||||
exit 0
|
||||
fi
|
||||
ID=$(python3 -c 'import json;print(json.load(open("rel-gh.json"))["id"])')
|
||||
for oid in $(python3 -c 'import json,sys;d=json.load(open("rel-gh.json"));print(" ".join(str(a["id"]) for a in d.get("assets",[]) if a["name"]==sys.argv[1]))' "$NAME"); do
|
||||
curl -sS -o /dev/null -X DELETE -H "$AUTH" "$API/releases/assets/$oid" || true
|
||||
done
|
||||
curl -sS --fail-with-body -o /dev/null -X POST -H "$AUTH" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary "@$FILE" \
|
||||
"https://uploads.github.com/repos/$REPO/releases/$ID/assets?name=$NAME"
|
||||
echo "uploaded $NAME to the GitHub release $TAG"
|
||||
run: python3 scripts/release/publish-desktop-asset.py "$TAG" "$FILE"
|
||||
|
||||
- name: Clean up the keychain, profiles and API key
|
||||
if: always()
|
||||
|
||||
@@ -627,15 +627,17 @@ jobs:
|
||||
# ---- Publish to the GitHub release ------------------------------------
|
||||
# PowerShell rather than the bash used elsewhere in this file: this step
|
||||
# parses JSON, and git-bash here has neither python nor node guaranteed,
|
||||
# while ConvertFrom-Json is native. Skips quietly without a token.
|
||||
# while ConvertFrom-Json is native.
|
||||
- name: Resolve the release tag
|
||||
id: reltag
|
||||
env:
|
||||
REQUESTED_RELEASE_TAG: ${{ github.event.inputs.release_tag }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
if [ "${GITHUB_REF:-}" != "${GITHUB_REF#refs/tags/}" ]; then
|
||||
TAG="${GITHUB_REF#refs/tags/}"
|
||||
else
|
||||
TAG="${{ github.event.inputs.release_tag }}"
|
||||
TAG="$REQUESTED_RELEASE_TAG"
|
||||
fi
|
||||
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
|
||||
if [ -n "$TAG" ]; then echo "publishing to $TAG"; else echo "no tag; build only"; fi
|
||||
@@ -648,10 +650,7 @@ jobs:
|
||||
TAG: ${{ steps.reltag.outputs.tag }}
|
||||
run: |
|
||||
$ErrorActionPreference = 'Stop'
|
||||
if (-not $env:GH_TOKEN) {
|
||||
Write-Host 'GH_RELEASE_TOKEN not set; skipping the GitHub upload'
|
||||
exit 0
|
||||
}
|
||||
if (-not $env:GH_TOKEN) { throw 'GH_RELEASE_TOKEN is missing' }
|
||||
$repo = 'Such-Software/hash-wallet'
|
||||
$api = "https://api.github.com/repos/$repo"
|
||||
$hdr = @{ Authorization = "Bearer $env:GH_TOKEN"; 'User-Agent' = 'hash-bags-ci' }
|
||||
@@ -660,18 +659,43 @@ jobs:
|
||||
# Named for the tag, not the commit: a release asset called
|
||||
# HashBags-windows-<40 hex>.zip tells a downloader nothing.
|
||||
$name = "HashBags-windows-$env:TAG.zip"
|
||||
try {
|
||||
$rel = Invoke-RestMethod -Headers $hdr -Uri "$api/releases/tags/$env:TAG"
|
||||
} catch {
|
||||
Write-Host "no GitHub release for $env:TAG; skipping"
|
||||
$page = 1
|
||||
do {
|
||||
$releases = Invoke-RestMethod -Headers $hdr -Uri "$api/releases?per_page=100&page=$page"
|
||||
$rel = $releases | Where-Object { $_.tag_name -ceq $env:TAG } | Select-Object -First 1
|
||||
$page++
|
||||
} while (-not $rel -and $releases.Count -eq 100)
|
||||
if (-not $rel) { throw "GitHub release $env:TAG does not exist" }
|
||||
|
||||
if ($env:GITHUB_EVENT_NAME -eq 'push') {
|
||||
$ref = "refs/tags/$env:TAG"
|
||||
$peeledRef = $ref + '^{}'
|
||||
$tagRefs = @(git ls-remote "https://github.com/$repo.git" $ref $peeledRef)
|
||||
if ($LASTEXITCODE -ne 0) { throw 'Could not read the GitHub release tag' }
|
||||
$tagSha = $tagRefs | Where-Object { $_.EndsWith("`t$peeledRef") } | Select-Object -First 1
|
||||
if (-not $tagSha) {
|
||||
$tagSha = $tagRefs | Where-Object { $_.EndsWith("`t$ref") } | Select-Object -First 1
|
||||
}
|
||||
if (-not $tagSha -or ($tagSha -split "`t")[0] -cne $env:GITHUB_SHA) {
|
||||
throw "GitHub tag $env:TAG does not point to the build commit"
|
||||
}
|
||||
if (-not $rel.draft) { throw 'Tag builds may only attach assets to a draft release' }
|
||||
}
|
||||
|
||||
$digest = 'sha256:' + (Get-FileHash -Algorithm SHA256 -LiteralPath $src.FullName).Hash.ToLowerInvariant()
|
||||
$asset = $rel.assets | Where-Object { $_.name -ceq $name } | Select-Object -First 1
|
||||
if ($asset) {
|
||||
if ($asset.state -ne 'uploaded' -or $asset.digest -cne $digest) {
|
||||
throw "GitHub already has a different or incomplete asset named $name"
|
||||
}
|
||||
Write-Host "$name is already uploaded with the expected digest"
|
||||
exit 0
|
||||
}
|
||||
# Replace a same-named asset from an earlier attempt, so a re-run does
|
||||
# not leave two that differ only by which build produced them.
|
||||
foreach ($a in @($rel.assets | Where-Object { $_.name -eq $name })) {
|
||||
Invoke-RestMethod -Headers $hdr -Method Delete -Uri "$api/releases/assets/$($a.id)" | Out-Null
|
||||
$encodedName = [uri]::EscapeDataString($name)
|
||||
$up = "https://uploads.github.com/repos/$repo/releases/$($rel.id)/assets?name=$encodedName"
|
||||
$uploaded = Invoke-RestMethod -Headers $hdr -Method Post -ContentType 'application/octet-stream' `
|
||||
-InFile $src.FullName -Uri $up
|
||||
if ($uploaded.state -ne 'uploaded' -or $uploaded.digest -cne $digest) {
|
||||
throw "GitHub did not confirm the expected digest for $name"
|
||||
}
|
||||
$up = "https://uploads.github.com/repos/$repo/releases/$($rel.id)/assets?name=$name"
|
||||
Invoke-RestMethod -Headers $hdr -Method Post -ContentType 'application/octet-stream' `
|
||||
-InFile $src.FullName -Uri $up | Out-Null
|
||||
Write-Host "uploaded $name to the GitHub release $env:TAG"
|
||||
|
||||
@@ -30,6 +30,9 @@ jobs:
|
||||
run: echo "HOME=/root" >> $GITHUB_ENV
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Test desktop release tooling
|
||||
run: PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s scripts/release
|
||||
with:
|
||||
fetch-depth: 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user