Skip to content

Commit

Permalink
cicd: correct workflow to download latest artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazrius committed Jul 9, 2023
1 parent 982b243 commit ac46c88
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sonar-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ jobs:
- name: Upload Sonar Build
uses: actions/upload-artifact@v3
with:
name: sonar-build-PR
name: sonar-build
path: ${{ env.BUILD_WRAPPER_OUT_DIR }}
31 changes: 27 additions & 4 deletions .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,40 @@ on:
jobs:
build:
runs-on: windows-latest
if: github.event.workflow_run.conclusion == 'success'
env:
SONAR_SCANNER_VERSION: 4.6.1.2450
SONAR_SERVER_URL: "https://sonarcloud.io"
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
COVERAGE_RESULTS: coverage_results
steps:
- name: Download Sonar Build
uses: actions/download-artifact@v3
- uses: actions/checkout@v3
with:
name: sonar-build-PR
path: ${{ env.BUILD_WRAPPER_OUT_DIR }}
repository: ${{ github.event.workflow_run.head_repository.full_name }}
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
- name: 'Download Artifacts'
uses: actions/github-script@v6
with:
script: |
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.payload.workflow_run.id,
});
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name == "sonar-build"
})[0];
let download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
let fs = require('fs');
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/sonar-build.zip`, Buffer.from(download.data));
- name: 'Unzip Sonar Build'
run: Expand-Archive -Force sonar-build.zip ${{ env.BUILD_WRAPPER_OUT_DIR }}
- name: Run sonar-scanner
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down

0 comments on commit ac46c88

Please sign in to comment.