Skip to content

Commit 7d61aef

Browse files
authored
Merge pull request #65780 from aireilly/add-distro-check
adding new get-updated-distros.sh script and updated Travis build
2 parents 4a27b7f + 793c22b commit 7d61aef

File tree

2 files changed

+64
-25
lines changed

2 files changed

+64
-25
lines changed

.travis.yml

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,32 @@ jobs:
1313
- CAN_FAIL=true
1414

1515
include:
16-
- stage: cache-and-validate
17-
name: "Create install cache and validate updated assemblies"
16+
- stage: validate-and-build
17+
name: "Validate and build"
1818
install:
1919
- gem install asciidoctor asciidoctor-diagram rouge
2020
- pip3 install pyyaml aura.tar.gz
2121
script:
22-
# Fail if Asciidoctor encounters errors. Pass otherwise.
22+
# Fail if Asciidoctor encounters errors. Pass otherwise. Then, build updated distros
2323
- chmod +x ./scripts/check-asciidoctor-build.sh
24+
- chmod +x ./scripts/get-updated-distros.sh
2425
- ./scripts/check-asciidoctor-build.sh || travis_terminate 1
26+
- |
27+
./scripts/get-updated-distros.sh |
28+
while read -r filename; do
29+
if [ "$filename" == "_topic_maps/_topic_map.yml" ]; then python3 build.py --distro openshift-enterprise --product "OpenShift Container Platform" --version 4.14 --no-upstream-fetch
2530
26-
- stage: build
27-
if: branch IN (main, enterprise-4.13, enterprise-4.14)
28-
name: "Build openshift-enterprise distro"
29-
script:
30-
- python3 build.py --distro openshift-enterprise --product "OpenShift Container Platform" --version 4.14 --no-upstream-fetch && python3 makeBuild.py
31+
elif [ "$filename" == "_topic_maps/_topic_map_osd.yml" ]; then python3 build.py --distro openshift-dedicated --product "OpenShift Dedicated" --version 4 --no-upstream-fetch
3132
32-
- # stage name not required, will continue to use `build`
33-
if: branch IN (main, enterprise-4.13, enterprise-4.14)
34-
name: "Build openshift-dedicated distro"
35-
script:
36-
- python3 build.py --distro openshift-dedicated --product "OpenShift Dedicated" --version 4 --no-upstream-fetch && python3 makeBuild.py
33+
elif [ "$filename" == "_topic_maps/_topic_map_ms.yml" ]; then python3 build.py --distro microshift --product "Microshift" --version 4 --no-upstream-fetch
3734
38-
- # stage name not required, will continue to use `build`
39-
if: branch IN (main, enterprise-4.13, enterprise-4.14)
40-
name: "Build openshift-rosa distro"
41-
script:
42-
- python3 build.py --distro openshift-rosa --product "Red Hat OpenShift Service on AWS" --version 4 --no-upstream-fetch && python3 makeBuild.py
35+
elif [ "$filename" == "_topic_maps/_topic_map_rosa.yml" ]; then python3 build.py --distro openshift-rosa --product "Red Hat OpenShift Service on AWS" --version 4 --no-upstream-fetch
4336
44-
- # stage name not required, will continue to use `build`
45-
if: branch IN (main, enterprise-4.13, enterprise-4.14)
46-
name: "Build microshift distro"
47-
script:
48-
- python3 build.py --distro microshift --product "Microshift" --version 4 --no-upstream-fetch && python3 makeBuild.py
37+
elif [ "$filename" == "_distro_map.yml" ]; then python3 build.py --distro openshift-enterprise --product "OpenShift Container Platform" --version 4.14 --no-upstream-fetch
38+
fi
39+
done
40+
41+
if [ -d "drupal-build" ]; then python3 makeBuild.py; fi
4942
5043
# Remove Vale stage until PR commenting feature is ready
5144
# - stage: check-with-vale
@@ -78,8 +71,7 @@ jobs:
7871
- ./autopreview.sh
7972

8073
stages:
81-
- cache-and-validate
82-
- build
8374
- netlify
75+
- validate-and-build
8476
#- check-with-vale
8577
#- automerge

scripts/get-updated-distros.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# Returns a list of updated _topic_map.yml files.
4+
# The list includes any topic maps that are themselves modified, and indirectly modifed topic maps where incldued AsciiDoc files have been updated.
5+
6+
# Get the *.adoc and distro maps files in the pull request
7+
FILES=$(git diff --name-only HEAD HEAD~$(git rev-list --count --no-merges origin/main..) --diff-filter=d "*.yml" "*.adoc" ':(exclude)_unused_topics/*')
8+
REPO_PATH=$(git rev-parse --show-toplevel)
9+
# Init an empty array
10+
DISTROS=()
11+
12+
# Get the modules in the PR, search for assemblies that include them, and concat with any updated assemblies files
13+
14+
MODULES=$(echo "$FILES" | awk '/modules\/(.*)\.adoc/')
15+
if [ "${MODULES}" ]
16+
then
17+
# $UPDATED_ASSEMBLIES is the list of assemblies that contains changed modules
18+
UPDATED_ASSEMBLIES=$(grep -rnwl "$REPO_PATH" --include=\*.adoc --exclude-dir={snippets,modules} -e "$MODULES")
19+
# Exit 0 if there are no modified assemblies
20+
if [[ -z "${UPDATED_ASSEMBLIES}" ]]
21+
then
22+
exit 0
23+
fi
24+
# Subtract $REPO_PATH from path with bash substring replacement
25+
UPDATED_ASSEMBLIES=${UPDATED_ASSEMBLIES//"$REPO_PATH/"/}
26+
fi
27+
# ASSEMBLIES is the list of modifed assemblies
28+
ASSEMBLIES=$(echo "$FILES" | awk '!/modules\/(.*)\.adoc/')
29+
# Concatenate both lists and remove dupe entries
30+
ALL_ASSEMBLIES=$(echo "$UPDATED_ASSEMBLIES $ASSEMBLIES" | tr ' ' '\n' | sort -u)
31+
# Check that assemblies are in a topic_map
32+
for ASSEMBLY in $ALL_ASSEMBLIES; do
33+
# Get the page name to search the topic_map
34+
# Search for files only, not folders
35+
PAGE="File: $(basename "$ASSEMBLY" .adoc)"
36+
# Don't include the assembly if it is not in a topic map
37+
if grep -rq "$PAGE" --include "*.yml" _topic_maps ; then
38+
DISTROS+=("$(grep -rl "$PAGE" --include "*.yml" _topic_maps)")
39+
fi
40+
done
41+
42+
# Handle modified topic maps
43+
UPDATED_DISTROS=$(echo "$FILES" | awk '/_topic_maps\/(.*)\.yml/')
44+
# Concat all the updated topic maps
45+
DISTROS+=("${UPDATED_DISTROS}")
46+
# Clean up and remove duplicates
47+
echo "${DISTROS[@]}" | tr ' ' '\n' | sort | uniq

0 commit comments

Comments
 (0)