Skip to content

Commit

Permalink
feat(sonar-dotnet): add project version to scans (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
JossWhittle authored Nov 14, 2024
1 parent cf9d6dc commit 173a61c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/sonar-dotnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,35 @@ jobs:
with:
fetch-depth: 0

- name: determine project version
id: version
uses: actions/github-script@v7.0.1
with:
script: |
var inputs = ${{ toJSON(inputs) }};
var ref = "${{ github.ref_name }}";
if (context.eventName === "push") {
// On push to tag use the tag as the version
var version = `${ref}`;
console.log(`version: ${version}`);
core.setOutput("version", version);
}
else if (context.eventName === "pull_request") {
// On pr use pr number
var pr = context.payload.number;
var version = `pr-${pr}`;
console.log(`version: ${version}`);
core.setOutput("version", version);
}
- name: scan project
run: |
docker run --rm -v $(pwd):/repo -w "/repo/$PROJECT_CONTEXT" $SONAR_IMAGE \
bash -c " \
dotnet /sonar-scanner/SonarScanner.MSBuild.dll begin \
/k:$PROJECT_NAME /name:$PROJECT_NAME \
/v:$PROJECT_VERSION \
/d:sonar.host.url=$SONAR_URL \
/d:sonar.login=$SONAR_TOKEN && \
dotnet restore $PROJECT_FILE && \
Expand All @@ -57,5 +80,6 @@ jobs:
PROJECT_NAME: ${{ inputs.project-name }}
PROJECT_FILE: ${{ inputs.project-file }}
PROJECT_CONTEXT: ${{ inputs.project-context }}
PROJECT_VERSION: ${{ steps.version.outputs.version }}
SONAR_URL: ${{ inputs.sonar-url }}
SONAR_TOKEN: ${{ secrets.sonar-token }}

0 comments on commit 173a61c

Please sign in to comment.