Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CI #408

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Deploy

on:
pull_request:
types:
- closed
branches:
- "dev"
- "main"

jobs:
deploy:
if: github.event.pull_request.merged == true
runs-on: self-hosted
environment: ${{ github.base_ref }}

steps:
- uses: actions/checkout@v3
- uses: dawidd6/action-download-artifact@v2
with:
pr: ${{github.event.pull_request.number}}
name: executable
path: bin/bot
- uses: dawidd6/action-download-artifact@v2
if: github.base_ref == 'main'
with:
pr: ${{github.event.pull_request.number}}
name: table

- name: Restart bot
env:
TELOXIDE_TOKEN: ${{ secrets.TELOXIDE_TOKEN }}
run: |
docker build -t first_aid_bot:${{ github.base_ref == 'main' && 'main' || 'dev' }} .
docker compose -f docker-compose_${{ github.base_ref == 'main' && 'main' || 'dev' }}.yml -p ${{ github.base_ref == 'main' && 'main' || 'dev' }}_bot up -d

release:
runs-on: ubuntu-latest
needs: build_and_test_bot
if: github.base_ref == 'main' && startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- uses: dawidd6/action-download-artifact@v2
with:
pr: ${{github.event.pull_request.number}}
name: table
- uses: dawidd6/action-download-artifact@v2
with:
pr: ${{github.event.pull_request.number}}
name: executable
- uses: dawidd6/action-download-artifact@v2
with:
pr: ${{github.event.pull_request.number}}
name: apk
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
generate_release_notes: true
files: |
app-release.apk
table.csv
first_aid_bot

notify:
runs-on: ubuntu-latest
needs: deploy
if: github.base_ref == 'main'

steps:
- uses: dawidd6/action-download-artifact@v2
with:
pr: ${{github.event.pull_request.number}}
name: table

- name: send telegram message on push
uses: appleboy/telegram-action@master
if: always() && github.base_ref == 'main' && !contains(needs.*.result, 'failure')
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
document: table.csv
message: |
${{ github.actor }} created commit:
Commit message: ${{ github.event.commits[0].message }}

See changes: https://github.com/${{ github.repository }}/actions/runs/${{github.sha}}
See error: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
Successfully deployed! 🙆

- name: send telegram message on push
uses: appleboy/telegram-action@master
if: always() && github.base_ref == 'main' && contains(needs.*.result, 'failure')
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
document: table.csv
message: |
${{ github.actor }} created commit:
Commit message: ${{ github.event.commits[0].message }}

See changes: https://github.com/${{ github.repository }}/actions/runs/${{github.sha}}
See error: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
The commit fails to build or tests have failed! 💣
105 changes: 105 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Build, test

on:
pull_request:
branches:
- "dev"
- "main"

concurrency:
group: ${{ github.base_ref }}

env:
CARGO_TERM_COLOR: always

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'
run: curl -L "docs.google.com/spreadsheets/d/${{ secrets['SHEET_ID_${github.base_ref}'] }}/gviz/tq?tqx=out:csv&sheet=Ukrainian" -o table.csv

- 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

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

# It should wait untill all checks will pass
auto-merge:
needs: [build_and_test_bot, build_flutter_apk]
runs-on: ubuntu-latest
if: github.base_ref == 'main'
permissions:
pull-requests: write
contents: write
steps:
- uses: fastify/github-action-merge-dependabot@v3
with:
target: minor
github-token: "${{ secrets.GITHUB_TOKEN }}"
Loading