name: Release Workflow on: release: types: [created] workflow_dispatch: inputs: version_name: description: "Version name (e.g., 1.0.0)" required: true version_code: description: "Version code (optional)" required: false permissions: contents: write env: USE_MATERIAL_KOLOR_SUBMODULE: false VERSION_NAME: ${{ github.event.release.tag_name || github.event.inputs.version_name }} VERSION_CODE: ${{ github.event.inputs.version_code }} KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} KEYSTORE_KEY_ALIAS: ${{ secrets.KEYSTORE_KEY_ALIAS }} KEYSTORE_KEY_PASSWORD: ${{ secrets.KEYSTORE_KEY_PASSWORD }} jobs: build: strategy: matrix: target: [android, web] name: "Build ${{ matrix.target }}" runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Java uses: actions/setup-java@v4 with: java-version: 17 distribution: adopt - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - name: Gradle Wrapper Validation uses: gradle/actions/wrapper-validation@v4 - name: Build for ${{ matrix.target }} run: | if [ -n "${{ env.VERSION_CODE }}" ]; then ./scripts/build ${{ matrix.target }} ${{ env.VERSION_NAME }} --code ${{ env.VERSION_CODE }} else ./scripts/build ${{ matrix.target }} ${{ env.VERSION_NAME }} fi - name: Upload Artifacts uses: actions/upload-artifact@v4 with: name: ${{ matrix.target }} path: dist if-no-files-found: error build-desktop: strategy: matrix: os: [ubuntu, macos] name: "Build desktop-${{ matrix.os }}" runs-on: ${{ matrix.os }}-latest steps: - name: Checkout uses: actions/checkout@v4 - name: Setup Java uses: actions/setup-java@v4 with: java-version: 17 distribution: adopt - name: Setup Gradle uses: gradle/actions/setup-gradle@v4 - name: Gradle Wrapper Validation uses: gradle/actions/wrapper-validation@v4 - name: Build for ${{ matrix.os }} run: | if [ -n "${{ env.VERSION_CODE }}" ]; then ./scripts/build desktop ${{ env.VERSION_NAME }} --code ${{ env.VERSION_CODE }} else ./scripts/build desktop ${{ env.VERSION_NAME }} fi - name: Upload Artifacts uses: actions/upload-artifact@v4 with: name: desktop-${{ matrix.os }} path: dist if-no-files-found: error release: needs: [build, build-desktop] runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' steps: - name: Checkout uses: actions/checkout@v4 - name: Check if tag exists id: check_tag run: | if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then git fetch --tags if git rev-parse -q --verify "refs/tags/${{ env.VERSION_NAME }}" >/dev/null; then echo "Tag exists" echo "tag_exists=true" >> $GITHUB_OUTPUT else echo "Tag does not exist" echo "tag_exists=false" >> $GITHUB_OUTPUT fi else echo "tag_exists=true" >> $GITHUB_OUTPUT fi - name: Download Artifacts uses: actions/download-artifact@v4 with: path: ./artifacts - name: Display downloaded files run: ls -R ./artifacts - name: Skip update release if tag does not exist if: steps.check_tag.outputs.tag_exists == 'false' run: echo "Skipping update release as tag does not exist" - name: Update Release with assets if: steps.check_tag.outputs.tag_exists == 'true' uses: actions/github-script@v7 with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const fs = require('fs').promises; const path = require('path'); let release; if (context.payload.release) { // Automatic trigger from a new release release = context.payload.release; } else { // Manual trigger, find release by tag (VERSION_NAME) const { data: releaseData } = await github.rest.repos.getReleaseByTag({ owner: context.repo.owner, repo: context.repo.repo, tag: process.env.VERSION_NAME }); release = releaseData; } let uploadCount = 0; async function uploadFilesRecursively(dir) { const entries = await fs.readdir(dir, { withFileTypes: true }); for (const entry of entries) { const fullPath = path.join(dir, entry.name); if (entry.isDirectory()) { await uploadFilesRecursively(fullPath); } else { console.log(`Uploading ${entry.name} to release...`); await github.rest.repos.uploadReleaseAsset({ owner: context.repo.owner, repo: context.repo.repo, release_id: release.id, name: entry.name, data: await fs.readFile(fullPath) }); uploadCount++; } } } const artifactsPath = path.join(process.cwd(), 'artifacts'); await uploadFilesRecursively(artifactsPath); console.log(`Successfully uploaded ${uploadCount} assets to the release.`); deploy: name: "Deploy to Production" runs-on: ubuntu-latest needs: build steps: - name: Checkout uses: actions/checkout@v4 - name: Download web build artifacts uses: actions/download-artifact@v4 with: name: web path: ./dist - name: Display downloaded files run: ls -R ./dist - name: Unzip web build artifacts run: | mkdir -p app/build/dist/wasmJs/productionExecutable cp -r ./dist/* app/build/dist/wasmJs/productionExecutable/ rm -rf ./dist - name: Deploy to production uses: FirebaseExtended/action-hosting-deploy@v0 with: repoToken: ${{ secrets.GITHUB_TOKEN }} firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_MATERIALKOLOR }} channelId: live projectId: materialkolor