GitHub etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
GitHub etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

6 Eylül 2023 Çarşamba

GitHub Actions Workflow

Örnek
Bir repository yaratırız ve .github/workflows/create-spring-boot-repository.yaml  dosyasını yaratırız. Dosya şöyle. Dosyanın çalışması için bir personal access token yaratılır ve secret olarak kaydedilir
name: Create Spring Boot Repository

on:
  workflow_dispatch:
    inputs:
      name:
        description: 'Repository Name'
        required: true
      description:
        description: 'Repository Description'
        required: true
      private:
        description: 'Private Repository'
        required: true
        default: 'false'
      groupId:
        description: 'Maven Group ID'
        required: true
      artifactId:
        description: 'Maven Artifact ID'
        required: true
      springBootVersion:
        description: 'Spring Boot Version'
        required: true
        default: '3.0.0'
      mainClassName:
        description: 'Main Class Name'
        required: true
        default: 'Application'
      userName:
        description: 'User Name'
        required: true
      userEmail:
        description: 'User Email'
        required: true
        
jobs:
  create-spring-boot-repository:
    runs-on: ubuntu-latest

    steps:
    - name: Step 1 - Checkout code
      uses: actions/checkout@v3

    - name:  Step 2 - Generate Spring Boot Project with Maven Wrapper
      run: |
        curl https://start.spring.io/starter.zip -o project.zip \
             -d type=maven-project \
             -d bootVersion=${{ github.event.inputs.springBootVersion }} \
             -d groupId=${{ github.event.inputs.groupId }} \
             -d artifactId=${{ github.event.inputs.artifactId }} \
             -d name=${{ github.event.inputs.mainClassName }}
        unzip project.zip -d spring-boot-project
        cd spring-boot-project
        mvn wrapper:wrapper

    - name: Step 3 - Create new GitHub repository
      run: |
        curl -X POST -H "Authorization: token ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}" \
             -d '{
                  "name": "${{ github.event.inputs.name }}",
                  "description": "${{ github.event.inputs.description }}",
                  "private": ${{ github.event.inputs.private }}
                }' \
             https://api.github.com/user/repos

    - name: Step 4 - Push to new repository
      run: |
        cd spring-boot-project
        echo "# ${{  github.event.inputs.name }}" >> README.md
        git config --global user.email "${{ github.event.inputs.userEmail }}"
        git config --global user.name "${{ github.event.inputs.userName }}"
        git init
        git add .
        git add README.md
        git commit -m "first commit"
        git branch -M main
        git remote add origin git@github.com:${{ github.actor }}/${{ github.event.inputs.name }}.git
        git remote set-url origin https://x-access-token:${{ env.GH_PERSONAL_ACCESS_TOKEN }}@github.com/${{ github.actor }}/${{ github.event.inputs.name }}
        git push -u origin main  # Push to 'main' branch
      env:
        GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

Github Actions - maven

Örnek - checkout + Set up JDK + Build
GitHub'daki repository'ye gidilir. Üst başlıktaki "Actions" düğmesine tıklanır. "New workflow" düğmesine tıklanır. "Java with Maven" düğmesine tıklanır. Şeklen şöyle

Karşımıza çıkan dosya şöyle. Dosya yolu şöyle "myrepository/.github/workflows/maven.yaml"
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/ building-and-testing-java-with-maven

name: Java CI with Maven

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Set up JDK 11
      uses: actions/setup-java@v3
      with:
        java-version: '11'
        distribution: 'temurin'
        cache: maven
    - name: Build with Maven
      run: mvn -B package --file pom.xml
Örnek - checkout + Set up JDK + Build
Şöyle yaparız
name: Java CI with Maven

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up JDK 11
      uses: actions/setup-java@v2
      with:
        java-version: '11'
        distribution: 'adopt'

    - name: Build with Maven
      run: ./mvnw clean install

Örnek
Push işleminden sonra testleri çalıştırıp, Docker'a image push'lamak için şöyle yaparız
name: CI/CD Pipeline

## The following codes trigger the pipeline when the code is pushed on the main branch.
on:
  push:
    branches: [ main ]

jobs:
  ## First Job: Test
  test:
    name: Unit Test
    ## Run on Ubuntu using the Latest Version
    runs-on: ubuntu-latest
    ## Job's steps
    steps:
      - uses: actions/checkout@v1
      ## Set up JDK 11
      - name: Set up JDK
        uses: actions/setup-java@v1
        with:
          java-version: '11'
      ## Set up Maven Cache
      - name: Cache Maven packages
        uses: actions/cache@v1
        with:
          path: ~/.m2
          key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
          restore-keys: ${{ runner.os }}-m2
      ## Run Maven Tests
      - name: Run Tests
        run: mvn -B test

  ## Second Job: Build and Push
  build-and-push:
    name: Build and Push
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK 11
        uses: actions/setup-java@v3
        with:
          java-version: '11'
          distribution: 'adopt'
          cache: maven
      - name: Build with Maven
        run: mvn -B package --file pom.xml

      - name: Dockerize & Push Docker Image
        uses: mr-smithers-excellent/docker-build-push@v5
        with:
          ## Docker Hub Account Number / Repository Name
          image: 19812381238/product-microservice
          tags: latest
          registry: docker.io
          ## Dockerfile Path
          dockerfile: product/Dockerfile
          ## Keep these secrets on GitHub for the privacy of our information
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
Örnek
Github sayfasına release yapmak için şöyle yaparız
name: Java CI to create and upload release on pull request
on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

