Skip to content

Back to snap (which is a VM) #248

Back to snap (which is a VM)

Back to snap (which is a VM) #248

Workflow file for this run

name: Build
on:
push:
workflow_dispatch:
inputs:
branch:
description: 'Branch to run the workflow on'
required: true
default: 'master'
# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: snap-pelion-edge-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
build-snap:
runs-on: [ "self-hosted", "snap" ]
steps:
- name: Enable write on all files
run: chmod a+w -R .
- name: Check out code
uses: actions/checkout@v4
with:
# Use the branch specified by the workflow_dispatch input or the pull_request event
ref: ${{ github.event.inputs.branch || github.event.pull_request.head.ref }}
- name: Copy mbed_cloud_dev_credentials.c
env:
MBED_CLOUD_DEV_CREDENTIALS: ${{ secrets.MBED_CLOUD_DEV_CREDENTIALS_SNAP_CI }}
run: |
echo "$MBED_CLOUD_DEV_CREDENTIALS" > mbed_cloud_dev_credentials.c
- name: Copy update_default_resources.c
env:
UPDATE_DEFAULT_RESOURCES: ${{ secrets.UPDATE_DEFAULT_RESOURCES_SNAP_CI }}
run: |
echo "$UPDATE_DEFAULT_RESOURCES" > update_default_resources.c
- name: Build Docker image
run: |
docker build --no-cache -f Dockerfile --label snapcore/snapcraft --tag ${USER}/snapcraft:latest .
- name: Build snap
run: |
# If previous run failed, set everything to write mode.
chmod a+w -R .
docker run --rm -v "$PWD":/build -w /build ${USER}/snapcraft:latest bash -c "sudo apt-get update && snapcraft --debug"
# The build left files with no write rights, which ruins next test run
chmod a+w -R .
- name: Archive the snap-binary
uses: actions/upload-artifact@v4
with:
name: pelion-edge-amd64.snap
path: ./pelion-edge*.snap
if-no-files-found: error
- name: Archive connect.sh
uses: actions/upload-artifact@v4
with:
name: connect.sh
path: ./connect.sh
if-no-files-found: error
test:
runs-on: [ "self-hosted", "snap" ]
needs: build-snap
timeout-minutes: 40
env:
ACCESS_KEY: ${{ secrets.IZUMA_ACCESS_KEY }}
steps:
- name: Check out code
uses: actions/checkout@v4
with:
# Use the branch specified by the workflow_dispatch input or the pull_request event
ref: ${{ github.event.inputs.branch || github.event.pull_request.head.ref }}
- name: Check out scripts-internal & e2e tests repos
run: |
git config --global url."https://${{ secrets.ACCESS_TOKEN }}@github.com/".insteadOf "git@github.com:"
git config --global url."https://${{ secrets.ACCESS_TOKEN }}@github".insteadOf "https://github"
git clone git@github.com:PelionIoT/e2e-edge-test-suite
git clone git@github.com:PelionIoT/scripts-internal.git
ls -al
- name: Set up Python v3.8
uses: actions/setup-python@v5
with:
python-version: v3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r e2e-edge-test-suite/requirements.txt
sudo apt install virtualenv
curl -LO https://dl.k8s.io/release/v1.25.0/bin/linux/amd64/kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
- name: Get pelion-edge.snap from storage
uses: actions/download-artifact@v4
with:
name: pelion-edge-amd64.snap
path: e2e-edge-test-suite
- name: Get connect.sh from storage
uses: actions/download-artifact@v4
with:
name: connect.sh
path: e2e-edge-test-suite
- name: Install snap as sudo and test
run: |
snapfile=$(ls e2e-edge-test-suite/*.snap)
sudo scripts-internal/snap/snap-install.sh -s $snapfile
sleep 5
if sudo snap restart pelion-edge; then
echo "sudo snap restart succeeded."
else
echo "sudo snap restart pelion-edge failed. Test results might be invalid."
fi
sleep 5
snap services
snap list
pelion-edge.help
pelion-edge.edge-info
pelion-edge.version
pelion-edge.edge-testnet
pelion-edge.curl --version
- name: Check snap-pelion-edge versions
run: |
sudo snap install yq
snapcraftyamlver=$(yq -r ".version" <snap/snapcraft.yaml |sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g")
version=$(pelion-edge.version |grep snap-pelion-edge | awk -F' ' '{ print $NF }')
if [[ "$snapcraftyamlver" != "$version" ]]; then
echo "FAIL - Snapcraft.yaml and pelion-edge.version versions differ: $snapcraftyamlver vs. $version"
exit 1
fi
snapver=$(snap list |grep "pelion-edge" | awk -F' ' '{ print $2 }')
if [[ "$snapcraftyamlver" != "$snapver" ]]; then
echo "FAIL - Snapcraft.yaml and snap list versions differ: '$snapcraftyamlver' vs. '$snapver'"
exit 1
fi
infover=$(pelion-edge.edge-info |grep "Pelion Edge Version:" | awk -F' ' '{ print $NF }' |sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2};?)?)?[mGK]//g" )
if [[ "$snapcraftyamlver" != "$infover" ]]; then
echo "FAIL - Snapcraft.yaml and pelion-edge.edge-info versions differ: '$snapcraftyamlver' vs. '$infover'"
exit 1
fi
- name: Run snap-test
if: ${{ failure() }} || ${{ success() }}
run: |
cd e2e-edge-test-suite
../scripts-internal/snap/snap-test.sh -a ${{ secrets.IZUMA_ACCESS_KEY }}
- name: Remove snap
if: always()
run: |
sudo scripts-internal/snap/snap-remove.sh -a ${{ secrets.IZUMA_ACCESS_KEY }} -s pelion-edge
- name: Archive the pytest.log
uses: actions/upload-artifact@v4
with:
name: pytest.log
path: e2e-edge-test-suite/pytest.log
if-no-files-found: error
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
results.xml
- name: Clean up .gitconfig
if: always()
run: rm -f ~/.gitconfig
pysh-check:
runs-on: client
steps:
- uses: actions/checkout@v4
- run: sudo apt-get install -y black pycodestyle pydocstyle shellcheck python3
- name: Check out scripts-internal
uses: actions/checkout@v4
with:
token: ${{ secrets.ACCESS_TOKEN }}
repository: PelionIoT/scripts-internal
path: scripts-internal
- run: |
echo . >scripts-internal/.nopyshcheck
scripts-internal/ci/more-lines-checker.sh dev ${{ github.ref_name }} "scripts-internal/pysh-check/pysh-check.sh --workdir . pysh" > pysh-check.log
cat pysh-check.log
- name: Archive the logs
if: always()
uses: actions/upload-artifact@v4
with:
name: Shellcheck logs
path: "./*.log"
yamllint-snapcraft-yaml:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: sudo apt-get install yamllint
- run: yamllint -c lint-config.yaml snap/snapcraft.yaml
- name: Check yq compliancy
run: |
sudo snap install yq
yq -r "." <snap/snapcraft.yaml >yqout.yaml
if diff -u snap/snapcraft.yaml yqout.yaml
then
echo "yq compliancy check passed"
else
echo "yq compliancy check failed"
exit 1
fi