|
1 | | -name: GitHub Actions Demo |
2 | | -run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 |
3 | | -on: [push] |
| 1 | +name: C++ CI |
| 2 | + |
| 3 | +on: [push, pull_request] |
| 4 | + |
4 | 5 | jobs: |
5 | | - Explore-GitHub-Actions: |
| 6 | + build: |
6 | 7 | runs-on: ubuntu-latest |
| 8 | + |
7 | 9 | steps: |
8 | | - # Langkah 1: Menampilkan beberapa informasi |
9 | | - - run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event." |
10 | | - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!" |
11 | | - - run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}." |
12 | | - |
13 | | - # Langkah 2: Checkout repository code |
14 | | - - name: Check out repository code |
15 | | - uses: actions/checkout@v4 |
16 | | - - run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner." |
17 | | - |
18 | | - # Langkah 3: Menampilkan daftar file di repository |
19 | | - - run: echo "🖥️ The workflow is now ready to test your code on the runner." |
20 | | - - name: List files in the repository |
21 | | - run: | |
22 | | - ls ${{ github.workspace }} |
23 | | - |
24 | | - # Langkah 4: Temukan dan Kompilasi Semua File C++ dengan main() |
25 | | - - name: Compile and run C++ Code |
26 | | - run: | |
27 | | - # Temukan semua file .cpp yang diubah |
28 | | - files=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '\.cpp$') |
29 | | - for file in $files; do |
30 | | - # Jika file mengandung main(), kompilasi dan jalankan |
31 | | - if grep -q 'int main' "$file"; then |
32 | | - echo "🎯 Compiling and running $file" |
33 | | - g++ -o program "$file" |
34 | | - ./program |
35 | | - fi |
36 | | - done |
37 | | - |
38 | | - # Langkah 5: Status pekerjaan |
39 | | - - run: echo "🍏 This job's status is ${{ job.status }}." |
| 10 | + - name: Checkout repository |
| 11 | + uses: actions/checkout@v2 |
| 12 | + |
| 13 | + - name: Set up C++ Compiler |
| 14 | + run: sudo apt-get install g++ |
| 15 | + |
| 16 | + - name: Compile Code |
| 17 | + run: g++ -o program $(find . -name "*.cpp") |
| 18 | + |
| 19 | + - name: Run Tests |
| 20 | + run: ./program |
0 commit comments