From b3456a21fee85cbbb552d6897532b94940f535a7 Mon Sep 17 00:00:00 2001 From: Andrew Benson Date: Tue, 14 Nov 2023 11:58:40 -0800 Subject: [PATCH] feat: Add a workflow status reporting workflow --- .github/workflows/workflowStatus.yml | 30 ++++++++++++++++++++ scripts/workflowStatus.pl | 42 ++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 .github/workflows/workflowStatus.yml create mode 100755 scripts/workflowStatus.pl diff --git a/.github/workflows/workflowStatus.yml b/.github/workflows/workflowStatus.yml new file mode 100644 index 0000000..10fba01 --- /dev/null +++ b/.github/workflows/workflowStatus.yml @@ -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 diff --git a/scripts/workflowStatus.pl b/scripts/workflowStatus.pl new file mode 100755 index 0000000..0e32761 --- /dev/null +++ b/scripts/workflowStatus.pl @@ -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;