Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add script and dockerfiles checks to github build action #9658

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/scripts/check-commit-titles.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/sh
# shellcheck disable=SC2317
emersion marked this conversation as resolved.
Show resolved Hide resolved

# This script reads newline separated commit titles from stdin
# output an error message when titles are deemed invalid,
# and exits accordingly

if [ -z "$NOCOLOR" ]; then
RED=$(tput setaf 1 2>/dev/null)
YELLOW=$(tput setaf 3 2>/dev/null)
BLUE=$(tput setaf 4 2>/dev/null)
RESET=$(tput sgr0 2>/dev/null)
fi
Expand Down
54 changes: 50 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
name: Build
permissions:
packages: write
outputs:
Expand Down Expand Up @@ -177,8 +178,39 @@ jobs:
name: osrdyne-test
path: osrd-osrdyne-test.tar

check_dockerfiles:
runs-on: ubuntu-latest
name: Check dockerfiles
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build dummy test_data and static_assets images
run: |
echo -e "FROM scratch" > Dockerfile.empty
docker build -t test_data -f Dockerfile.empty .
docker build -t static_assets -f Dockerfile.empty .

- name: Find and check all Dockerfiles using docker build --check
run: |
set -eo pipefail
find . -name 'Dockerfile*' -print0 | xargs -0 -I {} docker build --file {} --check .

check_scripts:
runs-on: ubuntu-latest
name: Check scripts
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Find and check all scripts using ShellCheck
uses: ludeeus/action-shellcheck@master
with:
ignore_names: gradlew
Synar marked this conversation as resolved.
Show resolved Hide resolved

check_generated_railjson_sync:
runs-on: ubuntu-latest
name: Check generated railjson sync
steps:
- uses: actions/checkout@v4
- name: Install poetry
Expand All @@ -204,6 +236,7 @@ jobs:

check_railjson_generator:
runs-on: ubuntu-latest
name: Check railjson generator
steps:
- uses: actions/checkout@v4
- name: Install poetry
Expand Down Expand Up @@ -264,6 +297,7 @@ jobs:

check_commits:
runs-on: ubuntu-latest
name: Check commits
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down Expand Up @@ -292,7 +326,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

final_newline_lint:
check_final_newline:
Khoyo marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
name: Check final newline
Khoyo marked this conversation as resolved.
Show resolved Hide resolved
steps:
Expand All @@ -316,6 +350,7 @@ jobs:

check_integration_tests:
runs-on: ubuntu-latest
name: Check integration tests
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -349,6 +384,7 @@ jobs:

check_osrd_schema:
runs-on: ubuntu-latest
name: Check osrd schema
steps:
- uses: actions/checkout@v4
- name: Install poetry
Expand Down Expand Up @@ -386,6 +422,7 @@ jobs:

check_toml:
runs-on: ubuntu-latest
name: Check toml
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -399,6 +436,7 @@ jobs:

check_infra_schema_sync:
runs-on: ubuntu-latest
name: Check infra schema sync
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -417,6 +455,7 @@ jobs:

check_front_rtk_sync:
runs-on: ubuntu-latest
name: Check front rtk sync
needs:
- build

Expand Down Expand Up @@ -452,6 +491,7 @@ jobs:

check_core:
runs-on: ubuntu-latest
name: Check core
needs:
- build
steps:
Expand Down Expand Up @@ -503,7 +543,7 @@ jobs:

check_editoast_tests:
runs-on: ubuntu-latest

name: Check editoast tests
needs:
- build

Expand Down Expand Up @@ -576,7 +616,7 @@ jobs:
# check to complete. As editoast tests take while to run, we don't want this to
# be on the hot path
runs-on: ubuntu-latest

name: Check editoast lints
needs:
- build
steps:
Expand Down Expand Up @@ -623,7 +663,7 @@ jobs:
check_editoast_openapi:
# for the same reason as check_editoast_lints, we run this in a separate job
runs-on: ubuntu-latest

name: Check editoast openapi
needs:
- build
steps:
Expand Down Expand Up @@ -668,6 +708,7 @@ jobs:

check_gateway:
runs-on: ubuntu-latest
name: Check gateway
needs:
- build

Expand Down Expand Up @@ -730,6 +771,7 @@ jobs:

check_osrdyne:
runs-on: ubuntu-latest
name: Check osrdyne
needs:
- build

Expand Down Expand Up @@ -792,6 +834,7 @@ jobs:

check_front:
runs-on: ubuntu-latest
name: Check front
needs:
- build

Expand Down Expand Up @@ -846,6 +889,7 @@ jobs:

integration_tests:
runs-on: ubuntu-latest
name: Integration tests
needs:
- build
steps:
Expand Down Expand Up @@ -956,6 +1000,7 @@ jobs:

end_to_end_tests:
runs-on: ubuntu-latest
name: End to end tests
needs:
- build
steps:
Expand Down Expand Up @@ -1058,6 +1103,7 @@ jobs:

check_reuse_compliance:
runs-on: ubuntu-latest
name: Check reuse compliance
steps:
- uses: actions/checkout@v4
- name: REUSE Compliance Check
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ jobs:
contents: read
pull-requests: write
runs-on: ubuntu-latest
name: "Check PR label"
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
7 changes: 4 additions & 3 deletions editoast/assets/signal_sprites/generate-atlas.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# First add all your svg in a subfolder named to the signaling system (eg: `BAL`)
# Then run this script. You will need docker.