env:
  build-number: ${GITHUB_RUN_NUMBER}

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-java@v3
        with:
          java-version: '11'
          distribution: 'temurin'
          cache: 'maven'
      - run: mvn clean package -DskipTests
      - run: mkdir staging && mv target/yb-workload-sim.jar target/yb-workload-sim-${{ env.build-number }}.jar && cp target/*.jar staging
      - uses: actions/upload-artifact@v3
        with:
          name: Package
          path: staging
          retention-days: 1
      - uses: marvinpinto/action-automatic-releases@latest
        with:
          repo_token: "${{ secrets.YOUR-GITHUB-TOKEN }}"
          automatic_release_tag: "${{ github.run_number }}"
          title: "Automated Build ${{ github.run_number }}"
          prerelease: true
          files: staging/*.jar

25 Temmuz 2023 Salı

GitHub SSH Key

Giriş
1. Kendi bilgisayarımda public/private key dosyaları oluştururum. IntelliJ terminal penceresinden şöyle yaparız. Burada -C ile e-posta adresi belirtiliyor, şart değil. Ben yapmadım
ssh-keygen -t ed25519 -C "your_email@example.com"
Windows kullanıyorsak dosyalar şurada
C:\Users\acelya\.ssh
Eğer Git Bash ile 
ls -al ~/.ssh
yapsak bile yine aynı dizini gösteriyor. 

2. id_ed25519.pub dosyasındaki içindeki satırları kopyalayıp, GitHub'da https://github.com/settings/keys adresinden yeni bir SSH key oluştururum

3. .git/config dosyasında depoya erişmek için kullanılan yöntem var. 
- Eğer depo ismi git@ ile başlıyorsa SSH kullanılır
- Eğer depo ismi https  ile başlıyorsa HTTPS kullanılır


13 Eylül 2022 Salı

GitHub CI/CD

Giriş
Kavramlar şöyle
1. Workflow : YAML ile tanımlanır
2. Jobs : Workflow içinde Jobs bulunur
3. Steps : Jobs içinde Steps bulunur
4. Actions : Steps içinde Actions bulunur
5. Events : Workflow nesnesi Events ile tetiklenir

Örnek
Burada bir örnek var. jobs içinde steps var. Her step ise name + uses + with veya name + run ile tanımlı
name: CI Workflow

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    
    steps:
      - name: Checkout code
        uses: actions/checkout@v2
        
      - name: Set up Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 14
          
      - name: Install dependencies
        run: npm install
        
      - name: Build and test
        run: npm run build && npm run test

Workflow
Bir workflow seçilir. Şeklen şöyle
Uses
Bazı hazır gelen şeyler şöyle
actions/checkout@v3
actions/setup-java@v3
actions/cache@v1

Secret
Şeklen şöyle. Settings sekmesinde Security menüsüne gidilir ve altındaki Actions menüsüne tıklanır

Kullanmak için şöyle yaparız
- name: Code Scan Analysis - SonarQube
      env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
          SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
      run: ./gradlew sonarqube -Dsonar.projectKey=android-demo-app
Örnek - To Jira
Şöyle yaparız. Github issue'ya "to-jira" diye label verince otomatik olarak Jira issue'su yaratır.
name: Create Issue in Jira when to-jira label added

on:
  issues:
    types: labeled


jobs:
  jira1:
    if: ${{ github.event.label.name == 'to-jira' }}
    runs-on: ubuntu-latest
    steps:
      - name: Test composite one
        uses: hazelcast/github-jira-tool-action@v2
        with:
          JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }}
          JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }}
          JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }}
          TARGET_JIRA_PROJECT: HZ
          JIRA_LABEL: from-gh
  
java with maven
GitHub maven yazısına taşıdım

java with gradle
Örnek
Şöyle yaparız
name: Android CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: set up JDK 11
      uses: actions/setup-java@v3
      with:
        java-version: '11'
        distribution: 'temurin'
        cache: gradle

    - name: Grant execute permission for gradlew
      run: chmod +x gradlew
    - name: Build with Gradle
      run: ./gradlew build
Açıklaması şöyle
name : The name of the workflow as it will appear in the “Actions” tab of the GitHub repository. Like here it is “Android CI”

on: Specifies the trigger for this workflow. So here the workflow will be triggered when there is a push event in “main” branch and pull_request event in “main” branch

jobs: A workflow job is a set of steps that execute on the same runner. We can have multiple jobs in a single workflow yml file. Groups together all the jobs that run in the Android CI workflow. Here, in the example there is a single job whose name is build

runs-on: Configures the job to run on the latest version of an Ubuntu Linux runner. This means that the job will execute on a fresh virtual machine hosted by GitHub. You can use windows and macOS runner too.

steps: Groups together all the steps that run in the build job. Each item nested under this section is a separate action or shell script.

uses: actions/checkout@v3 : The uses keyword specifies that this step will run v3 of the actions/checkout action. This is an action that checks out your repository onto the runner, allowing you to run scripts or other actions against your code (such as build and test tools). You should use the checkout action any time your workflow will run against the repository's code.

uses: actions/setup-java@v3 : This step uses the actions/setup-java@v3 action to install the specified version of the JDK (this example uses v11) of distribution: 'temurin'

run: chmod +x gradlew: The run keyword tells the job to execute a command on the runner. In this case, you are granting execute permission for gradlew

run: ./gradlew build: In this case you are building the code using gradle





31 Mart 2022 Perşembe

GitHub

1. GitHub'a Link Verme
Eğer bir dosyadaki belirli satırlara link vermek istersek dosya linkinin sonuna  #LBaşlangıçSatırNo-LBitişSatırNo eklenir

Örnek
Şöyle yaparız

2. Fork
Fork işlemi artık sadece "default" dalı getiriyor. Başka bir branch'i de getirmek için kendi repoma giderim. "View all branches" yaparım. "New branch" düğmesine tıklarım ve source olarak esas Github'ı veririm

3. Notifications
Github üzerindeki benden gözden geçirmek istenilen Pull Request'leri görmek için  şöyle yaparız
https://github.com/notifications?query=reason%3Areview-requested

4. Arama
Örnek - dosya ismi
filename:XX ile dosya ismine göre aramak için şöyle yaparız
https://github.com/search?q=org%3AOptivaInc+filename:Cd_fi.xml

5. Dosya İçinde Arama
in:file arama özelliği kullanılıyor

Örnek - kelime
"octocat" kelimesini arar
https://github.com/search?q=octocat+in%3Afile&type=Code
Örnek
Şöyle yaparız
SpringJUnitConfig  lang:Java owner:OrcunColak 

6. Belli Bir Repository Dosyaları İçinde Arama

Örnek
OptivaInc şirketine ait repository'lerdeki dosyalarda "octocat" kelimesini arar
https://github.com/search?q=org%3AOptivaInc+octocat+in%3Afile&type=Code
Şöyle yaparız
https://github.com/search?q=org%3AOptivaInc+INTPcrbdb%3A+in%3Afile&type=Code
Örnek
OptivaInc şirketine ait repository'lerdeki dosyalarda "octocat" kelimesini  uzantısı gradle olan dosyalarda arar
https://github.com/search?p=1&q=org%3AOptivaInc+octocat+in%3Afile+extension%3Agradle&type=Code
Issue
Created By ile Arama
Şöyle yaparız
https://github.com/hazelcast/hazelcast/issues/created_by/ocolak
Filtre bölümüne şunu yazabiliriz
is:open is:issue archived:false author:ocolak
İki repodaki label'lara bakmak için şöyle yaparız
is:issue repo:hazelcast/hazelcast repo:hazelcast/hazelcast-enterprise is:open label:"Type: Test-Failure" sort:created-desc 
GitHub Pull Request
Pull Request için açılan gözden geçirmeye yorum varsa, soruyu soran kişi Resolve Conversation işlemini yapar.

GitHub Review
1. Koda yorumları gir. Yorumlar Add single comment veya Start a review olarak girilebilir. Açıklaması şöyle
There are two options:
1. Add a single comment
2. Start a review

If you click on add single comment, the comment will be made immediately.

If you click on start a review, you’ll have the chance to write more comments before sending them at once. To end the review, you need to click on the Review changes button and select submit review.
 Start a review olarak girdiysek her girilen yorum Pending olarak gösterilir. Gözden geçirme bitince Review changes düğmesine tıklanır ve Request changes düğmesine tıklanır

Git Hook
Açıklaması şöyle
Git hooks are scripts that run automatically every time a particular event occurs in a Git repository. They let you customize Git’s internal behavior and trigger customizable actions at key points in the development life cycle.
maven için git-build-hook plugin kullanılabilir

Web Hook
Açıklaması şöyle
Go to the settings of your GitHub repository and go to Webhooks. Add a new webhook, add the previously generated public URL + “/github-webhook/” to the Payload URL and change the content type to application/json. Select Just the push event to trigger the webhook, and finally click Add webhook.
Şeklen şöyle