Skip to content

Commit

Permalink
Update CI CD
Browse files Browse the repository at this point in the history
  • Loading branch information
anstadnik committed Sep 19, 2023
1 parent 4860622 commit 48065a3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 65 deletions.
80 changes: 22 additions & 58 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,84 +9,48 @@ on:
- "main"

jobs:
build_and_test_bot:
if: github.event.pull_request.merged == true
runs-on: ubuntu-20.04
environment: ${{ github.event.pull_request.base.ref }}

steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Download the table
if: github.event.pull_request.base.ref == 'main'
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: github.event.pull_request.base.ref == 'main'
env:
SHEET_ID: ${{ secrets.SHEET_ID }}
run: cargo test --release && cargo build --release

- name: Test and build debug
if: github.event.pull_request.base.ref == 'dev'
env:
SHEET_ID: ${{ secrets.SHEET_ID }}
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.event.pull_request.base.ref == 'main'
with:
name: table
path: table.csv

deploy:
if: github.event.pull_request.merged == true
runs-on: [self-hosted]
needs: [build_and_test_bot, build_flutter_apk]
environment: ${{ github.event.pull_request.base.ref }}
runs-on: self-hosted
environment: ${{ github.base_ref }}

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

- uses: actions/download-artifact@v3
if: github.event.pull_request.base.ref == 'main'
- 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.event.pull_request.base.ref == 'main' && 'main' || 'dev' }} .
docker compose -f docker-compose_${{ github.event.pull_request.base.ref == 'main' && 'main' || 'dev' }}.yml -p ${{ github.event.pull_request.base.ref == 'main' && 'main' || 'dev' }}_bot up -d
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, build_flutter_apk]
if: github.event.pull_request.base.ref == 'main' && startsWith(github.ref, 'refs/tags/')
needs: build_and_test_bot
if: github.base_ref == 'main' && startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
- uses: dawidd6/action-download-artifact@v2
with:
pr: ${{github.event.pull_request.number}}
name: table
- uses: actions/download-artifact@v3
- uses: dawidd6/action-download-artifact@v2
with:
pr: ${{github.event.pull_request.number}}
name: executable
- uses: actions/download-artifact@v3
- uses: dawidd6/action-download-artifact@v2
with:
pr: ${{github.event.pull_request.number}}
name: apk
- name: Release
uses: softprops/action-gh-release@v1
Expand All @@ -98,20 +62,20 @@ jobs:
table.csv
first_aid_bot
notify:
runs-on: ubuntu-latest
needs: deploy
if: github.event.pull_request.base.ref == 'main'
if: github.base_ref == 'main'

steps:
- uses: actions/download-artifact@v3
- 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.event.pull_request.base.ref == 'main' && !contains(needs.*.result, 'failure')
if: always() && github.base_ref == 'main' && !contains(needs.*.result, 'failure')
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
Expand All @@ -126,7 +90,7 @@ jobs:
- name: send telegram message on push
uses: appleboy/telegram-action@master
if: always() && github.event.pull_request.base.ref == 'main' && contains(needs.*.result, 'failure')
if: always() && github.base_ref == 'main' && contains(needs.*.result, 'failure')
with:
to: ${{ secrets.TELEGRAM_TO }}
token: ${{ secrets.TELEGRAM_TOKEN }}
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ on:
- "main"

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

env:
CARGO_TERM_COLOR: always

jobs:
build_and_test_bot:
runs-on: ubuntu-20.04
environment: ${{ github.event.pull_request.base.ref }}
environment: ${{ github.base_ref }}

steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Download the table
if: github.event.pull_request.base.ref == 'main'
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

- name: Test and build release
if: github.event.pull_request.base.ref == 'main'
if: github.base_ref == 'main'
env:
SHEET_ID: ${{ secrets.SHEET_ID }}
run: cargo test --release && cargo build --release

- name: Test and build debug
if: github.event.pull_request.base.ref == 'dev'
if: github.base_ref == 'dev'
env:
SHEET_ID: ${{ secrets.SHEET_ID }}
run: cargo test && cargo build
Expand All @@ -46,7 +46,7 @@ jobs:
path: target/bot

- uses: actions/upload-artifact@v3
if: github.event.pull_request.base.ref == 'main'
if: github.base_ref == 'main'
with:
name: table
path: table.csv
Expand Down Expand Up @@ -95,7 +95,7 @@ jobs:
auto-merge:
needs: [build_and_test_bot, build_flutter_apk]
runs-on: ubuntu-latest
if: github.event.pull_request.base.ref == 'main'
if: github.base_ref == 'main'
permissions:
pull-requests: write
contents: write
Expand Down

0 comments on commit 48065a3

Please sign in to comment.