aboutsummaryrefslogtreecommitdiffstats
path: root/.github/workflows/build_and_test_ondemand.yml
blob: 4daea429c944e84667f8431f09be2580f69465ba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Build-and-Test On-demand VM

on:
  workflow_call:
    inputs:
      sanitizer:
        required: false
        type: string
      test_label_regexp:
        required: false
        type: string
      image:
        type: string
        required: false
        default: fd8snjpoq85qqv0mk9gi
  workflow_dispatch:
    inputs: 
      sanitizer:
        required: false
        type: string
      test_label_regexp:
        required: false
        type: string
      image:
        type: string
        required: false
        default: fd8snjpoq85qqv0mk9gi
    
jobs:

  provide-runner:
    name: Start self-hosted YC runner
    timeout-minutes: 5
    runs-on: ubuntu-latest
    outputs:
      label: ${{steps.start-yc-runner.outputs.label}}
      instance-id: ${{steps.start-yc-runner.outputs.instance-id}}
    steps:
      - name: Start YC runner
        id: start-yc-runner
        uses: yc-actions/yc-github-runner@v1
        with:
          mode: start
          yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }}
          github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
          folder-id: ${{secrets.YC_FOLDER}}
          image-id: ${{inputs.image}}
          disk-size: 930GB
          disk-type: network-ssd-nonreplicated
          cores: 32
          memory: 64GB
          core-fraction: 100
          zone-id: ru-central1-b
          subnet-id: ${{secrets.YC_SUBNET}}
      - name: cleanup-test-label
        uses: actions/github-script@v6
        with:
          github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
          script: |
            const { owner, repo } = context.repo;
            const prNumber = context.payload.pull_request.number;
            const labelToRemove = 'ok-to-test';
            try {
              const result = await github.rest.issues.removeLabel({
                owner,
                repo,
                issue_number: prNumber,
                name: labelToRemove
              });
            } catch(e) {
              // ignore the 404 error that arises
              // when the label did not exist for the
              // organization member
              console.log(e);
            }

  prepare-vm:
    name: Prepare runner
    uses: ./.github/workflows/prepare_vm_for_build.yml
    needs: provide-runner
    with:
      runner_label: ${{ needs.provide-runner.outputs.label }}
    secrets:
      rc_auth: ${{ secrets.REMOTE_CACHE_AUTH }}  

  main:
    name: Build and test
    needs: 
    - provide-runner
    - prepare-vm
    runs-on: [ self-hosted, "${{ needs.provide-runner.outputs.label }}" ]
    steps:
    - name: Checkout PR
      uses: actions/checkout@v3
      if: github.event.pull_request.head.sha != ''
      with:
          ref: ${{ github.event.pull_request.head.sha }}
    - name: Checkout
      uses: actions/checkout@v3
      if: github.event.pull_request.head.sha == ''
    - name: Build
      uses: ./.github/actions/build
      with: 
        sanitizer: ${{ inputs.sanitizer }}
    - name: Test
      uses: ./.github/actions/test
      with: 
        log_suffix: ${{format('{0}{1}', 'X64', inputs.sanitizer)}}
        test_label_regexp: ${{ inputs.test_label_regexp }}
        aws_key_id: ${{secrets.AWS_KEY_ID}}
        aws_key_value: ${{secrets.AWS_KEY_VALUE}}
        testman_token: ${{secrets.TESTMO_TOKEN}}
        testman_url: ${{vars.TESTMO_URL}}
        testman_project_id: ${{vars.TESTMO_PROJECT_ID}}

  release-runner:
    name: Release self-hosted YC runner if provided on-demand
    needs:
      - provide-runner # required to get output from the start-runner job
      - main # required to wait when the main job is done
    runs-on: ubuntu-latest
    if: always()
    steps:
      - name: Stop YC runner
        uses: yc-actions/yc-github-runner@v1
        with:
          mode: stop
          yc-sa-json-credentials: ${{ secrets.YC_SA_JSON_CREDENTIALS }}
          github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
          label: ${{ needs.provide-runner.outputs.label }}
          instance-id: ${{ needs.provide-runner.outputs.instance-id }}