Skip to content

Commit e35c0e8

Browse files
committed
Use downloadArtifact
Signed-off-by: Loïc Minier <[email protected]>
1 parent 8d50985 commit e35c0e8

File tree

1 file changed

+54
-48
lines changed

1 file changed

+54
-48
lines changed

.github/workflows/debos.yml

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -48,56 +48,62 @@ jobs:
4848
uses: actions/github-script@v6
4949
with:
5050
script: |
51-
// search for the latest artifact with this name in this repository
52-
// (not particularly for this workflow run; artifacts we're looking
53-
// for will only be built from a scheduled (cron) run, and not from
54-
// pull requests)
55-
let linux_deb_url = (
56-
await github.rest.actions.listArtifactsForRepo({
57-
owner: context.repo.owner,
58-
repo: context.repo.repo,
59-
name: "linux-deb-links",
60-
page: 1,
61-
per_page: 1,
62-
})
63-
).data.artifacts[0].archive_download_url;
64-
65-
let u_boot_rb1_url = (
66-
await github.rest.actions.listArtifactsForRepo({
67-
owner: context.repo.owner,
68-
repo: context.repo.repo,
69-
name: "u-boot-rb1-links",
70-
page: 1,
71-
per_page: 1,
72-
})
73-
).data.artifacts[0].archive_download_url;
74-
75-
console.log(`URL: ${u_boot_rb1_url}`);
76-
77-
// write files under temp dir
78-
const fs = require('fs');
79-
fs.writeFileSync('linux-deb-links.zip',
80-
Buffer.from(linux_deb_url));
81-
fs.writeFileSync('u-boot-rb1-links.zip',
82-
Buffer.from(u_boot_rb1_url));
83-
84-
const path = require('path');
85-
// Print the current directory
86-
const currentDirectory = process.cwd();
87-
console.log(`Current directory: ${currentDirectory}`);
88-
89-
// List files in the current directory
90-
fs.readdir(currentDirectory, (err, files) => {
91-
if (err) {
92-
console.error('Error reading directory:', err);
93-
return;
51+
// helper to search for the latest artifact with this name in this
52+
// repository (not particularly for this workflow run; artifacts
53+
// we're looking for will only be built from a scheduled (cron)
54+
// run, and not from pull requests)
55+
async function lastArtifactByName(name) {
56+
try {
57+
const response = await github.rest.actions.listArtifactsForRepo({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
name: name,
61+
page: 1,
62+
per_page: 1
63+
});
64+
if (response.data.artifacts && response.data.artifacts.length > 0) {
65+
return response.data.artifacts[0];
66+
} else {
67+
console.log(`Artifact with name ${name} not found`);
68+
}
69+
} catch (error) {
70+
console.error(`Error listing artifact with name ${name}:`, error);
71+
throw error;
72+
}
73+
}
74+
75+
// helper to download an artifact by id and save it into filePath
76+
async function downloadArtifact(artifactId, filePath) {
77+
try {
78+
const response = await github.rest.actions.downloadArtifact({
79+
owner: context.repo.owner,
80+
repo: context.repo.repo,
81+
artifact_id: artifactId,
82+
archive_format: 'zip'
83+
});
84+
fs.writeFileSync(filePath, Buffer.from(response.data));
85+
console.log(`Artifact saved to ${filePath}`);
86+
} catch (error) {
87+
console.error(`Error downloading artifact with ID ${artifactId}:`, error);
88+
throw error;
89+
}
90+
}
91+
92+
try {
93+
let linux_deb_artifact = await listArtifactByName("linux-deb-links");
94+
let u_boot_rb1_artifact = await listArtifactByName("u-boot-rb1-links");
95+
96+
if (!linux_deb_artifact || !u_boot_rb1_artifact) {
97+
console.error('One or both artifacts are missing');
98+
process.exit(1);
9499
}
95-
console.log('Files in current directory:');
96-
files.forEach(file => {
97-
console.log(file);
98-
});
99-
});
100100
101+
await downloadArtifact(owner, repo, linux_deb_artifact_id, 'linux-deb-links.zip');
102+
await downloadArtifact(owner, repo, u_boot_rb1_artifact_id, 'u-boot-rb1-links.zip');
103+
} catch (error) {
104+
console.error('Error retrieving artifacts: ', error);
105+
process.exit(1);
106+
}
101107
102108
- name: Download Linux deb and U-Boot for RB1 from fileserver
103109
run: |

0 commit comments

Comments
 (0)