@@ -100,6 +100,34 @@ jobs:
100100 wait-for-completion : true
101101 sync-status : true
102102
103+ # The artifact was already uploaded by the "Worker" job.
104+ # We need to find the artifact URL and report it below.
105+ - name : Get Artifact URL
106+ id : get_artifact_url
107+ uses : actions/github-script@v6
108+ with :
109+ script : |
110+ const res = await github.rest.actions.listArtifactsForRepo({
111+ owner: context.repo.owner,
112+ repo: context.repo.repo,
113+ })
114+ const artifactName = '${{ steps.set-artifact-name.outputs.artifact_name }}';
115+ // Find the most recent artifact with this name
116+ const artifacts = res.data.artifacts
117+ .filter(a => a.name === artifactName)
118+ .sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
119+
120+ if (artifacts.length > 0) {
121+ const artifact = artifacts[0];
122+ var workflowRunId = artifact.workflow_run_id || ${{ steps.launch_worker.outputs.runId }};
123+ core.setOutput('artifact_url', `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${workflowRunId}/artifacts/${artifact.id}`);
124+ core.setOutput('real_artifact_url', `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${workflowRunId}/artifacts/${artifact.id}`);
125+ core.setOutput('artifact_id', `${artifact.id}`);
126+ console.log(`Detected newest artifact ${artifact.id} from workflow run ${workflowRunId}`);
127+ } else {
128+ core.setFailed(`Artifact ${artifactName} not found`);
129+ }
130+
103131 # Inspired by https://javahelps.com/manage-github-artifact-storage-quota
104132 # This is the part which needs "actions: write" permission.
105133 # Note that the code below wipes everything matched by the filter!
@@ -118,42 +146,20 @@ jobs:
118146 repo: context.repo.repo,
119147 })
120148
149+ const artifact_id = '${{ steps.get_artifact_url.outputs.artifact_id }}';
150+
121151 res.data.artifacts
122152 .filter(({ name }) => name === '${{ steps.set-artifact-name.outputs.artifact_name }}')
123153 .forEach(({ id }) => {
154+ if (id == artifact_id) return;
155+ console.log(`Deleting artifact ${id}`);
124156 github.rest.actions.deleteArtifact({
125157 owner: context.repo.owner,
126158 repo: context.repo.repo,
127159 artifact_id: id,
128160 })
129161 })
130162
131- # The artifact was already uploaded by the "Worker" job.
132- # We need to find the artifact URL and report it below.
133- - name : Get Artifact URL
134- id : get_artifact_url
135- uses : actions/github-script@v6
136- with :
137- script : |
138- const res = await github.rest.actions.listArtifactsForRepo({
139- owner: context.repo.owner,
140- repo: context.repo.repo,
141- })
142- const artifactName = '${{ steps.set-artifact-name.outputs.artifact_name }}';
143- // Find the most recent artifact with this name
144- const artifacts = res.data.artifacts
145- .filter(a => a.name === artifactName)
146- .sort((a, b) => new Date(b.created_at) - new Date(a.created_at));
147-
148- if (artifacts.length > 0) {
149- const artifact = artifacts[0];
150- var workflowRunId = artifact.workflow_run_id || ${{ steps.launch_worker.outputs.runId }};
151- core.setOutput('artifact_url', `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${workflowRunId}/artifacts/${artifact.id}`);
152- core.setOutput('real_artifact_url', `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${workflowRunId}/artifacts/${artifact.id}`);
153- } else {
154- core.setFailed(`Artifact ${artifactName} not found`);
155- }
156-
157163 - name : " GHA-01: Create/update new GH PR comment with link"
158164 if : github.event.pull_request.number > 0
159165 continue-on-error : true
0 commit comments