Skip to content

Commit

Permalink
Merge pull request #7772 from Zehir/ddf-bundle-workflow
Browse files Browse the repository at this point in the history
Add interaction dispatcher workflow
  • Loading branch information
Zehir authored May 16, 2024
2 parents 06b5f45 + 23d68f6 commit aa8b3be
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# This is a basic workflow to help you get started with Actions

name: Continuous integration DDF Bundles

permissions:
contents: write
pull-requests: write
issues: write
name: CI DDF Bundles

# Controls when the action will run.
on:
Expand Down Expand Up @@ -87,7 +82,7 @@ jobs:
ci-ddf-bundles:
# The type of runner that the job will run on
runs-on: ubuntu-latest
name: Continuous integration DDF Bundles
name: CI DDF Bundles

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down Expand Up @@ -163,7 +158,7 @@ jobs:
# Github artifact
upload-artifact-enabled: true
upload-artifact-filter: 'added,modified'
upload-artifact-retention-days: 3
upload-artifact-retention-days: 30

# DDF Store
# Bundles are uploaded only on the push event when the PR is merged
Expand Down
90 changes: 90 additions & 0 deletions .github/workflows/interactions-dispatcher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Interactions dispatcher

on:
workflow_run:
workflows: ["CI DDF Bundles"]

jobs:
use_output:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
name: 'Interactions dispatcher'

with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
async function upsertComment(owner, repo, issue_number, marker, body) {
const {data: comments} = await github.rest.issues.listComments(
{owner, repo, issue_number});
body = `${marker}\n${body}`;
const existing = comments.filter((c) => c.body.includes(marker));
if (existing.length > 0) {
const last = existing[existing.length - 1];
core.info(`Updating comment ${last.id}`);
await github.rest.issues.updateComment({
owner, repo,
body,
comment_id: last.id,
});
} else {
core.info(`Creating a comment in issue / PR #${issue_number}`);
await github.rest.issues.createComment({issue_number, body, owner, repo});
}
}
async function run(){
const {owner, repo} = context.repo;
core.info("Fetching artifacts list")
const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner,
repo,
run_id: context.payload.workflow_run.id,
});
const matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
return artifact.name === "interaction_data"
})[0];
if(matchArtifact === undefined) {
core.info("No artifact found, stopping the action")
return
}
core.info(`Downloading artifact #${matchArtifact.id}`)
const download = await github.rest.actions.downloadArtifact({
owner,
repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
await github.rest.actions.deleteArtifact({
owner,
repo,
artifact_id: matchArtifact.id
})
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/interaction_data.zip`, Buffer.from(download.data));
await exec.exec(`unzip ${process.env.GITHUB_WORKSPACE}/interaction_data.zip`);
const interaction_data = JSON.parse(fs.readFileSync(`${process.env.GITHUB_WORKSPACE}/interaction_data.json`));
await Promise.all(interaction_data.map(async (data) => {
const {mode, marker, issue_number, body} = data;
if(mode === 'upsert')
await upsertComment(owner, repo, issue_number, marker, body);
else if(mode === 'insert')
await github.rest.issues.createComment({issue_number, body, owner, repo});
}));
}
run();

0 comments on commit aa8b3be

Please sign in to comment.