Skip to content

Commit

Permalink
WIP: Add support for getting artifacts from an issue_number
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeharder committed Nov 15, 2024
1 parent 81f812e commit c5a110f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
29 changes: 20 additions & 9 deletions .github/actions/get-keyvalue-artifacts/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,36 @@ const { extractInputs } = require('../context');
module.exports = async ({ github, context, core }) => {
let owner = process.env.OWNER;
let repo = process.env.REPO;
let issue_number = parseInt(process.env.ISSUE_NUMBER || "");
let run_id = parseInt(process.env.RUN_ID || "");

if (!owner || !repo || !run_id) {
if (!owner || !repo || !(issue_number || run_id)) {
let inputsFromContext = await extractInputs(github, context, core);
owner = owner || inputsFromContext.owner;
repo = repo || inputsFromContext.repo;
issue_number = issue_number || inputsFromContext.issue_number;
run_id = run_id || inputsFromContext.run_id;
}

core.info(`listWorkflowRunArtifacts(${owner}, ${repo}, ${run_id})`);
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: owner,
repo: repo,
run_id: run_id,
});
/** @type {string[]} */
let artifactNames = [];

const artifactNames = artifacts.data.artifacts.map((a) => a.name);
core.info(`artifactNames: ${JSON.stringify(artifactNames)}`)
if (run_id) {
// List artifacts from a single run_id
core.info(`listWorkflowRunArtifacts(${owner}, ${repo}, ${run_id})`);
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: owner,
repo: repo,
run_id: run_id,
});

artifactNames = artifacts.data.artifacts.map((a) => a.name);
}
else {
// TODO: List all artifacts of issue_number
}

core.info(`artifactNames: ${JSON.stringify(artifactNames)}`)
for (const artifactName of artifactNames) {
// If artifactName has format "key=value", add the key and value as env vars.
// If artifactName does not contain "=", ignore.
Expand Down
4 changes: 4 additions & 0 deletions .github/actions/get-keyvalue-artifacts/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ inputs:
run_id:
description: The unique identifier of the workflow run.
required: false
issue_number:
description: The number that identifies the issue.
required: false

runs:
using: composite
Expand All @@ -23,6 +26,7 @@ runs:
OWNER: ${{ inputs.owner }}
REPO: ${{ inputs.repo }}
RUN_ID: ${{ inputs.run_id }}
ISSUE_NUMBER: ${{ inputs.issue_number }}
with:
script: |
const action = require('./.github/actions/get-keyvalue-artifacts/action.js')
Expand Down

0 comments on commit c5a110f

Please sign in to comment.