-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1198c89
commit f4a61a6
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Taken from https://www.eliostruyf.com/retrieving-artifact-previous-github-actions-workflow/ | ||
|
||
module.exports = async ({ | ||
github, | ||
context, | ||
core | ||
}) => { | ||
const owner = context.repo.owner; | ||
const repo = context.repo.repo; | ||
|
||
const workflows = await github.rest.actions.listRepoWorkflows({ | ||
owner, | ||
repo | ||
}) | ||
|
||
const workflow = workflows.data.workflows.find(w => w.path.includes(process.env.WORKFLOW_FILENAME)); | ||
|
||
if (!workflow) { | ||
core.setFailed("No workflow found"); | ||
return; | ||
} | ||
|
||
const runs = await github.rest.actions.listWorkflowRuns({ | ||
owner, | ||
repo, | ||
workflow_id: workflow.id, | ||
status: "success", | ||
per_page: 1 | ||
}) | ||
|
||
if (runs.data.total_count === 0) { | ||
core.setFailed("No runs found"); | ||
return; | ||
} | ||
|
||
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | ||
owner, | ||
repo, | ||
run_id: runs.data.workflow_runs[0].id | ||
}); | ||
|
||
const artifact = artifacts.data.artifacts.find(artifact => artifact.name === process.env.ARTIFACT_NAME); | ||
if (artifact) { | ||
const response = await github.rest.actions.downloadArtifact({ | ||
owner, | ||
repo, | ||
artifact_id: artifact.id, | ||
archive_format: 'zip' | ||
}); | ||
require('fs').writeFileSync(process.env.ARTIFACT_FILENAME, Buffer.from(response.data)); | ||
|
||
console.log("Artifact downloaded successfully"); | ||
} else { | ||
core.setFailed("No artifact found"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Pipeline | ||
|
||
on: | ||
schedule: | ||
- cron: "0 6 * * *" | ||
|
||
jobs: | ||
pipeline: | ||
name: Start Pipeline | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
|
||
# We need to make sure that we have actions read access to get the previous artifact | ||
permissions: | ||
contents: read | ||
actions: read | ||
packages: write | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Download artifact | ||
uses: actions/github-script@v6 | ||
continue-on-error: true | ||
env: | ||
WORKFLOW_FILENAME: testing.yml | ||
ARTIFACT_NAME: data | ||
ARTIFACT_FILENAME: data.json | ||
with: | ||
script: | | ||
const script = require('./scripts/download-previous-artifact.js') | ||
await script({github, context, core}) | ||
- name: Modify JSON file | ||
run: | | ||
if [ ! -f data.json ]; then | ||
echo '{"broken_repos": []}' > data.json | ||
fi | ||
cat data.json | jq '.broken_repos += ["new_repo"]' > tmp.json && mv tmp.json data.json | ||
- uses: actions/upload-artifact@v3 | ||
if: always() | ||
with: | ||
name: data | ||
path: data.json | ||
retention-days: 60 |