| 
 | 1 | +  name: Nightly Build  | 
 | 2 | + | 
 | 3 | +  on:  | 
 | 4 | +    schedule:  | 
 | 5 | +      # Fire every day at 7:00am UTC (Roughly before EU workday and after US workday)  | 
 | 6 | +      - cron: "0 7 * * *"  | 
 | 7 | +    push:  | 
 | 8 | +      tags:  | 
 | 9 | +        - nightly  | 
 | 10 | +    workflow_call:  | 
 | 11 | +      inputs:  | 
 | 12 | +        is_PR:  | 
 | 13 | +          default: false  | 
 | 14 | +          type: boolean  | 
 | 15 | +          description: If a Pull Request has triggered it.  | 
 | 16 | +        PR_NUMBER:  | 
 | 17 | +          required: true  | 
 | 18 | +          type: number  | 
 | 19 | +          description: The Pull Request that triggered this workflow  | 
 | 20 | +        skip_tagging_and_releases:  | 
 | 21 | +          required: false  | 
 | 22 | +          default: true  | 
 | 23 | +          type: boolean  | 
 | 24 | +          description: Skips Tagging & releases, since workflow_call isn't available for github.event_name, default is true  | 
 | 25 | +      outputs:  | 
 | 26 | +        job_result:  | 
 | 27 | +          description: "Build job result"  | 
 | 28 | +          value: ${{ jobs.build.result }}  | 
 | 29 | + | 
 | 30 | +    workflow_dispatch:  | 
 | 31 | + | 
 | 32 | +  concurrency:  | 
 | 33 | +    # Allow only one workflow per any non-`main` branch.  | 
 | 34 | +    group: ${{ github.workflow }}-${{ github.ref_name }}-${{ github.ref_name == 'main' && github.sha || 'anysha' }}-${{ inputs.is_PR && 'is_PR' || 'not_PR'}}  | 
 | 35 | +    cancel-in-progress: true  | 
 | 36 | + | 
 | 37 | +  env:  | 
 | 38 | +    STORE_FILE_PATH: /tmp/app-debug.keystore  | 
 | 39 | +    BUILD_JSON_PATH: build.json  | 
 | 40 | +    VERSION_LABEL: ${{ (inputs.is_PR && 'pr') || 'nightly' }}  | 
 | 41 | +    DISCORD_RELEASE_NOTIFIER_ENABLED: "true"  | 
 | 42 | +  jobs:  | 
 | 43 | +    build:  | 
 | 44 | +      timeout-minutes: 60  | 
 | 45 | +      runs-on: ubuntu-latest  | 
 | 46 | +      if: github.repository_owner == 'Acode-Foundation'  | 
 | 47 | +        | 
 | 48 | +      outputs:  | 
 | 49 | +         release_output_url: ${{ steps.release.outputs.url }}   | 
 | 50 | +         updated_version: ${{ steps.update-version.outputs.UPDATED_VERSION}}   | 
 | 51 | +      steps:  | 
 | 52 | +        - name: Fast Fail if secrets are missing  | 
 | 53 | +          if: ${{ env.KEYSTORE_CONTENT == '' || env.BUILD_JSON_CONTENT == '' }}  | 
 | 54 | +          env:  | 
 | 55 | +             KEYSTORE_CONTENT: ${{ secrets.KEYSTORE_CONTENT }}   | 
 | 56 | +             BUILD_JSON_CONTENT: ${{ secrets.BUILD_JSON_CONTENT }}   | 
 | 57 | +          run: |  | 
 | 58 | +            echo "::error title=Missing Secrets::KEYSTORE_CONTENT or BUILD_JSON_CONTENT secrets are missing! Aborting workflow."  | 
 | 59 | +            exit 1  | 
 | 60 | +          | 
 | 61 | +        - name: Logging & summaries  | 
 | 62 | +          run: |  | 
 | 63 | +            echo "::group::Logging"   | 
 | 64 | +            echo "🎯 github trigger event name: ${{ github.event_name }}"  | 
 | 65 | +            echo "is_PR: ${{ inputs.is_PR }} "  | 
 | 66 | +            echo "PR_NUMBER: ${{ inputs.PR_NUMBER }}"   | 
 | 67 | +            echo "env: STORE_FILE_PATH: ${{ env.STORE_FILE_PATH }}"   | 
 | 68 | +            echo "env: BUILD_JSON_PATH: ${{ env.BUILD_JSON_PATH }}"   | 
 | 69 | +            echo "env: VERSION_LABEL: ${{ env. VERSION_LABEL }}"  | 
 | 70 | +            echo "github sha: ${{ github.sha }}"   | 
 | 71 | +            echo "should not skip tags, releases: ${{ ! inputs.skip_tagging_and_releases }} "   | 
 | 72 | +            echo "::endgroup::"   | 
 | 73 | +              | 
 | 74 | +            echo "## 🚀 Build Type: ${{ env.VERSION_LABEL }}" >> $GITHUB_STEP_SUMMARY  | 
 | 75 | +            echo "is_PR: ${{ inputs.is_PR || 'NOT a PR' }}" >> $GITHUB_STEP_SUMMARY  | 
 | 76 | +            echo "PR_NUMBER: ${{ inputs.PR_NUMBER || 'not a PR' }}" >> $GITHUB_STEP_SUMMARY  | 
 | 77 | +            echo "should not skip tags, releases: ${{ ! inputs.skip_tagging_and_releases }}" >> $GITHUB_STEP_SUMMARY       | 
 | 78 | +
  | 
 | 79 | +        - name: Checkout Repository  | 
 | 80 | +          uses: actions/checkout@v4  | 
 | 81 | +          with:  | 
 | 82 | +            fetch-depth: 0 # Required for tags  | 
 | 83 | + | 
 | 84 | +        - name: Set up Java 21  | 
 | 85 | +          uses: actions/setup-java@v4  | 
 | 86 | +          with:  | 
 | 87 | +            distribution: 'temurin'  | 
 | 88 | +            java-version: '21'  | 
 | 89 | +            cache: ${{ (github.ref == 'refs/heads/main' && 'gradle') || '' }}  | 
 | 90 | + | 
 | 91 | +        - name: Set up Node.js  | 
 | 92 | +          uses: actions/setup-node@v4  | 
 | 93 | +          with:  | 
 | 94 | +            node-version: 'lts/*' # or '18.x' for latest stable  | 
 | 95 | + | 
 | 96 | +        - name: Add keystore and build.json from secrets  | 
 | 97 | +          run: |  | 
 | 98 | +            echo "${{ secrets.KEYSTORE_CONTENT }}" | base64 -d > $STORE_FILE_PATH  | 
 | 99 | +            echo "${{ secrets.BUILD_JSON_CONTENT }}" | base64 -d > $BUILD_JSON_PATH  | 
 | 100 | +            echo "Keystore and build.json added successfully."  | 
 | 101 | +
  | 
 | 102 | +        - name: Export Commit Hash & prev tag  | 
 | 103 | +          run: |  | 
 | 104 | +            echo "GIT_COMMIT=$(git rev-parse HEAD)" >> $GITHUB_ENV  | 
 | 105 | +            echo "PREV_TAG=$(git describe --tags --abbrev=0 || git rev-list --max-parents=0 HEAD)" >> $GITHUB_ENV  | 
 | 106 | +
  | 
 | 107 | +        - name: Extract versionCode and version from config.xml  | 
 | 108 | +          id: extract_version  | 
 | 109 | +          run: |  | 
 | 110 | +            if [ ! -f config.xml ]; then  | 
 | 111 | +            echo "config.xml not found!"  | 
 | 112 | +            exit 1  | 
 | 113 | +            fi  | 
 | 114 | +            VERSION_CODE=$(grep 'versionCode=' config.xml | sed -E 's/.*versionCode="([0-9]+)".*/\1/')  | 
 | 115 | +            VERSION=$(grep -oP 'version="\K[0-9.]+' config.xml)  | 
 | 116 | +            echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_OUTPUT  | 
 | 117 | +            echo "VERSION=$VERSION" >> $GITHUB_OUTPUT  | 
 | 118 | +            echo "Extracted Version Code: $VERSION_CODE"  | 
 | 119 | +            echo "Extracted Version: $VERSION"  | 
 | 120 | +
  | 
 | 121 | +        - name: Append Commit Hash to Version and Update config.xml  | 
 | 122 | +          id: update-version   | 
 | 123 | +          run: |  | 
 | 124 | +            SHORT_COMMIT_HASH=$(echo "${{ env.GIT_COMMIT }}" | cut -c 1-7)  | 
 | 125 | +            if ${{ inputs.is_PR  || false }}; then   | 
 | 126 | +              PR_NUMBER=${{ inputs.PR_NUMBER }}  | 
 | 127 | +            else  | 
 | 128 | +              PR_NUMBER=  | 
 | 129 | +            fi  | 
 | 130 | +            UPDATED_VERSION="${{ steps.extract_version.outputs.VERSION }}-${{ env.VERSION_LABEL }}.${PR_NUMBER:-$SHORT_COMMIT_HASH}"  | 
 | 131 | +            echo "Updated Version: $UPDATED_VERSION"  | 
 | 132 | +              | 
 | 133 | +            # Update config.xml with the new version  | 
 | 134 | +            sed -i "s/version=\"${{ steps.extract_version.outputs.VERSION }}\"/version=\"$UPDATED_VERSION\"/g" config.xml  | 
 | 135 | +            echo "Updated version in config.xml"  | 
 | 136 | +            # Output the updated version  | 
 | 137 | +            echo "UPDATED_VERSION=$UPDATED_VERSION" >> $GITHUB_ENV  | 
 | 138 | +            echo "UPDATED_VERSION=$UPDATED_VERSION" >> $GITHUB_OUTPUT   | 
 | 139 | +
  | 
 | 140 | +        - name: Install Node.js Packages  | 
 | 141 | +          run: npm install  | 
 | 142 | + | 
 | 143 | +        - name: Run npm setup  | 
 | 144 | +          run: npm run setup  | 
 | 145 | + | 
 | 146 | +        - name: Run npm build paid dev apk  | 
 | 147 | +          run: |  | 
 | 148 | +             npm run build paid dev apk  | 
 | 149 | +             echo "VERSION: $UPDATED_VERSION" >> $GITHUB_STEP_SUMMARY  | 
 | 150 | +
  | 
 | 151 | +        - name: Upload APK Artifact  | 
 | 152 | +          uses: actions/upload-artifact@v4  | 
 | 153 | +          with:  | 
 | 154 | +            name: app-debug-${{ env.GIT_COMMIT }}  | 
 | 155 | +            path: platforms/android/app/build/outputs/apk/debug/app-debug.apk  | 
 | 156 | + | 
 | 157 | +        - name: remove keystore and build.json  | 
 | 158 | +          run: |  | 
 | 159 | +            rm $STORE_FILE_PATH $BUILD_JSON_PATH  | 
 | 160 | +            echo "Keystore and build.json removed successfully."  | 
 | 161 | +          | 
 | 162 | +        - name: Check Nightly Tag and Force Update  | 
 | 163 | +          #if: github.event_name == 'push' && contains(github.event.ref, 'tags/nightly') == false  | 
 | 164 | +          if: ${{ ! inputs.skip_tagging_and_releases }}  | 
 | 165 | +          run: |  | 
 | 166 | +            # Check if the nightly tag exists and get the commit it points to  | 
 | 167 | +            if git show-ref --quiet refs/tags/nightly; then  | 
 | 168 | +              TAG_COMMIT=$(git rev-parse nightly)  | 
 | 169 | +            else  | 
 | 170 | +              TAG_COMMIT=""  | 
 | 171 | +            fi  | 
 | 172 | +              | 
 | 173 | +            # If the current commit is the same as the tag, skip updating the tag  | 
 | 174 | +            if [ "$TAG_COMMIT" != "${{ env.GIT_COMMIT }}" ]; then  | 
 | 175 | +              echo "releaseRequired=true" >> $GITHUB_ENV  | 
 | 176 | +              # export tag commit before updating for change logs comparing.   | 
 | 177 | +              echo "TAG_COMMIT=$TAG_COMMIT" >> $GITHUB_ENV   | 
 | 178 | +              | 
 | 179 | +              git config --global user.name 'GitHub Actions'  | 
 | 180 | +              git config --global user.email 'github-actions@github.com'  | 
 | 181 | +              git tag -f nightly  | 
 | 182 | +              git push origin nightly --force  | 
 | 183 | +            else  | 
 | 184 | +              echo "Nightly tag already points to this commit. Skipping update."  | 
 | 185 | +            fi  | 
 | 186 | +
  | 
 | 187 | +        - name: Release Nightly Version  | 
 | 188 | +#          Only run this step, if not called from another workflow. And a previous step is successful with releasedRequired=true  | 
 | 189 | +          id: release  | 
 | 190 | +          if: ${{ ! inputs.skip_tagging_and_releases && success() && env.releaseRequired == 'true' }}  | 
 | 191 | +          uses: softprops/action-gh-release@v2  | 
 | 192 | +          with:  | 
 | 193 | +            prerelease: true  | 
 | 194 | +            name: ${{ env.UPDATED_VERSION }}  | 
 | 195 | +            tag_name: ${{ env.UPDATED_VERSION }}   | 
 | 196 | +            files: |  | 
 | 197 | +              platforms/android/app/build/outputs/apk/debug/app-debug.apk  | 
 | 198 | +            body: |  | 
 | 199 | +              Automated Nightly (pre-release) Releases for Today  | 
 | 200 | +              \n\n[Compare Changes](https://github.com/${{ github.repository }}/compare/${{ env.TAG_COMMIT }}...${{ github.sha }})  | 
 | 201 | +
  | 
 | 202 | +        - name: Update Last Comment by bot (If ran in PR)  | 
 | 203 | +          if: inputs.is_PR  | 
 | 204 | +          uses: marocchino/sticky-pull-request-comment@v2  | 
 | 205 | +          with:  | 
 | 206 | +             hide_and_recreate: true  | 
 | 207 | +             hide_classify: "OUTDATED"  | 
 | 208 | +             header: on-demand-build-status  | 
 | 209 | +             message: |  | 
 | 210 | +                   Preview Release for this, has been built.  | 
 | 211 | +           | 
 | 212 | +                   [Click here to view that github actions build](https://github.com/${{ github.repository}}/actions/runs/${{ github.run_id }})  | 
 | 213 | +               | 
 | 214 | + | 
 | 215 | +    community-release-notifier:  | 
 | 216 | +      needs: build  | 
 | 217 | +#      Run only if push tags, or triggered by a schedule  | 
 | 218 | +      if: ${{ github.repository_owner == 'Acode-Foundation' && (contains(fromJSON('["push", "schedule"]'), github.event_name) || ! inputs.skip_tagging_and_releases) && needs.build.outputs.release_output_url }}  | 
 | 219 | +      uses: Acode-Foundation/acode/.github/workflows/community-release-notifier.yml@main  | 
 | 220 | +      with:  | 
 | 221 | +         tag_name: ${{ needs.build.outputs.updated_version }}  | 
 | 222 | +         url: ${{ needs.build.outputs.release_output_url }}  | 
 | 223 | +      secrets:  | 
 | 224 | +        DISCORD_WEBHOOK_RELEASE_NOTES: ${{ secrets.DISCORD_WEBHOOK_RELEASE_NOTES }}  | 
0 commit comments