diff options
author | Tobias K <6317548+theCalcaholic@users.noreply.github.com> | 2022-08-21 03:40:27 +0300 |
---|---|---|
committer | Tobias K <6317548+theCalcaholic@users.noreply.github.com> | 2022-08-21 03:40:27 +0300 |
commit | 8b4f9cb0b31882857ee91b6d38c0b342abb173a1 (patch) | |
tree | e603f214e9900e12350a3af9f6e025fc92305858 /.github | |
parent | 9933d072d121fbf0d9c80afabf29edc0a2a89034 (diff) |
build-lxd.yml: Add update test
Diffstat (limited to '.github')
-rw-r--r-- | .github/workflows/build-lxd.yml | 147 | ||||
-rw-r--r-- | .github/workflows/lxd-trigger.yml (renamed from .github/workflows/pr-tests.yml) | 5 |
2 files changed, 145 insertions, 7 deletions
diff --git a/.github/workflows/build-lxd.yml b/.github/workflows/build-lxd.yml index 6a2e60b7..b4658940 100644 --- a/.github/workflows/build-lxd.yml +++ b/.github/workflows/build-lxd.yml @@ -42,25 +42,158 @@ jobs: id: pack-lxd run: | . ./build/buildlib.sh - ARTIFACT_NAME="NextCloudPi_LXD_${VERSION//\//_}" - lxc image export -q ncp/"${version}" "output/${ARTIFACT_NAME}" - echo "::set-output name=artifact_file::${ARTIFACT_NAME}.tar.gz" + 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_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 + git fetch -fu --tags origin ${{ env.VERSION }}:${{ env.VERSION }} + 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: 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 + VERSION="${VERSION/refs\/heads\//}" + VERSION="${VERSION/refs\/tags\//}" + VERSION="${VERSION/refs\/pull\//}" + echo "VERSION=${VERSION}" >> "$GITHUB_ENV" + echo "Running update ${{ needs.build-previous.outputs.previous_version }} -> ${VERSION}" + lxc exec ncp -- bash -c "DBG=x ncp-update '${VERSION//}'" + lxc stop ncp + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: "${{ env.VERSION }}" + - 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: "${{ inputs.git_ref || github.head_ref || github.ref_name }}" + ref: "${{ env.VERSION }}" - uses: whywaita/setup-lxd@v1 with: lxd_version: latest/stable @@ -73,12 +206,12 @@ jobs: - name: download LXD image from artifact store uses: actions/download-artifact@v3 with: - name: ${{ github.run_id }}-lxd-image + name: ${{ matrix.build.artifact_name }} - name: Launch ncp container run: | set -x lxc delete -q -f ncp || true - lxc image import -q "./${{ needs.build.outputs.artifact_file }}" --alias "ncp/test" + 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 diff --git a/.github/workflows/pr-tests.yml b/.github/workflows/lxd-trigger.yml index b32ffec3..5c8a2a9a 100644 --- a/.github/workflows/pr-tests.yml +++ b/.github/workflows/lxd-trigger.yml @@ -1,8 +1,13 @@ +name: LXD Tests + on: pull_request: branches: - master - devel + push: + branches: + - devel jobs: lxd: |