Update plugin and tools #142
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description | |
# =========== | |
# This workflow builds a docker image each time | |
# commits are pushed to GitHub or a pull request is opened. | |
# It also runs a container of this image to test it. | |
--- | |
name: CI | |
# This workflow is triggered each time commits are pushed to GitHub | |
# and also on each pull request (on the commit that would be created | |
# after the merge) but is not triggered if only markdown files were edited. | |
on: | |
push: | |
branches: | |
- '*' | |
paths-ignore: | |
- '*.md' | |
pull_request: | |
branches: | |
- '*' | |
paths-ignore: | |
- '*.md' | |
# Variables to configure the workflow | |
env: | |
DOCKERFILE_PATH: '.' | |
DOCKERFILE_FILENAME: 'Dockerfile' | |
DOCKER_IMAGE_NAME: 'lequal/sonar-scanner' | |
jobs: | |
# Job that builds the image and upload it as an artifact | |
build: | |
name: Build the docker image | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Build docker image | |
run: docker build -t $DOCKER_IMAGE_NAME $DOCKERFILE_PATH | |
- name: Save Docker image | |
run: docker image save -o image.tar $DOCKER_IMAGE_NAME | |
- name: Upload image as an artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: image | |
path: image.tar | |
# Jobs that test the image and the embedded tools | |
test: | |
name: Test the Docker image | |
runs-on: ubuntu-20.04 | |
needs: build | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Retrieve the image | |
uses: actions/download-artifact@v2 | |
with: | |
name: image | |
- name: Load the image | |
run: docker image load -i image.tar | |
- name: Cache sonar-scanner data | |
uses: actions/cache@v2 | |
with: | |
path: .sonarcache | |
key: sonar-scanner-cache | |
# Run the tests (with the appropriate server image) | |
- name: Test docker image | |
run: | | |
echo "Retrieving the branch name..." | |
if [ "${{ github.event_name }}" = "push" ] | |
then | |
branch=${{ github.ref }} | |
branch=${branch#*/} | |
branch=${branch#*/} | |
else # PR | |
branch=${{ github.head_ref }} | |
fi | |
echo "Cloning the server repo on branch $branch..." | |
if ! git clone https://github.com/cnescatlab/sonarqube.git -b "$branch" tmpserver; | |
then | |
echo "No branch $branch found on the server repository, using develop" | |
git clone https://github.com/cnescatlab/sonarqube.git -b develop tmpserver | |
fi | |
echo "Building the server image..." | |
docker build -t lequal/sonarqube:latest tmpserver/ | |
echo "Testing the scanner image..." | |
echo -e "Results of the CI pipeline\n" > tests_logs.txt | |
cd tests/ | |
python3 -m pip install -r requirements.txt | |
python3 -m pytest -v |& tee -a ../tests_logs.txt | |
# Have the job fail if at least one test failed | |
- name: Check all tests passed | |
run: grep -v -q "FAILED" tests_logs.txt |