Skip to content

Commit

Permalink
Fix CI tests run and make pipeline scripts work in Docker or outside …
Browse files Browse the repository at this point in the history
…of Docker (adding NX_RUN_LOCAL option)
  • Loading branch information
lorenjohnson committed Aug 18, 2024
1 parent ae8071d commit 62f3ae5
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .github/actions/setup-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,7 @@ runs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ inputs.github_token }}

- name: Set NX to run locally using Node vs in Docker dev runner container
shell: bash
run: echo "NX_RUN_LOCAL=true" >> $GITHUB_ENV
4 changes: 2 additions & 2 deletions .github/workflows/_build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push ${{ matrix.imageName }}
run: pnpm exec nx build ${{ matrix.imageName }} --push
run: ./nx build ${{ matrix.imageName }} --push

test:
needs: build
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
uses: ./.github/actions/pull-ghcr

- name: "Run ${{ matrix.suite }} test suite"
run: pnpm exec nx test -- ${{ matrix.suite }}
run: ./nx test -- ${{ matrix.suite }}

- name: Show logs
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_publish_image_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
git config --global user.name 'wikibase suite github actions bot'
git config --global user.email 'wikibase-suite-github-actions-bot@users.noreply.github.com'
pnpm exec nx release publish -p ${{ steps.extract_tag.outputs.imageName }}
./nx release publish -p ${{ steps.extract_tag.outputs.imageName }}
2 changes: 1 addition & 1 deletion .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ jobs:
PROJECT_ARG="-p ${{ inputs.image_name }}"
fi
pnpm exec nx release $PROJECT_ARG $DRY_RUN_FLAG
./nx release $PROJECT_ARG $DRY_RUN_FLAG
1 change: 1 addition & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ elif [ "$GITHUB_ACTIONS" == true ]; then
)
# local build
else
BUILD_ARGS+=("--load")
# When not tagging anything but the image name the "latest" tag is by default applied,
# making that explicit here:
TAGS+=(
Expand Down
9 changes: 9 additions & 0 deletions lint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/usr/bin/env bash

# Always run in dev runner (docker) to have the extra dependencies available (currently Python and Hadolint)
# If not running in Docker, start dev runner and run script again there
if [[ ! -f /.dockerenv ]]; then
# Make sure the docker network exists
docker network create wbs-dev > /dev/null 2>&1 || true

exec docker compose --progress quiet run --build --rm runner -c './lint.sh "$@"' -- "$@"
fi

[ -f "local.env" ] || touch local.env
source local.env

Expand Down
16 changes: 10 additions & 6 deletions nx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

set -e

# Create a local.env if it doesn't already exist
[ -f "local.env" ] || touch local.env
# Make sure the docker network exists
docker network create wbs-dev > /dev/null 2>&1 || true
source local.env

# If running inside a Docker container, execute nx directly
if [ -f /.dockerenv ]; then
exec nx "${*}"
# # Execute nx directly if locally flagged to run in node or running inside a Docker container
if [[ -f /.dockerenv || "$NX_RUN_LOCAL" == true ]]; then
exec pnpm exec nx "$@"
fi

# Otherwise, set up and run the Docker container
exec docker compose --progress quiet run --build --rm runner -c "nx ${*}"

# Create the expected Docker network if it doesn't exist
docker network create wbs-dev > /dev/null 2>&1 || true

exec docker compose --progress quiet run --build --rm runner -c 'pnpm exec nx "$@"' -- "$@"
14 changes: 11 additions & 3 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
# Change to the directory where the script is located
cd "$(dirname "${BASH_SOURCE[0]}")" || exit

# Make sure the docker network exists
docker network create wbs-dev > /dev/null 2>&1 || true
# Must in Docker environment to access test-services by Docker network names
# If not running in Docker, start dev runner and run script again there
if [[ ! -f /.dockerenv ]]; then
cd .. || exit 1

NODE_NO_WARNINGS=1 node --require ts-node/register --loader=ts-node/esm cli.ts "$@"
# Make sure the docker network exists
docker network create wbs-dev > /dev/null 2>&1 || true

exec docker compose --progress quiet run --build --rm runner -c 'test/test.sh "$@"' -- "$@"
fi

exec NODE_NO_WARNINGS=1 node --require ts-node/register --loader=ts-node/esm cli.ts "$@"

0 comments on commit 62f3ae5

Please sign in to comment.