client/.forgejo/workflows/deploy-dev.yml
Alois fc6d8950d4
Some checks failed
/ build-web (push) Successful in 6m28s
/ build-desktop (linux) (push) Failing after 7m9s
/ build-mobile (push) Failing after 11m37s
/ release (push) Has been skipped
(fix): builds
2026-07-04 01:50:13 +02:00

324 lines
11 KiB
YAML

on:
push:
branches:
- dev
paths-ignore:
- flake.nix
env:
NIX_CONFIG: experimental-features = nix-command flakes
jobs:
build-web:
runs-on: nixos
steps:
- name: Install node
run: nix profile add nixpkgs#nodejs_24
- name: Check out repo
uses: https://data.forgejo.org/actions/checkout@v4
- name: Install dependencies
run: nix develop .#electron --command pnpm install --frozen-lockfile
- name: Copy licenses
run: nix develop .#electron --command pnpm run copy-licenses
- name: Build packages
run: nix develop .#electron --command pnpm run build:packages
- name: Build web
run: nix develop .#electron --command pnpm run build:web
- name: Deploy
run: nix develop .#electron --command rsync -a --delete apps/web/dist/ /var/lib/www/tensamin-web-dev/
build-mobile:
runs-on: nixos
steps:
- name: Install node
run: nix profile add nixpkgs#nodejs_24
- name: Check out repo
uses: https://data.forgejo.org/actions/checkout@v4
- name: Install dependencies
run: nix develop .#tauri --command pnpm install --frozen-lockfile
- name: Copy licenses
run: nix develop .#tauri --command pnpm run copy-licenses
- name: Build packages
run: nix develop .#tauri --command pnpm run build:packages
- name: Setup Android Keystore
env:
KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
KEYSTORE_PROPERTIES: ${{ secrets.ANDROID_KEYSTORE_PROPERTIES }}
run: |
nix profile add nixpkgs#gnused
set -euo pipefail
if [ -z "$KEYSTORE_BASE64" ]; then
echo "ANDROID_KEYSTORE_BASE64 secret is missing or empty"
exit 1
fi
if [ -z "$KEYSTORE_PROPERTIES" ]; then
echo "ANDROID_KEYSTORE_PROPERTIES secret is missing or empty"
exit 1
fi
printf '%s' "$KEYSTORE_BASE64" \
| tr -d '[:space:]' \
| base64 -d > keystore.jks
printf '%s' "$KEYSTORE_PROPERTIES" \
| sed 's/\\n/\n/g' \
| tr -d '\r' \
| sed 's|^[[:space:]]*storeFile[[:space:]]*=.*|storeFile=keystore.jks|' \
> keystore.properties
grep -q '^[[:space:]]*storeFile[[:space:]]*=' keystore.properties || printf '\nstoreFile=keystore.jks\n' >> keystore.properties
if [ ! -s keystore.jks ]; then
echo "Decoded keystore.jks is missing or empty"
exit 1
fi
if [ ! -s keystore.properties ]; then
echo "Generated keystore.properties is missing or empty"
exit 1
fi
if ! grep -q '^[[:space:]]*keyAlias[[:space:]]*=' keystore.properties; then
echo "keystore.properties is missing keyAlias"
exit 1
fi
if ! grep -Eq '^[[:space:]]*(keyPassword|password)[[:space:]]*=' keystore.properties; then
echo "keystore.properties is missing keyPassword or password"
exit 1
fi
if ! grep -Eq '^[[:space:]]*(storePassword|password)[[:space:]]*=' keystore.properties; then
echo "keystore.properties is missing storePassword or password"
exit 1
fi
- name: Build mobile
run: nix develop .#tauri --command pnpm run build:mobile
- name: Upload mobile artifact
uses: https://data.forgejo.org/actions/upload-artifact@v3
with:
name: mobile-apk
path: apps/tauri/src-tauri/gen/android/app/build/outputs/apk/universal/release/app-universal-release.apk
build-desktop:
runs-on: nixos
strategy:
matrix:
target: [linux]
steps:
- name: Install node
run: nix profile add nixpkgs#nodejs_24
- name: Check out repo
uses: https://data.forgejo.org/actions/checkout@v4
- name: Install dependencies
run: nix develop .#electron --command pnpm install --frozen-lockfile
- name: Copy licenses
run: nix develop .#electron --command pnpm run copy-licenses
- name: Build packages
run: nix develop .#electron --command pnpm run build:packages
- name: Set Electron dev version
run: |
nix develop .#electron --command bash <<'EOF'
set -euo pipefail
VERSION="$(node -p "require('./package.json').version")"
SHORT_SHA="$(git rev-parse --short HEAD)"
DEV_VERSION="$VERSION-dev-$SHORT_SHA"
export DEV_VERSION
node -e '
const fs = require("fs");
const path = "apps/electron/package.json";
const pkg = JSON.parse(fs.readFileSync(path, "utf8"));
pkg.version = process.env.DEV_VERSION;
fs.writeFileSync(path, JSON.stringify(pkg, null, 2) + "\n");
'
EOF
- name: Build Electron desktop
run: |
nix develop .#electron --command bash <<'EOF'
set -euo pipefail
SEVEN_ZIP_DIR="$(mktemp -d)"
mkdir -p "$SEVEN_ZIP_DIR/bin"
ln -s "$(command -v 7za)" "$SEVEN_ZIP_DIR/bin/7za"
cd apps/electron
pnpm run package:raw -- -c.toolsets.sevenZip.url="file://$SEVEN_ZIP_DIR"
EOF
- name: Upload desktop artifacts
uses: https://data.forgejo.org/actions/upload-artifact@v3
with:
name: electron-desktop-${{ matrix.target }}
path: apps/electron/release/
release:
runs-on: nixos
needs: [build-web, build-mobile, build-desktop]
steps:
- name: Install node
run: nix profile add nixpkgs#nodejs_24
- name: Check out repo
uses: https://data.forgejo.org/actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
run: nix develop .#electron --command pnpm install --frozen-lockfile
- name: Download mobile artifact
uses: https://data.forgejo.org/actions/download-artifact@v3
with:
name: mobile-apk
path: apps/tauri/src-tauri/gen/android/app/build/outputs/apk/universal/release/
- name: Download desktop artifacts
uses: https://data.forgejo.org/actions/download-artifact@v3
with:
name: electron-desktop-linux
path: apps/electron/release/
- name: Read version and hash
id: version
run: |
nix develop .#electron --command bash <<'EOF'
set -euo pipefail
VERSION="$(node -p "require('./package.json').version")"
SHORT_SHA="$(git rev-parse --short HEAD)"
echo "version=$VERSION" >> "$FORGEJO_OUTPUT"
echo "short_sha=$SHORT_SHA" >> "$FORGEJO_OUTPUT"
echo "tag=${VERSION}-dev-${SHORT_SHA}" >> "$FORGEJO_OUTPUT"
echo "title=${VERSION}-dev-${SHORT_SHA}" >> "$FORGEJO_OUTPUT"
EOF
- name: Copy releases
env:
TENSAMIN_RELEASE_VERSION: ${{ steps.version.outputs.tag }}
TENSAMIN_RELEASE_TAG: ${{ steps.version.outputs.tag }}
run: |
nix develop .#electron --command bash <<'EOF'
set -euo pipefail
ASSET_BASE_URL="${{ forgejo.api_url }}"
ASSET_BASE_URL="${ASSET_BASE_URL%/api/v1}/${{ forgejo.repository }}/releases/download/${{ steps.version.outputs.tag }}"
FORGEJO_RELEASE_ASSET_BASE_URL="$ASSET_BASE_URL" pnpm run copy-releases
EOF
- name: Create pre-release and upload files
env:
TOKEN: ${{ forgejo.token }}
API: ${{ forgejo.api_url }}
REPO: ${{ forgejo.repository }}
SHA: ${{ forgejo.sha }}
TAG: ${{ steps.version.outputs.tag }}
TITLE: ${{ steps.version.outputs.title }}
run: |
nix develop .#electron --command bash <<'EOF'
set -eu
test -d releases
find releases -type f | grep -q .
LATEST_PROD_TAG="$(git for-each-ref refs/tags --sort=-creatordate --format='%(refname:short)' | awk '!/-/' | head -n 1 || true)"
if [ -n "$LATEST_PROD_TAG" ]; then
RAW_LOG="$(git log "$LATEST_PROD_TAG"..HEAD --pretty=format:'- %s')"
else
RAW_LOG="$(git log --pretty=format:'- %s')"
fi
export RAW_LOG LATEST_PROD_TAG API REPO TAG
BODY="$(node -e '
const raw = process.env.RAW_LOG;
const lines = raw.split("\n");
const commits = [];
for (const line of lines) {
const msg = line.replace(/^- /, "");
const parts = msg.split(/(?=\([^)]+\):)/).filter(Boolean).map(s => s.trim()).filter(s => s);
for (const part of parts) {
commits.push(part);
}
}
const priority = { "(feat):": 1, "(fix):": 2, "(qol):": 3 };
commits.sort((a, b) => {
const tagA = a.match(/^(\([^)]+\):)/)?.[1] || "";
const tagB = b.match(/^(\([^)]+\):)/)?.[1] || "";
return (priority[tagA] || 99) - (priority[tagB] || 99);
});
const log = commits.map(c => "- " + c).join("\n");
const latestTag = process.env.LATEST_PROD_TAG;
if (latestTag) {
const serverUrl = process.env.API.replace(/\/api\/v1.*/, "");
const compareUrl = serverUrl + "/" + process.env.REPO + "/compare/" + latestTag + "..." + process.env.TAG;
console.log(log + "\n\n[View changes](" + compareUrl + ")");
} else {
console.log(log);
}
')"
HTTP_STATUS=$(curl -s -w "%{http_code}" -o release_out.json -H "Authorization: token $TOKEN" "$API/repos/$REPO/releases/tags/$TAG")
if [ "$HTTP_STATUS" = "200" ]; then
echo "Release $TAG already exists."
RELEASE_ID="$(jq -r .id release_out.json)"
else
echo "Creating new pre-release for $TAG"
RELEASE_JSON="$(curl -f -sS -X POST "$API/repos/$REPO/releases" \
-H "Authorization: token $TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n \
--arg tag "$TAG" \
--arg name "$TITLE" \
--arg body "$BODY" \
--arg target "$SHA" \
'{
tag_name: $tag,
name: $name,
body: $body,
target_commitish: $target,
draft: false,
prerelease: true
}')")"
RELEASE_ID="$(echo "$RELEASE_JSON" | jq -r .id)"
fi
ASSET_BASE_URL="${API%/api/v1}/$REPO/releases/download/$TAG"
export ASSET_BASE_URL
node -e '
const fs = require("fs");
const path = "releases/electron-release-metadata.json";
const metadata = JSON.parse(fs.readFileSync(path, "utf8"));
metadata.version = process.env.TAG;
metadata.tag = process.env.TAG;
for (const artifact of metadata.artifacts || []) {
artifact.url = `${process.env.ASSET_BASE_URL}/${encodeURIComponent(artifact.name)}`;
}
fs.writeFileSync(path, `${JSON.stringify(metadata, null, 2)}\n`);
'
find releases -type f -print0 | while IFS= read -r -d '' file; do
name="$(basename "$file")"
curl -fsS -X POST "$API/repos/$REPO/releases/$RELEASE_ID/assets?name=$name" \
-H "Authorization: token $TOKEN" \
-F "attachment=@$file"
done
EOF