Skip to content

Commit

Permalink
feat: Add a workflow status reporting workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
abensonca committed Nov 14, 2023
1 parent 3ceb8d4 commit b3456a2
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/workflowStatus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Workflow-Status
on:
workflow_dispatch:
schedule:
- cron: '00 15 * * 1,2,3,4,5'
jobs:
Report-Status:
runs-on: ubuntu-latest
concurrency:
group: workflowStatus-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "The ${{ github.repository }} repository has been cloned to the runner."
- name: "Set environmental variables"
run: |
echo "GALACTICUS_EXEC_PATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
- name: Install tools
run: |
sudo apt -y update
sudo apt install -y libjson-pp-perl
- name: Retrieve and report status
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SLACK_WEBHOOK_STATUS_URL: ${{ secrets.SLACK_WEBHOOK_STATUS_URL }}
run: |
cd $GALACTICUS_EXEC_PATH
git config --global --add safe.directory $GALACTICUS_EXEC_PATH
./scripts/workflowStatus.pl
42 changes: 42 additions & 0 deletions scripts/workflowStatus.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env perl
use strict;
use warnings;
use JSON;
use Data::Dumper;

my $repo = "libmatheval";

my @workflows =
(
{
file => "cicd.yml",
name => "CI/CD"
}
);

foreach my $workflow ( @workflows ) {

my $json;
open(my $gh,"gh run list --workflow ".$workflow->{'file'}." --branch master --json conclusion |");
while ( my $line = <$gh> ) {
$json .= $line;
}
close($gh);
my $data = decode_json($json);
my $status = ":question:";
foreach my $run ( @{$data} ) {
if ( $run->{'conclusion'} eq "" ) {
$status = ":clock2:";
} elsif ( $run->{'conclusion'} eq "failure" ) {
$status = ":x:";
} elsif ( $run->{'conclusion'} eq "success" ) {
$status = ":white_check_mark:";
}
last
unless ( $status eq ":question:" );
}
system("curl -X POST -H 'Content-type: application/json' --data '{\"repo\":\"".$repo."\",\"workflow\":\"".$workflow->{'name'}."\",\"status\":\"".$status."\",\"url\":\"https://github.com/galacticusorg/".$repo."/actions/workflows/".$workflow->{'file'}."\"}' ".$ENV{'SLACK_WEBHOOK_STATUS_URL'});

}

exit;

0 comments on commit b3456a2

Please sign in to comment.