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

build-lxd.yml « workflows « .github - github.com/nextcloud/nextcloudpi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 275e283d5ed3d95f52f604b7d1c9ee1ddaf0043f (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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
name: "Build and test LXD image"
on:
  workflow_call:
    inputs:
      git_ref:
        required: true
        type: string
    outputs:
      artifact_name:
        value: "${{ jobs.build.outputs.artifact_name }}"
      artifact_file:
        value: "${{ jobs.build.outputs.artifact_file }}"
  push:
    branches:
      - "**"
  pull_request:
    branches:
      - "master"
      - "devel"

jobs:
  build:
    runs-on: ubuntu-latest
    outputs:
      artifact_name: "${{ env.ARTIFACT_NAME }}"
      artifact_file: "${{ steps.pack-lxd.outputs.artifact_file }}"
    env:
      VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}"
      ARTIFACT_NAME: "${{ github.run_id }}-lxd-image"
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          ref: "${{ env.VERSION }}"
      - uses: whywaita/setup-lxd@v1
        with:
          lxd_version: latest/stable
      - name: Build LXD image
        run: |
          ./build/build-LXD.sh
      - name: Pack LXD image
        id: pack-lxd
        run: |
          . ./build/buildlib.sh
          ARTIFACT_FILE="NextCloudPi_LXD_${VERSION//\//_}"
          lxc image export -q ncp/"${version}" "output/${ARTIFACT_FILE}"
          echo "::set-output name=artifact_file::${ARTIFACT_FILE}.tar.gz"
      - name: upload LXD image to artifact store
        uses: actions/upload-artifact@v3
        with:
          name: "${{ env.ARTIFACT_NAME }}"
          path: "output/${{ steps.pack-lxd.outputs.artifact_file }}"
          if-no-files-found: error

  build-previous:
    runs-on: ubuntu-latest
    outputs:
      artifact_name: "${{ env.ARTIFACT_NAME }}"
      artifact_file: "${{ steps.pack-lxd.outputs.artifact_file }}"
      previous_version: "${{ steps.checkout_previous_version.outputs.previous_version }}"
    env:
      VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}"
      ARTIFACT_NAME: "${{ github.run_id }}-lxd-image-previous"
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          ref: "${{ env.VERSION }}"
          fetch-depth: 0
      - name: Checkout previous release
        id: checkout_previous_version
        shell: bash
        run: |
          set -e
          if [[ -n "${{ github.base_ref }}" ]]
          then
            version="${{ github.base_ref }}"
          elif [[ "${{ env.VERSION }}" == "refs/heads/devel" ]]
          then
            version="master"
          else
            if [[ "${{ github.ref_type }}" != "tag" ]] || ! git describe --tags > /dev/null
            then
              git fetch -fu --tags origin ${{ env.VERSION }}:${{ env.VERSION }}
            fi
            version="$(git describe --tags)"
            [[ "$version" =~ .*-.*-.* ]] || {
              git checkout HEAD~1
              version="$(git describe --tags)"
            }
            version="${version%-*-*}"
          fi
          echo "Previous version is '$version'"
          git checkout "$version"
          echo "VERSION=$version" >> "$GITHUB_ENV"
          echo "::set-output name=previous_version::${version}"
      - uses: whywaita/setup-lxd@v1
        with:
          lxd_version: latest/stable
      - name: Build LXD image
        run: |
          ./build/build-LXD.sh
      - name: Pack LXD image
        id: pack-lxd
        run: |
          . ./build/buildlib.sh
          ARTIFACT_FILE="NextCloudPi_LXD_${VERSION//\//_}"
          lxc image export -q ncp/"${version}" "output/${ARTIFACT_FILE}"
          echo "::set-output name=artifact_file::${ARTIFACT_FILE}.tar.gz"
      - name: upload LXD image to artifact store
        uses: actions/upload-artifact@v3
        with:
          name: "${{ env.ARTIFACT_NAME }}"
          path: "output/${{ steps.pack-lxd.outputs.artifact_file }}"
          if-no-files-found: error

  update-previous:
    needs:
      - build-previous
    runs-on: ubuntu-latest
    outputs:
      artifact_name: "${{ env.ARTIFACT_NAME }}"
      artifact_file: "${{ steps.pack-lxd.outputs.artifact_file }}"
    env:
      VERSION: "${{ inputs.git_ref || github.ref }}"
      ARTIFACT_NAME: "${{ github.run_id }}-lxd-image-updated"
    steps:
      - uses: whywaita/setup-lxd@v1
        with:
          lxd_version: latest/stable
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          ref: "${{ env.VERSION }}"
      - name: download LXD image from artifact store
        uses: actions/download-artifact@v3
        with:
          name: ${{ needs.build-previous.outputs.artifact_name }}
      - name: Launch ncp container
        run: |
          set -x
          lxc delete -q -f ncp || true
          lxc image import -q "./${{ needs.build-previous.outputs.artifact_file }}" --alias "ncp/update"
          systemd-run --user --scope -p "Delegate=yes" lxc launch -q "ncp/update" ncp
          lxc exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done'
          sleep 30
          ip="$(lxc list -c n4 -f csv | grep '^ncp' | cut -d ',' -f2)"
          ip="${ip/% *}"
          echo "${ip} nextcloudpi.local" | sudo tee /etc/hosts

      - name: Update ncp
        run: |
          set -ex
          BRANCH="${VERSION/refs\/heads\//}"
          BRANCH="${BRANCH/refs\/tags\//}"
          if [[ "$BRANCH" =~ "refs/pull/"* ]]
          then
            UPDATE_ARGS=("${{ github.base_ref }}" "$VERSION") 
          else
            UPDATE_ARGS=("$BRANCH")
          fi
          echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
          echo "Running update ${{ needs.build-previous.outputs.previous_version }} -> ${VERSION}"
          latest_nc_version="$(cat etc/ncp.cfg | jq -r '.nextcloud_version')"
          lxc exec ncp -- bash -c "DBG=x ncp-update ${UPDATE_ARGS[*]}"
          lxc exec ncp -- /usr/local/bin/ncc status
          lxc exec ncp -- bash -c "DBG=x ncp-update-nc ${latest_nc_version?}"
          lxc stop ncp
      - name: Pack LXD image
        id: pack-lxd
        run: |
          set -x
          . ./build/buildlib.sh
          ARTIFACT_FILE="NextCloudPi_LXD_${VERSION//\//_}"
          lxc publish -q ncp -f --alias "ncp/updated"
          mkdir -p output
          lxc image export -q "ncp/updated" "output/${ARTIFACT_FILE}"
          echo "::set-output name=artifact_file::${ARTIFACT_FILE}.tar.gz"
      - name: upload LXD image to artifact store
        uses: actions/upload-artifact@v3
        with:
          name: "${{ env.ARTIFACT_NAME }}"
          path: "output/${{ steps.pack-lxd.outputs.artifact_file }}"
          if-no-files-found: error

  test:
    needs:
      - build
      - update-previous
    strategy:
      matrix:
        build:
          - source: install
            artifact_name: ${{ needs.build.outputs.artifact_name }}
            artifact_file: ${{ needs.build.outputs.artifact_file }}
          - source: update
            artifact_name: ${{ needs.update-previous.outputs.artifact_name }}
            artifact_file: ${{ needs.update-previous.outputs.artifact_file }}
      fail-fast: false
    runs-on: ubuntu-latest
    env:
      VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}"
    steps:
      - name: Checkout code
        uses: actions/checkout@v3
        with:
          ref: "${{ env.VERSION }}"
      - uses: whywaita/setup-lxd@v1
        with:
          lxd_version: latest/stable
      - name: Setup Firefox
        uses: browser-actions/setup-firefox@latest
      - name: Setup GeckoDriver
        uses: browser-actions/setup-geckodriver@latest
      - name: Setup Selenium
        run: pip install selenium
      - name: download LXD image from artifact store
        uses: actions/download-artifact@v3
        with:
          name: ${{ matrix.build.artifact_name }}
      - name: Launch ncp container
        run: |
          set -x
          lxc delete -q -f ncp || true
          lxc image import -q "./${{ matrix.build.artifact_file }}" --alias "ncp/test"
          systemd-run --user --scope -p "Delegate=yes" lxc launch -q "ncp/test" ncp
          lxc exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done'
          sleep 30
          ip="$(lxc list -c n4 -f csv | grep '^ncp' | cut -d ',' -f2)"
          ip="${ip/% *}"
          echo "${ip} nextcloudpi.local" | sudo tee /etc/hosts
      - name: Test LXD Image
        working-directory: ./tests
        run: |
          lxc exec ncp -- bash -c 'tail -f /var/log/ncp.log' |& awk '{ print "NCP::" $0 }' &
          python activation_tests.py --no-gui "nextcloudpi.local" 443 4443 || {
            echo "Activation test failed!"
            echo "Geckodriver logs:"
            tail -n 20 geckodriver.log >&2 || true
            echo "================"
            echo "ncp.log: "
            lxc exec ncp -- "tail -n20 /var/log/ncp.log"
            exit 1
          }
          python system_tests.py --non-interactive || {
            echo "System test failed!"
            exit 1
          }
          python nextcloud_tests.py --no-gui "nextcloudpi.local" 443 4443 || {
            echo "Nextcloud test failed!"
            echo "Geckodriver logs:"
            tail -n 20 geckodriver.log >&2 || true
            echo "================"
            echo "ncp.log: "
            lxc exec ncp -- "tail -n20 /var/log/ncp.log"
            exit 1
          }
          lxc stop ncp