I am using sonarqube to analyze the code of my project in PHP, everything is set up and partially working, the problem is as follows, I do a check with the Sonar scanner on my pull-requests and merge with the branch master, the analysis it is being carried out, but only in the modified files. I would need to analyze all the code at least on the merge with the master branch. When I go to Project -> code, I only have a few files in the master branch.
I would like to know if there is any parameter that can be passed in the scanner so that it always analyzes all files as it is done with the scanner run locally.
Code scanner
name: Analyze pull request
on:
pull_request:
types: [opened, edited, reopened, synchronize]
branches:
- master
jobs:
SonarQube-Scanner-pull_request:
runs-on: ubuntu-latest
steps:
- name: Setup sonarqube
uses: warchant/setup-sonar-scanner#v1
- name: 'Checkout repository on branch: ${{ github.REF }}'
uses: actions/checkout#v2
with:
ref: ${{ github.HEAD_REF }}
- name: Retrieve entire repository history
run: |
git fetch --prune --unshallow
- name: Run an analysis of the PR
env:
# to get access to secrets.SONAR_TOKEN, provide GITHUB_TOKEN
GITHUB_TOKEN:
run: sonar-scanner
-Dsonar.host.url=
-Dsonar.login=
-Dsonar.projectKey=Project
-Dsonar.qualitygate.wait=true
-Dsonar.pullrequest.key=${{ github.event.number }}
-Dsonar.pullrequest.branch=${{ github.HEAD_REF }}
-Dsonar.pullrequest.base=${{ github.BASE_REF }}
-Dsonar.pullrequest.github.repository=${{ github.repository }}
-Dsonar.scm.provider=git
-Dsonar.java.binaries=/tmp
enter image description here
Thank you for your help
Can you try by giving sonar.projectBaseDir and sonar.sources in sonar analysis properties.
Find more details here Alternate Analysis Directory
Related
I have a problem to deploy a symfony project with github action. I can connect with ssh and execute a git pull or a php bin/console doctrine:migrations:migrate, but it's impossible to use the compose command.
I followed the various explanations of ionos (https://www.ionos.com/digitalguide/websites/web-development/using-php-composer-in-ionos-webhosting-packages/) but github actions tells me "Could not open input file: composer.phar".
Here is my script if anyone has an idea
name: CD
on:
push:
branches: [ develop ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: SSH and Deploy
uses: appleboy/ssh-action#master
with:
host: ${{ secrets.APP_HOST }}
username: ${{ secrets.APP_USER }}
password: ${{ secrets.APP_PASS }}
port: 22
script: |
cd /homepages/14/d800745077/htdocs/clickandbuilds/dashJob
git pull
/usr/bin/php8.0-cli composer.phar i
/usr/bin/php8.0-cli bin/console d:m:m -n
It depends on your current working directory.
If the repository has composer.phar in your remote repository you just pulled, then the command would work.
If not, replace it with a find . -name "composer.phar" to check where that file is in the repository.
IONOS is offering a tooling named Deploy Now that should ease your setup. For PHP you can find docs here.
I want to check the code coverage percentage in the Github Action CI on push and pull requests. I'm using Symfony. I've found actions for Javascript but not for PHP or Symfony-based.
I've already created a GitHub action workflow which is as below:
name: Running Code Coverage
on: [push, pull_request]
jobs:
build:
name: Code Coverage
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [8.1]
steps:
- name: Checkout repository
uses: actions/checkout#v2
- name: Set up PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php#v2
with:
php-version: ${{ matrix.php-version }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action#v1
with:
token: ${{ secrets.CODECOV_SECRET_TOKEN }}
fail_ci_if_error: true
files: ./coverage_report.xml
But I cannot achieve my end goal using the above as it uploads the code coverage to codecov and there I can see the %age.
My goal is that the CI should fail when the code coverage is below a threshold like 100%.
Referencing from the official docs on threshold:
threshold (number): Allow the coverage to drop by X%, and posting a success status.
Here is an example codecov.yml reference from the same docs:
coverage:
status:
project:
default:
# basic
target: auto
threshold: 0%
base: auto
flags:
- unit
paths:
- "src"
# advanced settings
branches:
- master
if_ci_failed: error #success, failure, error, ignore
informational: false
only_pulls: false
I can update my code on cPanel using git version control. At the moment I then have to go to the terminal and run the artisan migrate command. Can this be added together to make one step?
This is my workflow:
This is a basic workflow to help you get started with Actions
name: CI
Controls when the workflow will run
on:
Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ main ]
Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
This workflow contains a single job called "build"
job_one:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: executing remote ssh commands using ssh keys
uses: appleboy/ssh-action#master
with:
host: hostgoeshere
username: uknet
key: ${{ secrets.CPANEL }}
#password: passwordgoeshere
port: 7822
script: |
cd /home/uknet/public_html/master
pwd
git add .
git stash
git pull origin main
git status
Is it possible to add a terminal line at the bottom with php artisan migrate?
I have my own php image, which I would like to use for my project to run tests on.
container: rela589n/doctrine-event-sourcing-php:latest
services:
test_db:
image: postgres:13-alpine
env:
POSTGRES_DB: des
POSTGRES_USER: des_user
POSTGRES_PASSWORD: p#$$w0rd
steps:
- uses: actions/checkout#v2
- whatever_needed_to_run_tests_inside_container
This fails on checkout action with such error:
EACCES: permission denied, open '/__w/doctrine-event-sourcing/doctrine-event-sourcing/6977c4d4-3881-44e9-804e-ae086752556e.tar.gz'
And this is logical as in fresh docker container there's no such folder structure. What i thought to do is run checkout action inside virtual machine provided runs-on: ubuntu-20.04 and configure volume for docker so that it will have access to code. However I have no idea neither is it a good practice to do this way nor how to implement this. I guess even if it is possible to do this way it won't work for other actions.
Had the same issue when trying to use my own Docker image. In my case, installing everything I need on the fly was not an option, so I had to fix this issue.
It appears that GitHub runs the Docker image with user 1001 named runner and group 121 named docker. After adding the group, adding the user and adding the user to sudoers the problem was solved.
Notice that the checkout path starts with /_w which is strange. If I perform actions/checkout#v2 without my container, the path is /home/runner. Not sure how to solve that yet.
Thanks, this really helped me to find the issue when trying to deploy a CDK project from within a Docker container on Github Actions.
I was getting a permission denied error after checking out the code, and trying to deploy it.
Error: EACCES: permission denied, mkdir '/__w/arm-test/arm-test/cdk.out/asset.7d21b14f781f8b0e4ebb3b30c66614a80f71a2c1637298e5557a97662fce0abe'
This issue had the workaround of running the container with the same user and group as the Github Actions runner, so that it matched with the permissions of the source code directory: https://github.com/actions/runner/issues/691
jobs:
configure:
runs-on: ubuntu-latest
outputs:
uid_gid: ${{ steps.get-user.outputs.uid_gid }}
steps:
- id: get-user
run: echo "::set-output name=uid_gid::$(id -u):$(id -g)"
clone-and-install:
needs: configure
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/vscode/devcontainers/base:ubuntu
options: --user ${{ needs.configure.outputs.uid_gid }}
steps:
- uses: actions/checkout#v2
I am trying to integrate sonarcloud with Bitbucket pipeline. I have a simple test project with single file named index.php consisting few lines.
I am exactly not sure what method should I follow.
I have created sonar-project.properties files that consists following lines.
sonar.sourceEncoding=UTF-8
sonar.host.url=https://sonarcloud.io/dashboard?id=first_ftp
sonar.projectKey=first_ftp
Here is my yml file
image: aariacarterweir/lamp-gitftp:latest
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &build-test-sonarcloud
name: Build, test and analyze on SonarCloud
caches:
- node
- sonar
script:
- npm install --quiet
- npm run test -- --code-coverage --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox
- pipe: sonarsource/sonarcloud-scan:0.1.5
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions="**/testing/**,**/*.spec.ts" -Dsonar.typescript.lcov.reportPaths=coverage/lcov.info'
When I check into sonarcloud website, It tells
The main branch has no lines of code
Can anybody help me how to configure properly sonarcloud with bitbucket for php project.
I've had the same issue - in my case it was because of the name of the project - it was called ---------Test, and apparently, by default, Sonar will treat that as a test assembly and will exclude it from analysis.
Before running code analysis in bitbucket pipelines, you would have to first manually run analysis(only once). By following below steps.