Skip to content

Commit

Permalink
Add new script for generating the last modified dates of stacks and s…
Browse files Browse the repository at this point in the history
…amples (#429)

* update dockerfiles with new script

Signed-off-by: Jordan Dubrick <[email protected]>

* add new script for generating last modified dates

Signed-off-by: Jordan Dubrick <[email protected]>

* fix accidental removal of comment

Signed-off-by: Jordan Dubrick <[email protected]>

* change last_modified to lastModified

Signed-off-by: Jordan Dubrick <[email protected]>

* update grabbing of version and stack name

Signed-off-by: Jordan Dubrick <[email protected]>

* add suggestion and use last commit of directory instead of devfile

Signed-off-by: Jordan Dubrick <[email protected]>

---------

Signed-off-by: Jordan Dubrick <[email protected]>
  • Loading branch information
Jdubrick authored Jun 24, 2024
1 parent bcfb507 commit 7583bcf
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
9 changes: 8 additions & 1 deletion .ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,19 @@ USER root
# Automatically set when --platform flag is set, will default to amd64 if no platform is given
ARG TARGETARCH=amd64

# Install yq
# Install yq and jq
ENV YQ_VERSION=v4.44.1
ENV JQ_VERSION=1.6
RUN curl -sL -O https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${TARGETARCH} -o /usr/local/bin/yq && mv ./yq_linux_${TARGETARCH} /usr/local/bin/yq && chmod +x /usr/local/bin/yq
RUN yum install -y jq-${JQ_VERSION}

COPY . /registry

# Script needs to be run from within registry directory
WORKDIR /registry
RUN bash .ci/generate_last_mod_file.sh
WORKDIR /

# Download the registry build tools
RUN git clone https://github.com/devfile/registry-support.git /registry-support

Expand Down
10 changes: 8 additions & 2 deletions .ci/Dockerfile.offline
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ USER root
# Automatically set when --platform flag is set, will default to amd64 if no platform is given
ARG TARGETARCH=amd64

# Install yq
# Install yq and jq
ENV YQ_VERSION=v4.44.1
ENV JQ_VERSION=1.6
RUN curl -sL -O https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${TARGETARCH} -o /usr/local/bin/yq && mv ./yq_linux_${TARGETARCH} /usr/local/bin/yq && chmod +x /usr/local/bin/yq

RUN yum install -y jq-${JQ_VERSION}
COPY . /registry

# Script needs to be run from within registry directory
WORKDIR /registry
RUN bash .ci/generate_last_mod_file.sh
WORKDIR /

# Download the registry build tools
RUN git clone https://github.com/devfile/registry-support.git /registry-support

Expand Down
81 changes: 81 additions & 0 deletions .ci/generate_last_mod_file.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/sh

#
# Copyright Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

stack_data=()
sample_data=()

grab_stacks() {
echo "Grabbing last modified date for stacks"

# look through git tree for all devfiles under stacks/
for filename in $(git ls-tree -r --name-only HEAD); do
if [[ $filename == *"stacks/"*"/devfile"* ]]; then
directory=$(dirname "$filename")
version=$(yq -r .metadata.name $filename)
stack=$(yq -r .metadata.version $filename)
# last commit that modified the entire directory that contains a devfile
last_commit=$(git log -1 --format="%aI" -- "$directory")

stack_data+=("{\"name\": \"${stack}\",\"version\": \"${version}\",\"lastModified\": \"${last_commit}\"}")
fi
done
}

grab_samples(){
echo "Grabbing last modified date for samples"
echo "Creating temp data.json file"

yq -p yaml -o json extraDevfileEntries.yaml > data.json
PARENT_DIR=$PWD
TEMP_DIR=$PWD/temp
mkdir -p temp && cd temp
while IFS= read -r line; do
name=$(echo "$line" | cut -d ' ' -f 1)
version=$(echo "$line" | cut -d ' ' -f 2)
revision=$(echo "$line" | cut -d ' ' -f 3)
git_origin=$(echo "$line" | cut -d ' ' -f 4)
repo_name="$name"-"$revision"

git clone -q -b $revision $git_origin $repo_name
cd $repo_name
last_commit=$(git log -1 --format="%aI")
cd $TEMP_DIR
sample_data+=("{\"name\": \"${name}\",\"version\": \"${version}\",\"lastModified\": \"${last_commit}\"}")
done < <(jq -r '.samples[] | "\(.name) \(.versions[] | "\(.version) \(.git.revision) \(.git.remotes.origin)")"' $PARENT_DIR/data.json)
cd $PARENT_DIR

# cleanup of temp files and temp data store
echo "Cleaning up temp files"
rm -rf $PARENT_DIR/temp
rm $PARENT_DIR/data.json

}

create_last_modified_file() {
grab_stacks
grab_samples
echo "Creating the last_modified.json file"

stacks_json=$(printf '%s\n' "${stack_data[@]}" | jq -s .)
samples_json=$(printf '%s\n' "${sample_data[@]}" | jq -s .)

last_mod_file=$(jq -n --argjson stacks "$stacks_json" --argjson samples "$samples_json" '{ stacks: $stacks, samples: $samples }')
echo "$last_mod_file" > last_modified.json

}

create_last_modified_file

0 comments on commit 7583bcf

Please sign in to comment.