Skip to content

Commit

Permalink
verify generated files exist in ui/dist (#847)
Browse files Browse the repository at this point in the history
* verify files script

* ui change

* minor fix

* updated scriot

* updated scriot

* updated scriot

* updated scriot

* updated scriot

* test

* make file

* removed html change

* addressing comments
  • Loading branch information
shreyakhajanchi committed Jun 26, 2024
1 parent 9296b6e commit a6e9323
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/scripts/verify-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Define the path to the dist directory and index.html file
DIST_DIR="ui/dist/ui"
INDEX_FILE="${DIST_DIR}/index.html"

# Check if index.html exists
if [ ! -f "$INDEX_FILE" ]; then
echo "Error: index.html not found in $DIST_DIR"
exit 1
fi

# Define the patterns to search for
declare -a patterns=("styles[^\"']*\.css" "runtime[^\"']*\.js" "polyfills[^\"']*\.js" "main[^\"']*\.js")

# Flag to check if any file is missing
MISSING_FILES=false

# Check each pattern
for pattern in "${patterns[@]}"; do
# Use grep to find the file reference in index.html
file=$(grep -oP "(?<=href=\"|src=\")$pattern(?=\")" "$INDEX_FILE" | head -n 1)

if [ -z "$file" ]; then
echo "Error: No file matching pattern $pattern found in $INDEX_FILE"
MISSING_FILES=true
else
# Check if the file exists in the dist directory
FILE_PATH="${DIST_DIR}/${file}"
if [ ! -f "$FILE_PATH" ]; then
echo "Error: File not found - $FILE_PATH"
MISSING_FILES=true
else
echo "File exists: $FILE_PATH"
fi
fi
done

# Exit with an error if any file was missing
if [ "$MISSING_FILES" = true ]; then
echo "Verification failed. File mismatch issue. Please ensure that you have run ng build."
exit 1
else
echo "All expected files are present. Verification passed."
fi
34 changes: 34 additions & 0 deletions .github/workflows/ui-generated-files-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2024 Google LLC
#
# 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.

name: ui-generated-files-check
on:
push:
branches:
- master
pull_request:
paths:
- 'ui/**'

jobs:
verify:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Verify files
run: |
chmod +x .github/scripts/verify-files.sh
.github/scripts/verify-files.sh
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ifndef $(GOPATH)
endif
# Build the default binary
build:
cd ui/ && ng build
go build -o spanner-migration-tool
# Build a static binary
build-static:
Expand Down

0 comments on commit a6e9323

Please sign in to comment.