chore: Sửa lỗi dòng #18
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
push: | |
branches: | |
- main | |
- 'feature/*' | |
- 'develop/*' | |
paths: | |
- "**/*.kt" | |
- ".github/workflows/android_ci_cd.yml" | |
pull_request: | |
branches: | |
- main | |
- 'feature/*' | |
- 'develop/*' | |
paths: | |
- "**/*.kt" | |
- ".github/workflows/android_ci_cd.yml" | |
jobs: | |
check_conflict: | |
runs-on: ubuntu-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.` | |
}) | |
build: | |
runs-on: ubuntu-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: ubuntu-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 | |
notify: | |
runs-on: ubuntu-latest | |
needs: [ check_conflict, build, test ] | |
if: always() | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Send Telegram Notification on Success | |
if: success() | |
uses: appleboy/telegram-action@master | |
with: | |
to: ${{ secrets.TELEGRAM_CHAT_ID }} | |
token: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
format: markdown | |
message: | | |
✅ *Build Succeeded* | |
*Repository*: ${{ github.repository }} | |
*Committer*: ${{ github.actor }} | |
*Commit Message*: ${{ github.event.head_commit.message }} | |
*Branch*: ${{ github.ref_name }} | |
*Changes*: [View Changes](https://github.com/pass-with-high-score/quick_mem/commit/${{github.sha}}) | |
*Action*: [View Action](https://github.com/pass-with-high-score/quick_mem/runs/${{ github.run_id }}) | |
- name: Send Telegram Notification on Failure | |
if: failure() | |
uses: appleboy/telegram-action@master | |
with: | |
to: ${{ secrets.TELEGRAM_CHAT_ID }} | |
token: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
format: markdown | |
message: | | |
❌ *Build Failed* | |
*Repository*: ${{ github.repository }} | |
*Committer*: ${{ github.actor }} | |
*Commit Message*: ${{ github.event.head_commit.message }} | |
*Branch*: ${{ github.ref_name }} | |
*Changes*: [View Changes](https://github.com/pass-with-high-score/quick_mem/commit/${{github.sha}}) | |
*Job Name*: ${{ github.job }} | |
*Workflow Run*: [View Details](https://github.com/pass-with-high-score/quick_mem/actions/runs/${{ github.run_id }}) |