Skip to content

Commit 5859bec

Browse files
authored
ci: make commit sha consistent across workflows (#680)
1 parent 92d800a commit 5859bec

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

.github/workflows/basic-test.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Essential Test
22

33
on: workflow_call
44

5+
env:
6+
COMMIT_SHA: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
7+
58
jobs:
69
lint:
710
runs-on: ubuntu-latest
@@ -18,7 +21,7 @@ jobs:
1821
- name: Archive lint report results
1922
uses: actions/upload-artifact@v4
2023
with:
21-
name: lint-report-${{ github.sha }}
24+
name: lint-report-${{ env.COMMIT_SHA }}
2225
path: reports
2326

2427
build:
@@ -32,13 +35,14 @@ jobs:
3235
- name: Archive build result
3336
uses: actions/upload-artifact@v4
3437
with:
35-
name: library-dist-${{ github.sha }}
38+
name: library-dist-${{ env.COMMIT_SHA }}
3639
path: dist
3740

3841
unit-test:
3942
strategy:
4043
matrix:
41-
os: [ubuntu-latest, windows-latest]
44+
os: [ubuntu-latest] # to have test faster
45+
# os: [ubuntu-latest, windows-latest]
4246
node-version: [20, 22]
4347
runs-on: ${{ matrix.os }}
4448
steps:
@@ -61,5 +65,5 @@ jobs:
6165
name: Archive coverage report
6266
uses: actions/upload-artifact@v4
6367
with:
64-
name: ngx-deploy-npm-coverage-report-${{ github.sha }}
68+
name: ngx-deploy-npm-coverage-report-${{ env.COMMIT_SHA }}
6569
path: coverage/packages/ngx-deploy-npm/lcov.info

.github/workflows/sonar-pr.yml

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,59 @@ jobs:
3535
JSON.stringify(${{ github.event.workflow_run }}, null, 2)
3636
3737
# Download reports
38-
- uses: ./.github/actions/download-coverage-report
39-
with:
40-
sha: ${{ github.event.workflow_run.head_sha }}
41-
- uses: ./.github/actions/download-lint-report
38+
- name: 'Download reports'
39+
uses: actions/github-script@v6
4240
with:
43-
sha: ${{ github.event.workflow_run.head_sha }}
41+
script: |
42+
async function downloadArtifact(artifactName) {
43+
console.log(`Looking for artifact: ${artifactName}`);
44+
45+
let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
46+
owner: context.repo.owner,
47+
repo: context.repo.repo,
48+
run_id: context.payload.workflow_run.id,
49+
});
50+
51+
console.log('Available artifacts:', allArtifacts.data.artifacts.map(a => a.name));
52+
53+
let matchArtifact = allArtifacts.data.artifacts.find((artifact) => {
54+
return artifact.name === artifactName;
55+
});
56+
57+
if (!matchArtifact) {
58+
throw new Error(`Artifact "${artifactName}" not found!`);
59+
}
60+
61+
let download = await github.rest.actions.downloadArtifact({
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
artifact_id: matchArtifact.id,
65+
archive_format: 'zip',
66+
});
67+
68+
let fs = require('fs');
69+
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/${artifactName}.zip`, Buffer.from(download.data));
70+
71+
return artifactName;
72+
}
73+
74+
const sha = context.payload.workflow_run.head_sha;
75+
76+
// Download both artifacts
77+
await Promise.all([
78+
downloadArtifact(`ngx-deploy-npm-coverage-report-${sha}`),
79+
downloadArtifact(`lint-report-${sha}`)
80+
]);
81+
82+
- name: 'Extract reports'
83+
run: |
84+
# Extract coverage report
85+
mkdir -p coverage/packages/ngx-deploy-npm
86+
unzip ngx-deploy-npm-coverage-report-*.zip -d coverage/packages/ngx-deploy-npm
87+
88+
# Extract lint report
89+
mkdir -p reports
90+
unzip lint-report-*.zip -d reports
4491
4592
- name: SonarCloud Scan
4693
uses: sonarsource/sonarcloud-github-action@master

0 commit comments

Comments
 (0)