Welcome to mirror list, hosted at ThFree Co, Russian Federation.

build-sd-images.yml « workflows « .github - github.com/nextcloud/nextcloudpi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3df86c88affe8c7c52c95e4412e110cbcf2ae3bb (plain)
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
name: "Build Armbian Images"
on:
  workflow_call:
    inputs:
      git_ref:
        required: true
        type: string
      board_id:
        required: true
        type: string
      board_name:
        required: true
        type: string
      require_test:
        required: false
        default: true
        type: boolean
    outputs:
      artifact_name:
        value: "${{ jobs.build.outputs.artifact_name }}"
      artifact_file:
        value: "${{ jobs.build.outputs.artifact_file }}"

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      VERSION: "${{ inputs.git_ref }}"
    defaults:
      run:
        shell: bash
    outputs:
      artifact_file: ${{ env.ARTIFACT_FILE }}
      artifact_name: ${{ github.run_id }}-${{ inputs.board_id }}-image
    steps:
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      - name: Apply workaround for sudo bug (https://github.com/multiarch/qemu-user-static/issues/17)
        run: |
          apt-get -y --no-install-recommends install binfmt-support qemu-user-static
          for conf in qemu-{aarch64,arm}-static.conf
          do
            sed 's/:F$/:OC/' /usr/lib/binfmt.d/$conf > /etc/binfmt/$conf
          done
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          ref: "${{ env.VERSION }}"
      - name: "Build Armbian"
        if: ${{ inputs.board_id != 'raspberrypi' }}
        id: build-armbian
        continue-on-error: true
        run: |
          set -ex
          export LIB_TAG=master
          export IMG="NextCloudPi_${{ inputs.board_name }}_${VERSION//\//_}.img"
          [[ "${{ github.ref_protected }}" == true ]] || export DBG=x
          
          ./build/build-SD-armbian.sh "${{ inputs.board_id }}" "${{ inputs.board_name }}"
          
          artifacts=("armbian/output/images/Armbian"*.img)
          mkdir -p output
          mv "${artifacts[0]}" "output/$IMG"
          echo "::set-output name=artifact_file::${IMG}"
          echo "ARTIFACT_FILE=${IMG}" >> $GITHUB_ENV
      - name: "Build Armbian (2nd attempt)"
        if: ${{ inputs.board_id != 'raspberrypi' && steps.build-armbian.outcome == 'failure' }}
        id: build-armbian-2nd
        run: |
          set -ex
          echo "Cleanup armbian build leftovers..."
          sudo rm -rf armbian/ tmp/ output/
          
          export LIB_TAG=master
          export IMG="NextCloudPi_${{ inputs.board_name }}_${VERSION//\//_}.img"
          [[ "${{ github.ref_protected }}" == true ]] || export DBG=x

          ./build/build-SD-armbian.sh "${{ inputs.board_id }}" "${{ inputs.board_name }}"

          artifacts=("armbian/output/images/Armbian"*.img)
          mkdir -p output
          mv "${artifacts[0]}" "output/$IMG"
          echo "::set-output name=artifact_file::${IMG}"
          echo "ARTIFACT_FILE=${IMG}" >> $GITHUB_ENV
      - name: "Upload Armbian logs"
        if: ${{ inputs.board_id != 'raspberrypi' && steps.build-armbian-2nd.outcome == 'failure' }}
        uses: actions/upload-artifact@v3
        with:
          name: ${{ github.run_id }}-${{ inputs.board_id }}-logs
          path: armbian/output
      - name: Build RPI SD Image
        if: ${{ inputs.board_id == 'raspberrypi' }}
        id: build-rpi
        run: |
          set -ex
          echo "Protected? ${{ github.ref_protected }}"
          export IMG="NextCloudPi_${{ inputs.board_name }}_${VERSION//\//_}.img"
          [[ "${{ github.ref_protected }}" == true ]] || export DBG=x
          ./build/build-SD-rpi.sh
          mkdir -p output
          mv "tmp/$IMG" ./output/

          for i in {1..10}
          do
            sudo losetup | grep "${IMG}" || break;
            [[ "$i" -lt 10 ]] || { echo "Timeout while waiting for image to unmount"; exit 1; }
            sleep 6
            echo "Retrying ($i out of 10)"
          done

          echo "::set-output name=artifact_file::${IMG}"
          echo "ARTIFACT_FILE=${IMG}" >> $GITHUB_ENV
      - name: upload image to artifact store
        uses: actions/upload-artifact@v3
        with:
          name: ${{ github.run_id }}-${{ inputs.board_id }}-image
          path: output/${{ env.ARTIFACT_FILE }}
          if-no-files-found: error

  test:
    needs: build
    runs-on: ubuntu-latest
    env:
      VERSION: "${{ inputs.git_ref }}"
      ARTIFACT_ID: ${{ needs.build.outputs.artifact_name }}
      ARTIFACT_FILE: ${{ needs.build.outputs.artifact_file }}
    defaults:
      run:
        shell: bash
    steps:
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v1
      - name: Apply workaround for sudo bug (https://github.com/multiarch/qemu-user-static/issues/17)
        run: |
          apt-get -y --no-install-recommends install binfmt-support qemu-user-static
          for conf in qemu-{aarch64,arm}-static.conf
          do
            sed 's/:F$/:OC/' /usr/lib/binfmt.d/$conf > /etc/binfmt/$conf
          done
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          ref: "${{ env.VERSION }}"
      - uses: actions/download-artifact@v3
        with:
          name: ${{ env.ARTIFACT_ID }}
          path: output
      - name: Prepare test
        run: |
          set -ex
          mv output/${ARTIFACT_FILE?} ncp.img
          sudo apt-get install -y systemd-container
          sudo pip install selenium
          sudo rm -rf raspbian_root
          . ./build/buildlib.sh
          mount_raspbian "ncp.img"
          echo 'Mutex posixsem' | sudo tee -a raspbian_root/etc/apache2/mods-available/ssl.conf
      - name: Test image
        id: test
        run: |
          set -ex
          
          trap 'sudo machinectl terminate ncp' EXIT
          
          sudo systemd-nspawn --boot -D ./raspbian_root/ -M ncp --hostname=nextcloudpi |& awk '{ print "CONTAINER::" $0 }' &
          sudo systemd-run --machine=ncp -P --wait bash -c 'tail -f /var/log/ncp.log' |& awk '{ print "NCP::" $0 }' &
          sleep 30
          
          success=false
          for attempt in {1..30}
          do
            echo ":: Wait for container to startup (attempt $attempt/30) ::"
            ip="$(sudo systemd-run --machine=ncp -P --wait bash -c '. /usr/local/etc/library.sh > /dev/null; get_ip')"
            [[ -n "$ip" ]] && curl -k "https://$ip/activate" > /dev/null || { sleep 6; continue; }
            success=true
            break
          done
          
          [[ "$success" == "true" ]] || {
            echo "Could not reach container. Aborting..."
            exit 1
          }
          
          success=false
          for attempt in {1..3}
          do
            echo ":: Activation Tests (attempt $attempt/3) ::"
            python tests/activation_tests.py -t 300 --no-gui "$ip" 443 4443 || {
              echo "Activation test failed!"
              echo "Geckodriver logs:"
              tail -n 20 geckodriver.log >&2 || true
              echo "================"
              echo "ncp.log: "
              sudo systemd-run --wait -P --machine=ncp ncp /bin/bash -c "tail -n20 /var/log/ncp.log || echo 'ncp.log not found'"
              sleep 6
              continue
            }
            success=true
            break
          done
          [[ "$success" == "true" ]] || {
            echo "Activation test failed in all attempts!"
            exit 1
          }
          
          success=false
          for attempt in {1..3}
          do
            echo ":: System Tests (attempt $attempt/3) ::"
            sudo python tests/system_tests.py --non-interactive || {
              echo "System test failed!"
              sleep 6
              continue
            }
            success=true
            break
          done
          [[ "$success" == "true" ]] || {
            echo "System test failed in all attempts!"
            exit 1
          }
          
          success=false
          for attempt in {1..3}
          do
            echo ":: Nextcloud Tests (attempt $attempt/3) ::"
            python tests/nextcloud_tests.py --no-gui "$ip" 443 4443 || {
              echo "Nextcloud test failed!"
              echo "Geckodriver logs:"
              tail -n 20 geckodriver.log >&2 || true
              echo "================"
              echo "ncp.log: "
              sudo systemd-run --wait -P --machine=ncp ncp /bin/bash -c "tail -n20 /var/log/ncp.log" || true
              sleep 6
              continue
            }
            success=true
            break
          done
          
          [[ "$success" == "true" ]] || {
            echo "Nextcloud test failed in all attempts!"
            exit 1
          }