diff --git a/.github/workflows/CD.yml b/.github/workflows/CD.yml index c00d4bc7..b6139b6e 100644 --- a/.github/workflows/CD.yml +++ b/.github/workflows/CD.yml @@ -16,6 +16,11 @@ jobs: steps: - uses: actions/checkout@v3 + + - name: Download the table + if: github.base_ref == 'main' + run: curl -L "docs.google.com/spreadsheets/d/${{ secrets.SHEET_ID }}/gviz/tq?tqx=out:csv&sheet=Ukrainian" -o table.csv + - uses: dawidd6/action-download-artifact@v2 with: pr: ${{github.event.pull_request.number}} @@ -24,12 +29,6 @@ jobs: skip_unpack: true # path: bin/bot - run: unzip executable.zip -d bin - - uses: dawidd6/action-download-artifact@v2 - if: github.base_ref == 'main' - with: - pr: ${{github.event.pull_request.number}} - workflow: CI.yml - name: table - name: Restart bot env: diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 61af4c58..7a7f17f8 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -14,91 +14,19 @@ env: jobs: build_and_test_bot: - runs-on: ubuntu-20.04 - - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable - - uses: Swatinem/rust-cache@v2 - - name: Download the table - if: github.base_ref == 'main' - # env: - # SHEET_ID: - # run: curl -L "docs.google.com/spreadsheets/d/${{ secrets['SHEET_ID_${github.base_ref}'] }}/gviz/tq?tqx=out:csv&sheet=Ukrainian" -o table.csv - run: curl -L "docs.google.com/spreadsheets/d/${{ secrets['SHEET_ID_dev'] }}/gviz/tq?tqx=out:csv&sheet=Ukrainian" -o table.csv - - # - uses: baptiste0928/cargo-install@v2 - # with: - # crate: cargo-bloat - # - run: cd bot && cargo bloat - # env: - # SHEET_ID: ${{ secrets['SHEET_ID_${github.base_ref}'] }} - - - name: Test and build release - if: github.base_ref == 'main' - env: - SHEET_ID: ${{ secrets['SHEET_ID_${github.base_ref}'] }} - run: cargo test --release && cargo build --release - - - name: Test and build debug - if: github.base_ref == 'dev' - env: - SHEET_ID: ${{ secrets['SHEET_ID_${github.base_ref}'] }} - run: cargo test && cargo build - - - name: Move binary - run: mv target/*/bot target - - - uses: actions/upload-artifact@v3 - with: - name: executable - path: target/bot - - - uses: actions/upload-artifact@v3 - if: github.base_ref == 'main' - with: - name: table - path: table.csv + uses: ./.github/workflows/build_and_test_bot.yml + with: + release: ${{ github.base_ref == 'main' }} + upload-artifact: true + secrets: + SHEET_ID: ${{ secrets.SHEET_ID }} build_flutter_apk: - runs-on: ubuntu-latest - defaults: - run: - working-directory: app - steps: - - uses: actions/checkout@v3 - - uses: extractions/setup-just@v1 - - uses: subosito/flutter-action@v2 - with: - channel: "stable" - cache: true - - uses: actions/setup-java@v3 - with: - distribution: "zulu" - java-version: "11" - cache: "gradle" - - uses: dtolnay/rust-toolchain@stable - with: - targets: aarch64-linux-android, armv7-linux-androideabi, x86_64-linux-android, i686-linux-android - - uses: Swatinem/rust-cache@v2 - - uses: baptiste0928/cargo-install@v2 - with: - crate: flutter_rust_bridge_codegen - - uses: baptiste0928/cargo-install@v2 - with: - crate: cargo-ndk - - uses: baptiste0928/cargo-install@v2 - with: - crate: cargo-expand - - run: just && flutter build apk --release - env: - SHEET_ID: ${{ secrets['SHEET_ID_${github.base_ref}'] }} - # https://github.com/actions/upload-artifact/issues/294 - - uses: actions/upload-artifact@v3 - with: - name: apk - if-no-files-found: error - path: app/build/app/outputs/flutter-apk/app-release.apk + uses: ./.github/workflows/build_flutter_apk.yml + with: + upload-artifact: true + secrets: + SHEET_ID: ${{ secrets.SHEET_ID }} # It should wait untill all checks will pass auto-merge: diff --git a/.github/workflows/build_and_test_bot.yml b/.github/workflows/build_and_test_bot.yml new file mode 100644 index 00000000..73d4213d --- /dev/null +++ b/.github/workflows/build_and_test_bot.yml @@ -0,0 +1,47 @@ +on: + workflow_call: + inputs: + release: + required: true + type: boolean + upload-artifact: + required: true + type: boolean + + secrets: + SHEET_ID: + required: true + +jobs: + build_and_test_bot: + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - uses: Swatinem/rust-cache@v2 + - name: Download the table + if: inputs.release + run: curl -L "docs.google.com/spreadsheets/d/${{ secrets.SHEET_ID }}/gviz/tq?tqx=out:csv&sheet=Ukrainian" -o table.csv + + - name: Test and build release + if: inputs.release + env: + SHEET_ID: ${{ env.SHEET_ID }} + run: cargo test --release && cargo build --release + + - name: Test and build debug + if: ${{ !inputs.release }} + env: + SHEET_ID: ${{ env.SHEET_ID }} + run: cargo test && cargo build + + - name: Move binary + if: inputs.upload-artifact + run: mv target/*/bot target + + - uses: actions/upload-artifact@v3 + if: inputs.upload-artifact + with: + name: executable + path: target/bot diff --git a/.github/workflows/build_flutter_apk.yml b/.github/workflows/build_flutter_apk.yml new file mode 100644 index 00000000..c5d05872 --- /dev/null +++ b/.github/workflows/build_flutter_apk.yml @@ -0,0 +1,54 @@ +on: + workflow_call: + inputs: + # release: + # required: true + # type: boolean + upload-artifact: + required: true + type: boolean + + secrets: + SHEET_ID: + required: true + +jobs: + build_flutter_apk: + runs-on: ubuntu-latest + defaults: + run: + working-directory: app + steps: + - uses: actions/checkout@v3 + - uses: extractions/setup-just@v1 + - uses: subosito/flutter-action@v2 + with: + channel: "stable" + cache: true + - uses: actions/setup-java@v3 + with: + distribution: "zulu" + java-version: "11" + cache: "gradle" + - uses: dtolnay/rust-toolchain@stable + with: + targets: aarch64-linux-android, armv7-linux-androideabi, x86_64-linux-android, i686-linux-android + - uses: Swatinem/rust-cache@v2 + - uses: baptiste0928/cargo-install@v2 + with: + crate: flutter_rust_bridge_codegen + - uses: baptiste0928/cargo-install@v2 + with: + crate: cargo-ndk + - uses: baptiste0928/cargo-install@v2 + with: + crate: cargo-expand + - run: just && flutter build apk --release + env: + SHEET_ID: ${{ secrets.SHEET_ID }} + - uses: actions/upload-artifact@v3 + if: inputs.upload-artifact + with: + name: apk + if-no-files-found: error + path: app/build/app/outputs/flutter-apk/app-release.apk