-
Notifications
You must be signed in to change notification settings - Fork 3
/
get-last-successful-workflow-run-for-artifacts.sh
executable file
·131 lines (110 loc) · 5 KB
/
get-last-successful-workflow-run-for-artifacts.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
#
# Copyright contributors to the Galasa project
#
# SPDX-License-Identifier: EPL-2.0
#
#-----------------------------------------------------------------------------------------
#
# Objectives: Get the last successful workflow run ID to get artifacts from if the current
# workflow run has not built a particular module.
#
#-----------------------------------------------------------------------------------------
# Where is this script executing from ?
BASEDIR=$(dirname "$0");pushd $BASEDIR 2>&1 >> /dev/null ;BASEDIR=$(pwd);popd 2>&1 >> /dev/null
# echo "Running from directory ${BASEDIR}"
export ORIGINAL_DIR=$(pwd)
# cd "${BASEDIR}"
cd "${BASEDIR}/.."
PROJECT_DIR=$(pwd)
#-----------------------------------------------------------------------------------------
#
# Set Colors
#
#-----------------------------------------------------------------------------------------
bold=$(tput bold)
underline=$(tput sgr 0 1)
reset=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 76)
white=$(tput setaf 7)
tan=$(tput setaf 202)
blue=$(tput setaf 25)
#-----------------------------------------------------------------------------------------
#
# Headers and Logging
#
#-----------------------------------------------------------------------------------------
underline() { printf "${underline}${bold}%s${reset}\n" "$@" ; }
h1() { printf "\n${underline}${bold}${blue}%s${reset}\n" "$@" ; }
h2() { printf "\n${underline}${bold}${white}%s${reset}\n" "$@" ; }
debug() { printf "${white}[.] %s${reset}\n" "$@" ; }
info() { printf "${white}[➜] %s${reset}\n" "$@" ; }
success() { printf "${white}[${green}✔${white}] ${green}%s${reset}\n" "$@" ; }
error() { printf "${white}[${red}✖${white}] ${red}%s${reset}\n" "$@" ; }
warn() { printf "${white}[${tan}➜${white}] ${tan}%s${reset}\n" "$@" ; }
bold() { printf "${bold}%s${reset}\n" "$@" ; }
note() { printf "\n${underline}${bold}${blue}Note:${reset} ${blue}%s${reset}\n" "$@" ; }
#-----------------------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------------------
function usage {
info "Syntax: get-last-successful-workflow-run-for-artifacts.sh [OPTIONS]"
cat << EOF
Options are:
-h | --help : Display this help text
--repo The repository for this GitHub Actions workflow
EOF
}
#-----------------------------------------------------------------------------------------
# Process parameters
#-----------------------------------------------------------------------------------------
repo=""
while [ "$1" != "" ]; do
case $1 in
-h | --help ) usage
exit
;;
--repo ) repo="$2"
shift
;;
* ) error "Unexpected argument $1"
usage
exit 1
esac
shift
done
#-----------------------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------------------
function get_last_successful_workflow_id() {
MODULE=$1
SKIPPED_JOB_NAME=$2
h1 "Getting the last successful workflow run ID that has stored artifacts for the ${MODULE} module"
h2 "Using the GitHub CLI to list the successful runs of the Main Build Orchestrator workflow"
gh run list --repo "${repo}" --workflow "Main Build Orchestrator" --status success | tee gh-run-list.log
h2 "Extracting the run IDs from the output"
output=$(cat gh-run-list.log 2>&1)
run_ids=($(echo "$output" | grep -oE '[0-9]{11}'))
echo "Extracted IDs: ${run_ids[@]}"
for run_id in "${run_ids[@]}"; do
echo "Checking if the run ${run_id} ran the ${MODULE} build or skipped it"
if gh run view ${run_id} --log 2>&1 | grep -q "${SKIPPED_JOB_NAME}"; then
echo "The build of module ${MODULE} was skipped so will have no artifacts in this workflow run."
else
echo "The build of module ${MODULE} was not skipped - artifacts should be available to download!"
echo "${MODULE}_artifacts_id=${run_id}" >> $GITHUB_OUTPUT
break
fi
done
}
get_last_successful_workflow_id openapi2beans "Buildutils is unchanged"
get_last_successful_workflow_id galasabld "Buildutils is unchanged"
get_last_successful_workflow_id platform "Platform is unchanged"
get_last_successful_workflow_id wrapping "Wrapping is unchanged"
get_last_successful_workflow_id gradle "Gradle is unchanged"
get_last_successful_workflow_id maven "Maven is unchanged"
get_last_successful_workflow_id framework "Framework is unchanged"
get_last_successful_workflow_id extensions "Extensions is unchanged"
get_last_successful_workflow_id managers "Managers is unchanged"
get_last_successful_workflow_id obr "OBR is unchanged"