GitHub Eylemlerini Kullanarak Robot Kodu için CI kurmak

Bir ekip ortamında çalışmanın önemli bir yönü, GitHub gibi merkezi bir depoya gönderilen kodu test edebilmektir. Örneğin, proje yöneticisi veya lider geliştirici, kodu birleştirmeden önce bir dizi birim testini çalıştırmak isteyebilir veya tüm kodun çalışır durumda olduğundan emin olmak isteyebilir.

‘GitHub Eylemleri <https://github.com/features/actions>`_ ekiplerin ve bireylerin çekme isteklerinde çeşitli dallardaki kod üzerinde birim testleri oluşturmasına ve çalıştırmasına olanak tanıyan bir hizmettir. Bu tip servisler genel olarak “Continuous Integration-Sürekli Entegrasyon” hizmetleri şeklinde bilinir. Bu öğretici yazı size GitHub Aksiyonlarını robot kodu projelerinde nasıl kurulacağını göstericektir.

Not

This tutorial assumes that your team’s robot code is being hosted on GitHub. For an introduction to Git and GitHub, please see this introduction guide.

Eylem oluşturma

CI sürecini gerçekleştirme talimatları bir YAML dosyasında depolanır. Bunu oluşturmak için, deponun sağ üstünde bulunan “Actions_Eylemler” sekmesine tıklayın. Ardından “set up a workflow yourself-kendi başınıza bir iş akışı oluşturun” bağlantısına tıklayın.

Setup a workflow yourself.

Şimdi bir metin editörü ile karşılanacaksınız. Tüm varsayılan metni aşağıdakilerle değiştirin:

# This is a basic workflow to build robot code.

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch.
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # This grabs the WPILib docker container
    container: wpilib/roborio-cross-ubuntu:2024-22.04

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - uses: actions/checkout@v4

    # Declares the repository safe and not under dubious ownership.
    - name: Add repository to git safe directories
      run: git config --global --add safe.directory $GITHUB_WORKSPACE

    # Grant execute permission for gradlew
    - name: Grant execute permission for gradlew
      run: chmod +x gradlew

    # Runs a single command using the runners shell
    - name: Compile and run tests on robot code
      run: ./gradlew build

Ardından, ekranın sağ üst köşesinde bulunan “Start commit-işlemeye başla” butonuna tıklayarak değişiklikleri kaydedin. İsterseniz varsayılan kaydetme mesajını düzenleyebilirsiniz. Sonrasında, “Commit new file-yeni dosya işle” yeşil butonuna tıklayın.

Committing a new file.

Ana bilgisayarda bir işlem gerçekleştiğinde, GitHub artık her zaman otomatik olarak çalıştıracaktır. Herhangi bir yapının durumunu izlemek için ekranın üst kısmındaki ” Actions -eylemler” sekmesine tıklayabilirsiniz.

View of the actions tab

Eylemler YAML Dosyasının Dökümü

İşte yukarıdaki YAML dosyasının bir dökümü. Her satırın tam olarak anlaşılması gerekmese de, bir miktar anlayış, daha fazla özellik eklemenize ve ortaya çıkabilecek olası sorunları gidermenize yardımcı olacaktır.

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the main branch.
on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

Bu kod bloğu, eylemin ne zaman çalışacağını belirler. Şu anda eylem, işlem yürütüldüğünde yada istendiğinde çalışacaktır.

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # This grabs the WPILib docker container
    container: wpilib/roborio-cross-ubuntu:2024-22.04

Her aksiyonun iş akışı, sıralı olarak (birbiri ardına) veya paralel (aynı anda) çalışan bir veya daha fazla işten oluşur. İş akışımızda sadece bir “yapım” işi vardır.

Şunu belirtmek isteriz ki , işin bir Ubuntu sanal makinesinde ve sanallaştırılmış bir ‘JDK, C ++ derleyici ve roboRIO araç zincirleri içeren bir Docker konteynerinde <https://www.docker.com/resources/what-container>`_ çalışmasını istiyoruz.

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4

# Declares the repository safe and not under dubious ownership.
- name: Add repository to git safe directories
  run: git config --global --add safe.directory $GITHUB_WORKSPACE

# Grant execute permission for gradlew
- name: Grant execute permission for gradlew
  run: chmod +x gradlew

# Runs a single command using the runners shell
- name: Compile and run tests on robot code
  run: ./gradlew build

Each job has certain steps that will be executed. This job has four steps. The first step involves checking out the repository to access the robot code. The second step is a workaround for a GitHub Actions issue. The third step involves giving the virtual machine permission to execute gradle tasks using ./gradlew. The final step runs ./gradlew build to compile robot code and run any unit tests.

README.md dosyasına Yapı Durum işareti ekleme

Main üzerinde en son derlemenin durumunu hızlı bir şekilde kontrol etmek için deponuzun README dosyasının üstüne bir CI durum işareti eklemek yararlıdır. Bunu yapmak için, ekranın üst kısmındaki “Actions-eylemler” sekmesine tıklayın ve ekranın sol tarafındaki “CI” sekmesini seçin. Ardından, sağ üstteki “Create status badge-durum işareti oluştur” düğmesini tıklayın ve durum işareti Markdown kodunu kopyalayın.

Where to click on "Copy status badge Markdown"

Son olarak, Kopyaladığınız Markdown kodunu README dosyanızın en üstüne yapıştırın, uygulayın ve değişikliklerinizi gönderin. Şimdi, ana depo sayfanızda GitHub Aksiyonları durum rozetini görmelisiniz.

A picture of the repository with the badge created.