From 694b68cbc5f7c84c934f82abe8ee2feff567bb81 Mon Sep 17 00:00:00 2001 From: Ksan Date: Thu, 11 Jun 2026 15:11:09 +0200 Subject: [PATCH] updated ci/cd to add releases and testing claude code on my project --- .gitea/workflows/ci.yaml | 90 ++++++++++++++++++++++++++ frontend/scripts/set-mobile-version.js | 28 ++++++++ 2 files changed, 118 insertions(+) create mode 100644 frontend/scripts/set-mobile-version.js diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 370d75c..263055a 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -82,3 +82,93 @@ jobs: ssh -i ~/.ssh/key \ "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \ "cd ~/programs/etf-oglasi-server && docker compose pull && docker compose up -d" + + mobile-release: + name: Mobile Release + needs: backend-unit-tests + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + defaults: + run: + working-directory: frontend + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Set up JDK ${{ env.JAVA_VERSION }} + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: ${{ env.JAVA_VERSION }} + + - name: Set up Android SDK + uses: android-actions/setup-android@v3 + + - name: Accept Android SDK licenses + run: yes | sdkmanager --licenses > /dev/null || true + + - name: Determine next mobile version + id: version + run: | + git fetch --tags + LAST=$(git tag -l 'mobile-v*' | sed 's/mobile-v//' | sort -n | tail -1) + NEXT=$(( ${LAST:-0} + 1 )) + echo "next=$NEXT" >> "$GITHUB_OUTPUT" + echo "tag=mobile-v$NEXT" >> "$GITHUB_OUTPUT" + + - name: Stamp app version + run: node scripts/set-mobile-version.js ${{ steps.version.outputs.next }} + + - name: Restore Firebase config + run: echo "${{ secrets.GOOGLE_SERVICES_JSON_BASE64 }}" | base64 -d > google-services.json + + - name: Restore env + run: echo "EXPO_PUBLIC_API_URL=${{ secrets.EXPO_PUBLIC_API_URL }}" > .env + + - name: Restore signing keystore + run: echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 -d > ksan.dev.keystore + + - name: Install dependencies + run: npm ci + + - name: Prebuild Android project + run: npx expo prebuild -p android --no-install + + - name: Build signed release APK + working-directory: frontend/android + run: | + ./gradlew assembleRelease \ + -Pandroid.injected.signing.store.file="$PWD/../ksan.dev.keystore" \ + -Pandroid.injected.signing.store.password="${{ secrets.ANDROID_KEYSTORE_PASSWORD }}" \ + -Pandroid.injected.signing.key.alias="${{ secrets.ANDROID_KEY_ALIAS }}" \ + -Pandroid.injected.signing.key.password="${{ secrets.ANDROID_KEY_PASSWORD }}" + + - name: Locate APK + id: apk + run: | + APK=$(find android/app/build/outputs/apk/release -name "*.apk" | head -n1) + OUT="etfoglasi-${{ steps.version.outputs.tag }}.apk" + cp "$APK" "$OUT" + echo "path=frontend/$OUT" >> "$GITHUB_OUTPUT" + echo "name=$OUT" >> "$GITHUB_OUTPUT" + + - name: Create Gitea release + run: | + RELEASE_ID=$(curl -sf -X POST \ + -H "Authorization: token ${{ secrets.GITEARELEASE_TOKEN }}" \ + -H "Content-Type: application/json" \ + -d "{\"tag_name\":\"${{ steps.version.outputs.tag }}\",\"target_commitish\":\"${{ github.sha }}\",\"name\":\"${{ steps.version.outputs.tag }}\",\"draft\":false,\"prerelease\":false}" \ + "https://git.${{ secrets.DOMAIN }}/api/v1/repos/${{ secrets.REGISTRY_USER }}/etf-oglasi/releases" \ + | node -pe "JSON.parse(require('fs').readFileSync(0,'utf8')).id") + + curl -sf -X POST \ + -H "Authorization: token ${{ secrets.GITEARELEASE_TOKEN }}" \ + -F "attachment=@${{ steps.apk.outputs.path }}" \ + "https://git.${{ secrets.DOMAIN }}/api/v1/repos/${{ secrets.REGISTRY_USER }}/etf-oglasi/releases/$RELEASE_ID/assets?name=${{ steps.apk.outputs.name }}" diff --git a/frontend/scripts/set-mobile-version.js b/frontend/scripts/set-mobile-version.js new file mode 100644 index 0000000..e0528fe --- /dev/null +++ b/frontend/scripts/set-mobile-version.js @@ -0,0 +1,28 @@ +// Used by CI to stamp a mobile release build with its version number. +// Updates version.json (read by hooks/useUpdatecheck.tsx) and app.json's +// android.versionCode/versionName so the build, the in-app update check, +// and the Gitea release tag (mobile-vN) all agree on the same number. +const fs = require('fs'); +const path = require('path'); + +const version = parseInt(process.argv[2], 10); +if (!Number.isInteger(version) || version <= 0) { + console.error('Usage: node set-mobile-version.js '); + process.exit(1); +} + +const root = path.join(__dirname, '..'); + +fs.writeFileSync( + path.join(root, 'version.json'), + JSON.stringify({ version }, null, 2) + '\n', +); + +const appJsonPath = path.join(root, 'app.json'); +const appJson = JSON.parse(fs.readFileSync(appJsonPath, 'utf8')); +appJson.expo.version = `1.0.${version}`; +appJson.expo.android = appJson.expo.android ?? {}; +appJson.expo.android.versionCode = version; +fs.writeFileSync(appJsonPath, JSON.stringify(appJson, null, 2) + '\n'); + +console.log(`Stamped mobile version ${version}`);