diff --git a/.github/workflows/pr-pipeline.yml b/.github/workflows/pr-pipeline.yml new file mode 100644 index 0000000..d954170 --- /dev/null +++ b/.github/workflows/pr-pipeline.yml @@ -0,0 +1,38 @@ +name: PR pipeline + +on: + pull_request: + branches: + - develop + +env: + IMAGE_NAME: hsldevcom/hsl-map-server + TEST_STAGE: tester + +jobs: + build-check-test: + name: Build, check, test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + clean: 'true' + fetch-depth: 2 + + - name: Lowercase Docker Image Name + run: echo "IMAGE_NAME=${IMAGE_NAME,,}" >> "${GITHUB_ENV}" + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build tester image + uses: docker/build-push-action@v6 + with: + context: . + load: true + target: "${{ env.TEST_STAGE }}" + tags: "${{ env.IMAGE_NAME }}:${{ env.TEST_STAGE }}" + + - name: Run checks and tests inside Docker + run: docker run --rm "${{ env.IMAGE_NAME }}:${{ env.TEST_STAGE }}" diff --git a/Dockerfile b/Dockerfile index 07a41eb..5dd956d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16-bullseye-slim +FROM node:16-bullseye-slim AS base ENV WORK=/opt/hsl-map-server ENV DATA_DIR=${WORK}/data @@ -27,6 +27,14 @@ RUN yarn install && yarn cache clean COPY . ${WORK} +# tester stage: install devDependencies and run linting; exits non-zero on failures +FROM base AS tester +RUN NODE_ENV=development yarn install && yarn cache clean +RUN node_modules/.bin/eslint . + +# production stage: download map data and run the server +FROM base AS production + RUN mkdir -p ${DATA_DIR} # OpenMapTiles dataset generated by hsldevcom