Skip to content

Merge branch 'polycube-network:master' into master #1

Merge branch 'polycube-network:master' into master

Merge branch 'polycube-network:master' into master #1

Workflow file for this run

# This is a basic workflow to help in CI
name: Polycube CI
# Controls when the action will run. Triggers the workflow on schedule events
on:
push:
branches:
- master
tags:
- "v*"
paths-ignore:
- 'Documentation/**'
pull_request_target:
types:
- opened
- reopened
- synchronize
paths-ignore:
- 'Documentation/**'
env:
app-container: polycubed
app-registry: polycubenets
jobs:
# This job deal with retrieving variables for workflow configuration
configure:
name: Preliminary configuration
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.configure.outputs.ref }}
repo: ${{ steps.configure.outputs.repo }}
state: ${{ steps.configure.outputs.state }}
version: ${{ steps.version.outputs.version }}
build-matrix: ${{ steps.setup-build-matrix.outputs.build-matrix }}
steps:
- name: If tag pushed get the version
id: version
run: echo "::set-output name=version::${GITHUB_REF/refs\/tags\//}"
if: |
github.event_name == 'push' &&
github.event.base_ref == 'refs/heads/master' &&
startsWith(github.ref, 'refs/tags/v')
- name: Configure ref and state
id: configure
run: |
# If the event is a pull request the repo to checkout is the PR repo, otherwise
# we checkout the current repo
if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then
echo "::set-output name=ref::${{ github.event.pull_request.head.sha }}"
echo "::set-output name=repo::${{ github.event.pull_request.head.repo.full_name }}"
echo "::set-output name=state::dev"
elif [[ "${{ steps.version.outputs.version }}" != "" ]]; then
echo "::set-output name=ref::${{ steps.version.outputs.version }}"
echo "::set-output name=repo::${{ github.repository }}"
echo "::set-output name=state::release"
else
echo "::set-output name=ref::${{ github.sha }}"
echo "::set-output name=repo::${{ github.repository }}"
echo "::set-output name=state::master"
fi
- name: Setup matrix combinations
id: setup-build-matrix
run: |
if [[ "${{ steps.configure.outputs.state }}" == "dev" ]]; then
BUILD_MATRIX='
{"mode": "default", "name": "polycube-pr"},
'
else
BUILD_MATRIX='
{"mode": "default", "name": "polycube"},
{"mode": "pcn-k8s", "name": "polycube-k8s"},
{"mode": "pcn-iptables", "name": "polycube-iptables"},
'
fi
echo ::set-output name=build-matrix::{\"include\":[$BUILD_MATRIX]}
start-notify:
name: Start build notification with Slack
runs-on: ubuntu-latest
needs: [configure]
steps:
- name: Notify on slack that CI started
uses: 8398a7/action-slack@v3
with:
status: custom
fields: workflow,commit,repo,ref
custom_payload: |
{
"attachments":[
{
"title":`${process.env.AS_WORKFLOW}`,
"text": "All polycube builds started",
"fields":[{
"title":"Check suite",
"value":"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
},
{
"title":"Git reference",
"value":`${process.env.AS_REPO}@${process.env.AS_REF}`,
},
{
"title":"Commit",
"value":`${process.env.AS_COMMIT}`,
}]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always() # Pick up events even if the job fails or is canceled.
# This job deals with building the application
build:
name: Build & Push Polycube
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: [configure]
outputs:
default: ${{ steps.save.outputs.default }}
k8s: ${{ steps.save.outputs.pcn-k8s }}
iptables: ${{ steps.save.outputs.pcn-iptables }}
# Build strategies
strategy:
matrix: ${{ fromJson(needs.configure.outputs.build-matrix) }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository (default master)
- uses: actions/checkout@v2
with:
submodules: true
persist-credentials: false
ref: ${{ needs.configure.outputs.ref }}
repository: "${{ needs.configure.outputs.repo }}"
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Repo setup
id: setup
run: |
repo=${{ env.app-registry }}/${{ matrix.name }}
if [[ "${{ needs.configure.outputs.state }}" == "dev" ]]; then
echo "::set-output name=repo-tags::$repo:${{ needs.configure.outputs.ref }}"
else
echo "::set-output name=repo-tags::$repo:${{ needs.configure.outputs.ref }},$repo:latest"
fi
- name: Docker login
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
builder: ${{ steps.buildx.outputs.name }}
build-args: |
DEFAULT_MODE=${{ matrix.mode }}
push: true
tags: ${{ steps.setup.outputs.repo-tags }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Save build result in output
id: save
if: always()
run: |
echo "::set-output name=${{ matrix.mode }}::${{ job.status }}"
# This job deals with tests
test:
name: Test Polycube
runs-on: ubuntu-latest
needs: [build, configure]
if: needs.configure.outputs.state == 'dev'
outputs:
clean: ${{ steps.clean.outputs.default-clean }}
same: ${{ steps.clean.outputs.default-same }}
# Test strategies
strategy:
fail-fast: false
matrix:
test: ['default-clean', 'default-same']
include:
- test: 'default-clean'
name: 'polycube-pr'
mode: default
test-script: run-tests.sh
relaunch-polycubed: true
test-mode: CleanInstance
- test: 'default-same'
name: 'polycube-pr'
mode: default
test-script: run-tests.sh
relaunch-polycubed: false
test-mode: SameInstance
steps:
- uses: actions/checkout@v2
with:
submodules: true
persist-credentials: false
ref: ${{ needs.configure.outputs.ref }}
repository: "${{ needs.configure.outputs.repo }}"
- name: Setup Python
uses: actions/setup-python@v1
- name: Setup VirtualEnv
run: python3 -m pip install --user virtualenv
- name: Setup JUnitParser
run: python3 -m pip install --user junitparser
- name: Setup XMLToDict
run: python3 -m pip install --user xmltodict
# Install additional tools that are required in the testing phase
# - nmap: some tests use 'nping', which is included in this package
- name: Setup additional testing tools
run: |
sudo apt-get update
sudo apt-get install nmap
- name: Docker login with bot credentials
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Prepare tests log directory
run: sudo mkdir -p /var/log/polycube
- name: Set OS env
run: |
echo "KILL_COMMAND=docker stop ${{ env.app-container }}" >> $GITHUB_ENV
echo "polycubed=docker run -d --name ${{ env.app-container }} --rm --privileged \
--pid=host --cap-add ALL --network host \
-v /proc:/host/proc -v /lib/modules:/lib/modules:ro -v /var/run/netns/:/var/run/netns:rw \
-v /usr/src:/usr/src:ro -v /etc/localtime:/etc/localtime:ro \
${{ env.app-registry }}/${{ matrix.name }}:${{ needs.configure.outputs.ref }}" >> $GITHUB_ENV
- name: Extract from Docker image
run: |
$polycubed /bin/sleep infinity
./CI/extract_from_docker_image.sh ${{ env.app-container }}
$KILL_COMMAND
- name: Run tests
run: |
cd tests/
sudo ./${{ matrix.test-script }} ${{ matrix.relaunch-polycubed }} || true
export LC_ALL=C
python3 -m virtualenv venv -p python3
. venv/bin/activate
python3 -m pip install -r ./converter/requirements.txt
export TEST_RESULTS=`ls -1 test_results_*`
python3 ./converter/to_junit.py ${{ matrix.test-mode }}
- name: Upload tests result
if: always()
uses: actions/[email protected]
with:
name: test_results_${{ matrix.test }}
path: ./tests/output.xml
- name: Check job status
id: check
if: always()
run: python3 ./tests/check_tests.py ./tests/output.xml
- name: Save tests result in output and clean
id: clean
if: always()
run: |
echo "::set-output name=${{ matrix.test }}::${{ steps.check.outcome }}"
./CI/clean_slave.sh
end-notify:
name: End build notification with Slack
runs-on: ubuntu-latest
needs: [configure, build, test]
if: always()
steps:
- name: Build result check
id: result
if: |
needs.build.outputs.default == 'success' &&
((needs.configure.outputs.state == 'dev' && needs.test.outputs.clean == 'success' && needs.test.outputs.same == 'success') ||
(needs.configure.outputs.state != 'dev' && needs.build.outputs.k8s == 'success' && needs.build.outputs.iptables == 'success'))
run: echo "::set-output name=status::success"
- name: Notify on slack the build outcome
uses: 8398a7/action-slack@v3
with:
status: custom
fields: workflow,commit,repo,ref
custom_payload: |
{
"attachments":[
{
"title":`${process.env.AS_WORKFLOW}`,
"text": "Build finished",
"color": '${{ steps.result.outputs.status }}' === 'success' ? 'good' : 'danger',
"fields":[{
"title":"Check suite",
"value":"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
},
{
"title":"Git reference",
"value":`${process.env.AS_REPO}@${process.env.AS_REF}`,
},
{
"title":"Commit",
"value":`${process.env.AS_COMMIT}`,
},
{
"title":"Build modes",
"value": '${{ needs.configure.outputs.state }}' == 'dev' ? "*default* ${{ needs.build.outputs.default }}\n*pcn-k8s* skipped\n*pcn-iptables* skipped\n" : "*default* ${{ needs.build.outputs.default }}\n*pcn-k8s* ${{ needs.build.outputs.k8s }}\n*pcn-iptables* ${{ needs.build.outputs.iptables }}\n",
"short": "true"
},
{
"title":"Test modes",
"value": '${{ needs.configure.outputs.state }}' != 'dev' ? "skipped" : "*default clean* ${{ needs.test.outputs.clean }}\n*default same* ${{ needs.test.outputs.same }}",
"short": "true"
}
]
}]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always() # Pick up events even if the job fails or is canceled.
release:
name: Release Polycube
runs-on: ubuntu-latest
needs: [build, configure]
if: needs.configure.outputs.state == 'release'
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v2
with:
# The changelog generation requires the entire history
fetch-depth: 0
submodules: true
persist-credentials: false
- name: Get the latest Polycube release
uses: pozetroninc/[email protected]
id: last-release
with:
repository: ${{ github.repository }}
- name: Generate changelog
id: changelog
uses: metcalfc/[email protected]
with:
myToken: ${{ secrets.GITHUB_TOKEN }}
- name: Save the CHANGELOG as a file
run: |
echo "${{ steps.changelog.outputs.changelog }}" > ./output.md
sed '/pull request/!d' output.md > output_pr.md
sed 's/\[\]/\[view commit\]/' output_pr.md > CHANGELOG.md
sed -i "1s/.*/## Merged PR since tag ${{ steps.last-release.outputs.release }}/" ./CHANGELOG.md
- name: Create the release
uses: actions/create-release@v1
with:
tag_name: ${{ needs.build.outputs.version }}
release_name: Release ${{ needs.build.outputs.version }}
body_path: ./CHANGELOG.md
draft: false
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}