name: Docker
on:
  - push
  - pull_request
concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  cancel-in-progress: true
jobs:
  test:
    name: Docker
    runs-on: ubuntu-22.04
    steps:
    - name: Checkout source
      uses: actions/checkout@v4
    - name: Poke config
      run: |
        cp config/example.storage.yml config/storage.yml
        cp config/docker.database.yml config/database.yml
        touch config/settings.local.yml
    - name: Build Docker Image
      run: |
        docker compose build
    - name: Start Docker Compose
      run: |
        docker compose up -d
        sleep 15 # let the DB warm up a little
    - name: Prepare Database
      run: |
        docker compose run --rm web bundle exec rails db:migrate
        docker compose run --rm web bundle exec rails i18n:js:export
        docker compose run --rm web bundle exec rails assets:precompile
        docker compose run --rm web osmosis --rx docker/null-island.osm.xml --wd host=db database=openstreetmap user=openstreetmap password=openstreetmap validateSchemaVersion=no
    - name: Test Basic Website
      run: |
        curl -siL http://127.0.0.1:3000 | egrep '^HTTP/1.1 200 OK'
        curl -siL http://127.0.0.1:3000 | grep 'OpenStreetMap is the free wiki world map'
        curl -siL http://127.0.0.1:3000/api/0.6/node/1 | grep 'Null Island'
    - name: Test Complete Suite
      run: |
        docker compose run --rm web bundle exec rails db:test:prepare
        docker compose run --rm web bundle exec rails test:all
