image: node:25 default: interruptible: true timeout: 1 minute cache: key: files: - package-lock.json paths: - node_modules/ stages: - test - deploy - build - release - publish test: stage: test rules: - if: $CI_COMMIT_TAG when: never - when: always script: - npm run typecheck - npm run build - npm run test deploy-nsite: stage: deploy timeout: 10 minutes rules: - if: $CI_COMMIT_TAG when: never - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH variables: NSYTE_VERSION: "v0.24.1" script: # Build the web app - npm ci - npm run build - cp dist/index.html dist/404.html # Remove sourcemaps to stay under nsite's 65KB manifest limit - find dist -name '*.map' -delete # Download nsyte binary - curl -fsSL "https://github.com/sandwichfarm/nsyte/releases/download/${NSYTE_VERSION}/nsyte-linux" -o /usr/local/bin/nsyte - chmod +x /usr/local/bin/nsyte # Deploy to nsite via nsyte using the nbunksec credential - >- nsyte deploy ./dist -i --sec "$NSITE_NBUNKSEC" --name shakespeare --relays "wss://relay.ditto.pub,wss://relay.nsite.lol,wss://relay.dreamith.to,wss://relay.primal.net" --servers "https://blossom.primal.net,https://blossom.ditto.pub,https://blossom.dreamith.to" --fallback "/index.html" --use-fallback-relays --use-fallback-servers build-apk: stage: build image: eclipse-temurin:21-jdk timeout: 15 minutes needs: [] rules: - if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/ variables: ANDROID_SDK_ROOT: /opt/android-sdk ANDROID_HOME: /opt/android-sdk before_script: # Install system dependencies - apt-get update -qq - apt-get install -y -qq curl unzip > /dev/null # Install Node.js 22 - curl -fsSL https://deb.nodesource.com/setup_22.x | bash - - apt-get install -y -qq nodejs > /dev/null - node --version - npm --version # Install Android SDK command-line tools - mkdir -p $ANDROID_SDK_ROOT/cmdline-tools - curl -fsSL https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip -o cmdline-tools.zip - unzip -q cmdline-tools.zip -d $ANDROID_SDK_ROOT/cmdline-tools - mv $ANDROID_SDK_ROOT/cmdline-tools/cmdline-tools $ANDROID_SDK_ROOT/cmdline-tools/latest - export PATH="$ANDROID_SDK_ROOT/cmdline-tools/latest/bin:$ANDROID_SDK_ROOT/platform-tools:$PATH" # Accept licenses and install SDK components - printf 'y\ny\ny\ny\ny\ny\ny\n' | sdkmanager --licenses > /dev/null 2>&1 || true - sdkmanager --install "platforms;android-36" "build-tools;36.0.0" "platform-tools" > /dev/null # Write local.properties for Gradle - echo "sdk.dir=$ANDROID_SDK_ROOT" > android/local.properties # Decode signing keystore and migrate JKS -> PKCS12 for Gradle compatibility - echo "$ANDROID_KEYSTORE_BASE64" | base64 -d > android/app/my-upload-key.jks - keytool -importkeystore -srckeystore android/app/my-upload-key.jks -destkeystore android/app/my-upload-key.keystore -deststoretype pkcs12 -srcstorepass "$KEYSTORE_PASSWORD" -deststorepass "$KEYSTORE_PASSWORD" -srcalias upload -destalias upload -noprompt - rm android/app/my-upload-key.jks # Write key.properties from CI/CD variables - | cat > android/key.properties << EOF storePassword=$KEYSTORE_PASSWORD keyPassword=$KEY_PASSWORD keyAlias=upload storeFile=my-upload-key.keystore EOF script: # Extract semver version from git tag (e.g., v9.9.2 -> 9.9.2) - TAG="${CI_COMMIT_TAG#v}" - VERSION_NAME="${TAG}" - VERSION_CODE="${CI_PIPELINE_IID}" - echo "Building version $VERSION_NAME (code $VERSION_CODE) from tag $CI_COMMIT_TAG" # Stamp version into build.gradle - sed -i "s/versionCode [0-9]*/versionCode ${VERSION_CODE}/" android/app/build.gradle - sed -i "s/versionName \"[^\"]*\"/versionName \"${VERSION_NAME}\"/" android/app/build.gradle # Build web assets - npm ci - npx vite build -l error - cp dist/index.html dist/404.html # Sync web assets to Capacitor Android project - npx cap sync android # Build signed release APK - cd android && chmod +x gradlew && ./gradlew assembleRelease bundleRelease && cd .. # Copy APK to a predictable artifact path - mkdir -p artifacts - cp android/app/build/outputs/apk/release/app-release.apk "artifacts/Shakespeare.apk" - cp android/app/build/outputs/bundle/release/app-release.aab "artifacts/Shakespeare.aab" - ls -lh artifacts/ # Upload to Generic Packages registry for a stable public download URL - | curl --fail --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \ --upload-file "artifacts/Shakespeare.apk" \ "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/shakespeare/${CI_COMMIT_TAG}/Shakespeare-${CI_COMMIT_TAG}.apk" - | curl --fail --header "JOB-TOKEN: ${CI_JOB_TOKEN}" \ --upload-file "artifacts/Shakespeare.aab" \ "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/shakespeare/${CI_COMMIT_TAG}/Shakespeare-${CI_COMMIT_TAG}.aab" artifacts: paths: - artifacts/Shakespeare.apk - artifacts/Shakespeare.aab expire_in: 90 days cache: key: android-gradle paths: - android/.gradle/ - .gradle/ release: stage: release image: registry.gitlab.com/gitlab-org/release-cli:latest needs: - build-apk rules: - if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/ script: - echo "Creating release for $CI_COMMIT_TAG" # Extract the latest changelog section for the release description. # Reads from "## [version]" to the next "## [" or end of file. - | VERSION="${CI_COMMIT_TAG#v}" RELEASE_NOTES=$(awk "/^## \\[${VERSION}\\]/{found=1; next} /^## \\[/{if(found) exit} found{print}" CHANGELOG.md) if [ -z "$RELEASE_NOTES" ]; then RELEASE_NOTES="Shakespeare ${CI_COMMIT_TAG}" fi - echo "$RELEASE_NOTES" > release-notes.md release: tag_name: $CI_COMMIT_TAG name: $CI_COMMIT_TAG description: './release-notes.md' assets: links: - name: Shakespeare-${CI_COMMIT_TAG}.apk url: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/shakespeare/${CI_COMMIT_TAG}/Shakespeare-${CI_COMMIT_TAG}.apk link_type: package - name: Shakespeare-${CI_COMMIT_TAG}.aab url: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/shakespeare/${CI_COMMIT_TAG}/Shakespeare-${CI_COMMIT_TAG}.aab link_type: package publish-zapstore: stage: publish image: golang:1.24 needs: - build-apk rules: - if: $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/ variables: SIGN_WITH: $ZAPSTORE_BUNKER_URL RELAY_URLS: "wss://relay.zapstore.dev,wss://relay.ditto.pub" BLOSSOM_URL: "https://blossom.ditto.pub" script: - go install github.com/zapstore/zsp@latest # Restore the persistent NIP-46 client key so the bunker recognizes us across CI runs. # zsp stores client keys at ~/.config/zsp/bunker-keys/.key - BUNKER_PUBKEY=$(echo "$ZAPSTORE_BUNKER_URL" | sed 's|bunker://||;s|?.*||') - mkdir -p ~/.config/zsp/bunker-keys - echo "$ZAPSTORE_CLIENT_KEY" > ~/.config/zsp/bunker-keys/${BUNKER_PUBKEY}.key - APK_PATH="artifacts/Shakespeare.apk" - VERSION="${CI_COMMIT_TAG#v}" - sed -i "2i release_source:\ ./${APK_PATH}" zapstore.yaml - sed -i "2i version:\ ${VERSION}" zapstore.yaml - zsp publish --quiet --skip-preview zapstore.yaml