Hello!
I need your help to correctly define the version numbers for my two branches defined in SonarQube cloud.
On some of my projects, we have a develop branch and a master branch. All of our pull requests are made from develop and merged into it. Once our scope is defined, we merge develop into master.
This action will:
- Define the version number based on the scope (major/minor/bug fixes)
- Launch the deployment of our stacks for production.
Within our two projects, we therefore have the two branches present, including the master branch as the main branch.
Our problem is as follows: Currently, the version number in SonarCloud is not the one we have. I thought about adding the following code to my GitHub workflow, but I’m not sure if this is the right way to do it…
name: 'Release a new version from master'
on:
push:
branches:
- master
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 20
- name: Install dependencies and release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd ci
yarn install
npx semantic-release
- name: Get new version from the latest tag
id: get_version
run: |
git fetch --tags
VERSION=$(git describe --tags --abbrev=0)
echo "NEW_VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Update sonar-project.properties
run: |
sed -i "s/sonar.projectVersion=.*/sonar.projectVersion=${{ steps.get_version.outputs.NEW_VERSION }}/" sonar-project.properties
- name: Commit and Push changes
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add sonar-project.properties
git commit -m "chore(release): update sonar version to ${{ steps.get_version.outputs.NEW_VERSION }}"
git push
- name: Cherry-pick to develop
run: |
git fetch origin develop:develop
git checkout develop
git cherry-pick master
git push origin develop
What we want is for pull requests made from develop to only have the code from the PR as new code, and not code from 2-3 months ago…
To do this, I modified my CI, which is launched on each PR, to add this
name: 'Sonarcloud Scan'
on:
push:
branches:
- master
- develop
jobs:
sonarcloud:
runs-on: ubuntu-latest
env:
SYMFONY_ENV: test
php-version: '7.4'
php-extensions: xml, ctype, intl, pgsql, redis, amqp, gd, imagick
ext-cache-key: cache-v1 # can be any string, change to clear the extension cache.
steps:
- name: Pin node version
uses: actions/setup-node@v2
with:
node-version: '14'
- uses: actions/checkout@v4
- name: Load RP CI stack
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
run: |
cp ./ci/env_docker.ci ./.env
cp ./ci/env.ci ./.env.test
cp ./ci/docker-compose.yml ./docker-compose.test.yml
docker compose -v
docker compose -f docker-compose.test.yml up --build -d
- name: Setup cache environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ env.php-version }}
extensions: ${{ env.php-extensions }}
key: ${{ env.ext-cache-key }}
- name: Cache extensions
uses: actions/cache@v4.2.0
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.php-version }}
extensions: ${{ env.php-extensions }}
tools: composer:v2
- name: Check running containers
run: docker compose -f docker-compose.test.yml ps
- name: Validate composer.json and composer.lock
run: composer validate
- name: Get composer cache directory
id: composercache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v4.2.0
id: redpill-composer-cache
with:
path: 'vendor'
key: redpill-composer-${{ hashFiles('composer.lock') }}
- name: Install composer dependencies
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
if: steps.redpill-composer-cache.outputs.cache-hit != 'true'
run: composer install --prefer-dist --no-progress --no-suggest --no-scripts --no-interaction
- name: Control Symfony installation
run: php bin/console --env=${{ env.SYMFONY_ENV }}
- name: Run test suite on whole project (with coverage)
run: composer test-with-coverage
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@v5.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Unfortunately, I’m a little lost and I’m having trouble figuring out if my approach is correct or not ![]()
What do you think?
Thank you in advance for your help. ![]()
