Skip to content

Commit

Permalink
Add an artifact pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofer-Julian committed Nov 14, 2024
1 parent 1198c89 commit f4a61a6
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
56 changes: 56 additions & 0 deletions .github/scripts/download-previous-artifact.js
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");
}
}
46 changes: 46 additions & 0 deletions .github/workflows/artifact_pipeline.yml
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

0 comments on commit f4a61a6

Please sign in to comment.