for signaling_system in $(ls); do
for signaling_system in *; do
# Skip files (like this file)
[ ! -d "${signaling_system}" ] && continue
[ -d "${signaling_system}" ] || continue

# Prepare the tmp directory
tmp_dir="$(mktemp -d)"
Expand All @@ -20,7 +20,8 @@ for signaling_system in $(ls); do
cp "${tmp_dir}"/sprites/sprites* "${signaling_system}"

# Add a linefeed to the json files
for json_file in $(ls "${signaling_system}"/*.json); do
for json_file in "${signaling_system}"/*.json; do
[ -f "$json_file" ] || continue
echo "" >> "${json_file}"
done

Expand Down
6 changes: 2 additions & 4 deletions front/scripts/generate-types.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/bin/sh
npx @rtk-query/codegen-openapi src/config/openapi-editoast-config.ts
if [ $? -ne 0 ]; then
if ! npx @rtk-query/codegen-openapi src/config/openapi-editoast-config.ts; then
echo "npx @rtk-query/codegen-openapi src/config/openapi-editoast-config.ts command failed. Exit the script"
exit 1
fi
yarn eslint --fix src/common/api/generatedEditoastApi.ts --no-ignore
npx @rtk-query/codegen-openapi src/config/openapi-gateway-config.ts
if [ $? -ne 0 ]; then
if ! npx @rtk-query/codegen-openapi src/config/openapi-gateway-config.ts; then
echo "npx @rtk-query/codegen-openapi src/config/openapi-gateway-config.ts command failed. Exit the script"
exit 1
fi
Expand Down
10 changes: 5 additions & 5 deletions scripts/cleanup-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ "$#" -ne 0 ]; then
exit 1
fi

root_path="$(realpath $(dirname "$0")/..)"
root_path=$(realpath "$(dirname "$0")/..")

# These variables are necessary to load the infra on the correct instance (the pr-infra or the dev one)
OSRD_POSTGRES="osrd-postgres"
Expand All @@ -37,13 +37,13 @@ echo "Checking database exists..."
DB_EXISTS="$(docker exec $OSRD_POSTGRES psql -p $OSRD_POSTGRES_PORT -c "SELECT EXISTS (SELECT FROM pg_stat_database WHERE datname = 'osrd');")"
DB_EXISTS="$(echo "$DB_EXISTS" | grep -o -E '[tf]$')"

if [ $DB_EXISTS = 't' ]; then
if [ "$DB_EXISTS" = 't' ]; then
echo " Database 'osrd' found"
else
echo " Database 'osrd' not found"
fi

if [ $DB_EXISTS = 't' ]; then
if [ "$DB_EXISTS" = 't' ]; then
# Check that no service is connected to the database
echo "Checking database availability..."

Expand All @@ -56,7 +56,7 @@ if [ $DB_EXISTS = 't' ]; then
DB_CONN="$(docker exec "$OSRD_POSTGRES" psql -p "$OSRD_POSTGRES_PORT" -c "SELECT numbackends FROM pg_stat_database WHERE datname = 'osrd';")"
DB_CONN="$(echo "$DB_CONN" | grep -o -E '[0-9]+$')"

if [ $DB_CONN -ne 0 ]; then
if [ "$DB_CONN" -ne 0 ]; then
echo " The database can not be cleared."
echo " A process is connected to your database, please check it and close it."
echo " In doubt, you can shutdown the whole compose stack and only keep the database running."
Expand All @@ -77,6 +77,6 @@ docker exec "$OSRD_POSTGRES" psql -p "$OSRD_POSTGRES_PORT" -f //tmp/init.sql > /
echo "Deleting valkey cache..."
docker exec "$OSRD_VALKEY" valkey-cli -p "$OSRD_VALKEY_PORT" FLUSHALL > /dev/null 2>&1 || docker volume rm -f $OSRD_VALKEY_VOLUME > /dev/null

echo "Cleanup done!\n"
echo 'Cleanup done!'
echo "You may want to apply migrations if you don't load a backup:"
echo "'diesel migration run --migration-dir \"$root_path/editoast/migrations\"' # 'docker compose up editoast' does it automatically"
2 changes: 1 addition & 1 deletion scripts/create-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set -e

OUTPUT_DIR="."
if [ "$#" -eq 1 ]; then
OUTPUT_DIR="$(readlink -f $1)/"
OUTPUT_DIR="$(readlink -f "$1")/"
fi

# Check output directory
Expand Down
4 changes: 2 additions & 2 deletions scripts/drop-core.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh

docker rm -f dyn-osrd-core-$1
docker rm -f "dyn-osrd-core-$1"

docker compose \
-p "osrd" \
-f "docker-compose.yml" \
exec rabbitmq rabbitmqctl delete_queue core-$1
exec rabbitmq rabbitmqctl delete_queue "core-$1"
2 changes: 1 addition & 1 deletion scripts/load-backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ "$#" -ne 1 ]; then
exit 1
fi

root_path="$(realpath $(dirname "$0")/..)"
root_path=$(realpath "$(dirname "$0")/..")

# Check sha1 is matching
echo "Checking backup integrity..."
Expand Down
Loading