name: Continuous Integration
on: push
jobs:
  unit-tests:
    uses: ./.github/workflows/_test.yml
  npm-publish:
    needs: unit-tests
    if: github.ref == 'refs/heads/master' && needs.unit-tests.result == 'success'
    runs-on: ubuntu-24.04
    permissions:
      id-token: write
      contents: write
    steps:
      - uses: actions/checkout@v6
      - name: Install Node.js
        uses: actions/setup-node@v6
        with:
          node-version: 22.x
      - name: Run semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: >
          if [[ "${{ github.repository_owner }}" == "pelias" ]]; then
            curl "https://raw.githubusercontent.com/pelias/ci-tools/master/semantic-release.sh" | bash -
          fi
  build-docker-images:
    # run this job if the unit tests passed and the npm-publish job was a success or was skipped
    # note: github actions won't run a job if you don't call one of the status check functions, so `always()` is called since it evalutes to `true`
    if: ${{ always() && needs.unit-tests.result == 'success' && (needs.npm-publish.result == 'success' || needs.npm-publish.result == 'skipped') }}
    needs: [unit-tests, npm-publish]
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v6
      - name: Build Docker images
        env:
          DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
        run: |
          curl "https://raw.githubusercontent.com/pelias/ci-tools/master/build-docker-images.sh" | bash -
