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ırKullanmak 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” branchjobs: 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 buildruns-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 gradlewrun: ./gradlew build: In this case you are building the code using gradle
Hiç yorum yok:
Yorum Gönder