Skip to content

chore: Sửa lại thời gian build #8

chore: Sửa lại thời gian build

chore: Sửa lại thời gian build #8

Workflow file for this run

name: Android CI
on:
push:
branches:
- main
- 'feature/*'
- 'develop/*'
pull_request:
branches:
- main
- 'feature/*'
- 'develop/*'
jobs:
check_conflict:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Check for Conflicts
run: |
git fetch origin main
MERGE_BASE=$(git merge-base HEAD origin/main)
git merge-tree $MERGE_BASE HEAD origin/main > merge_output.txt
if grep -q "<<<<<<<" merge_output.txt; then
echo "Code conflicts detected. Please resolve them before merging."
echo "::warning file=merge_output.txt::Conflicts found in the following files:"
grep -l "<<<<<<<" merge_output.txt
exit 1
fi
- name: Notify about Conflicts
if: failure()
uses: actions/github-script@v6
with:
github-token: ${{ secrets.APP_TOKEN }}
script: |
const fs = require('fs');
const conflictFiles = fs.readFileSync('merge_output.txt', 'utf-8')
.split('\n')
.filter(line => line.includes("<<<<<<<"))
.map(line => line.split("<<<<<<<")[1].trim());
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Code conflicts detected in the following files:\n\n${conflictFiles.map(file => `- \`${file}\``).join('\n')}\n\nPlease resolve them before merging.`
})
- name: Notify about Conflicts on Telegram
if: failure()
run: |
conflict_files=$(grep -l "<<<<<<<" merge_output.txt | tr '\n' ', ' | sed 's/, $//')
MESSAGE="❗️*Code Conflicts Detected*
*Conflicting Files*:\n${conflict_files}
Please resolve these conflicts before merging."
curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
-d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
-d parse_mode="MarkdownV2" \
-d text="${MESSAGE}"
build:
runs-on: macos-latest
needs: check_conflict
strategy:
matrix:
java-version: [ 17 ]
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
cache: gradle
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-jdk-${{ matrix.java-version }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-jdk-${{ matrix.java-version }}-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Upload APK
if: success()
uses: actions/upload-artifact@v4
with:
name: app
path: app/build/outputs/**/*.apk
test:
runs-on: macos-latest
needs: build
strategy:
matrix:
java-version: [ 17 ]
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java-version }}
distribution: 'temurin'
cache: gradle
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ runner.os }}-jdk-${{ matrix.java-version }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-jdk-${{ matrix.java-version }}-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Run Unit Tests
run: ./gradlew test
deploy:
runs-on: macos-latest
needs: test
steps:
- uses: actions/checkout@v4
- name: Send Telegram Notification on Success
if: success()
run: |
ARTIFACT_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ github.run_number }}"
ACTION_LINK="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
BRANCH="${{ github.ref_name }}"
DURATION=$(echo "scale=2; ${{ github.run_duration }}/60" | bc)
MESSAGE="✅ *Build Succeeded*
*Committer*: ${{ github.actor }}
*Commit Message*: ${{ github.event.head_commit.message }}
*Branch*: $BRANCH
*Build Duration*: $DURATION minutes
*Action*: [View Action](${ACTION_LINK})"
curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
-d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
-d parse_mode="MarkdownV2" \
-d text="${MESSAGE}"
- name: Send Telegram Notification on Failure
if: failure()
run: |
MESSAGE="❌ *Build Failed*
*Committer*: ${{ github.actor }}
*Commit Message*: ${{ github.event.head_commit.message }}
*Branch*: ${{ github.ref_name }}
*Job Name*: ${{ github.job }}
*Workflow Run*: [View Details](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})"
curl -s -X POST "https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendMessage" \
-d chat_id="${{ secrets.TELEGRAM_CHAT_ID }}" \
-d parse_mode="MarkdownV2" \
-d text="${MESSAGE}"