Browse Source

Patch/download artifacts workflow runs (#40)

* manually adding branch filter

* fixing the workflow run loop

* remembering how to do Promises

* updating download artifact test workflow

* adding debugging code

* adding debugging code

* fixing the raw data filtering

* fixing variable name

* fixing more data model changes

* Removing the required branch filter

* switching up how we test the BRANCH download

* fixing syntax

* Adding debugging code

* fixing the branch test

* checking on the sort of the runs

* fixing syntax

* switching the order of sorting

* fixing up the test workflow

* reworking the tests

* more fixing of the tests

* wet spaghetti

* fixing the tests

* cleaning up some of the code

* Adding another test

* Adding easier testing

* Adding some curly braces

* Removing some debugging code
pull/41/head
Joseph Flinn 4 years ago committed by GitHub
parent
commit
c1fa8e0987
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 82
      .github/workflows/test-download-artifacts.yml
  2. 3
      .github/workflows/upload-test-artifacts.yml
  3. 67
      download-artifacts/main.js

82
.github/workflows/test-download-artifacts.yml

@ -4,6 +4,11 @@ name: Test Download Artifacts Action @@ -4,6 +4,11 @@ name: Test Download Artifacts Action
on:
workflow_dispatch:
inputs: {}
workflow_run:
workflows:
- Upload Test Artifacts
types:
- completed
jobs:
download-latest:
@ -16,16 +21,18 @@ jobs: @@ -16,16 +21,18 @@ jobs:
- name: Download
uses: ./download-artifacts
with:
workflow: upload.yml
workflow: upload-test-artifacts.yml
artifacts: artifact
path: artifact
- name: Test
run: cat artifact/sha | grep $GITHUB_SHA
run: |
cat artifact/sha
echo $GITHUB_SHA
download-branch:
name: Download BRANCH
download-master:
name: Download master
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/master'
steps:
@ -35,14 +42,39 @@ jobs: @@ -35,14 +42,39 @@ jobs:
- name: Download
uses: ./download-artifacts
with:
workflow: upload.yml
workflow: upload-test-artifacts.yml
artifacts: artifact
path: artifact
branch: master
- name: Test
run: cat artifact/sha | grep $GITHUB_SHA
run: |
cat artifact/sha
echo $GITHUB_SHA
download-branch:
name: Download current branch
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f
- name: Extract branch name
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Download
uses: ./download-artifacts
with:
workflow: upload-test-artifacts.yml
artifacts: artifact
path: artifact
branch: ${{ steps.extract_branch.outputs.branch }}
- name: Test
run: |
cat artifact/sha
echo $GITHUB_SHA
download-pr:
name: Download Pull Request
@ -55,13 +87,15 @@ jobs: @@ -55,13 +87,15 @@ jobs:
- name: Download
uses: ./download-artifacts
with:
workflow: upload.yml
workflow: upload-test-artifacts.yml
artifacts: artifact
path: artifact
pr: ${{github.event.pull_request.number}}
- name: Test
run: cat artifact/sha | grep $GITHUB_SHA
run: |
cat artifact/sha
echo $GITHUB_SHA
download-all:
@ -74,12 +108,14 @@ jobs: @@ -74,12 +108,14 @@ jobs:
- name: Download
uses: ./download-artifacts
with:
workflow: upload.yml
workflow: upload-test-artifacts.yml
- name: Test
run: |
cat artifact1/sha1 | grep $GITHUB_SHA
cat artifact2/sha2 | grep $GITHUB_SHA
ls -atlh
cat sha
cat sha1
cat sha2
download-multiple:
@ -92,15 +128,15 @@ jobs: @@ -92,15 +128,15 @@ jobs:
- name: Download
uses: ./download-artifacts
with:
workflow: upload.yml
workflow: upload-test-artifacts.yml
artifacts: 'artifact1,
artifact2'
artifact2'
- name: Test
run: |
ls -alth
cat artifact1/sha1 | grep $GITHUB_SHA
cat artifact2/sha2 | grep $GITHUB_SHA
ls -atlh
cat sha1
cat sha2
download-wildcard:
@ -113,14 +149,14 @@ jobs: @@ -113,14 +149,14 @@ jobs:
- name: Download
uses: ./download-artifacts
with:
workflow: upload.yml
workflow: upload-test-artifacts.yml
artifacts: '*.txt'
- name: Test
run: |
ls -alth
cat artifact1.txt/sha1 | grep $GITHUB_SHA
cat artifact2.txt/sha2 | grep $GITHUB_SHA
ls -atlh
cat sha1
cat sha2
download-conclusion:
@ -133,10 +169,12 @@ jobs: @@ -133,10 +169,12 @@ jobs:
- name: Download
uses: ./download-artifacts
with:
workflow: upload.yml
workflow: upload-test-artifacts.yml
artifacts: artifact
path: artifact
workflow_conclusion: ''
- name: Test
run: cat artifact/sha | grep $GITHUB_SHA
run: |
cat artifact/sha
echo $GITHUB_SHA

3
.github/workflows/upload-test-artifacts.yml

@ -4,6 +4,9 @@ name: Upload Test Artifacts @@ -4,6 +4,9 @@ name: Upload Test Artifacts
on:
workflow_dispatch:
inputs: {}
push:
paths:
- "download-artifacts/**"
jobs:
upload:

67
download-artifacts/main.js

@ -24,9 +24,7 @@ async function main() { @@ -24,9 +24,7 @@ async function main() {
const client = github.getOctokit(token)
console.log("==> Workflow:", workflow)
console.log("==> Repo:", owner + "/" + repo)
console.log("==> Conclusion:", workflowConclusion)
if (pr) {
@ -58,40 +56,46 @@ async function main() { @@ -58,40 +56,46 @@ async function main() {
}
if (!runID) {
for await (const runs of client.paginate.iterator(client.actions.listWorkflowRuns, {
let runs = await client.actions.listWorkflowRuns({
owner: owner,
repo: repo,
workflow_id: workflow,
branch: branch,
event: event,
workflow_id: workflow
}).then(workflowRunsResponse => {
return workflowRunsResponse.data.workflow_runs
.sort((a, b) => {
a_date = new Date(a.created_at)
b_date = new Date(b.created_at)
// descending order
return b_date - a_date
})
})
if (branch) {
runs = runs.filter(run => run.head_branch == branch)
}
)) {
for (const run of runs.data) {
if (commit && run.head_sha != commit) {
continue
}
if (runNumber && run.run_number != runNumber) {
continue
}
if (workflowConclusion && (workflowConclusion != run.conclusion && workflowConclusion != run.status)) {
for (const run of runs) {
if (commit && run.head_sha != commit) {
continue
}
if (runNumber && run.run_number != runNumber) {
continue
}
if (workflowConclusion && (workflowConclusion != run.conclusion && workflowConclusion != run.status)) {
continue
}
if (checkArtifacts) {
let artifacts = await client.actions.listWorkflowRunArtifacts({
owner: owner,
repo: repo,
run_id: run.id,
})
if (artifacts.data.artifacts.length == 0) {
continue
}
if (checkArtifacts) {
let artifacts = await client.actions.listWorkflowRunArtifacts({
owner: owner,
repo: repo,
run_id: run.id,
})
if (artifacts.data.artifacts.length == 0) {
continue
}
}
runID = run.id
break
}
if (runID) {
break
}
runID = run.id
break
}
}
@ -119,8 +123,9 @@ async function main() { @@ -119,8 +123,9 @@ async function main() {
return artifactNames.map(name => matchesWithRegex(artifact.name, name)).reduce((prevValue, currValue) => prevValue || currValue)
})
if (artifactsToDownload.length == 0)
if (artifactsToDownload.length == 0) {
throw new Error("no artifacts found")
}
for (const artifact of artifactsToDownload) {
console.log("==> Artifact:", artifact.id)

Loading…
Cancel
Save