# This workflow builds a map using the base and branch commit of a PR and uploads
# the logs as an artifact that update-pr.yml uses to add back as a comment.

name: Publish a Snapshot

on:
  push:
    branches: [ main ]
  workflow_dispatch:
    inputs:
      image_tags:
        description: 'Extra docker image tags ("latest,test")'
        required: true
        default: 'latest,snapshot'

jobs:
  snapshot:
    runs-on: ubuntu-latest
    timeout-minutes: 20
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v3
        with:
          submodules: true
      - name: Cache data/sources
        uses: ./.github/cache-sources-action
      - name: Set up JDK
        uses: actions/setup-java@v3
        with:
          java-version: 17
          distribution: 'temurin'
          cache: 'maven'
          server-id: ossrh
          server-username: MAVEN_USERNAME
          server-password: MAVEN_PASSWORD
      - run: ./scripts/build-release.sh
      - run: ./scripts/test-release.sh
      - run: sha256sum planetiler-dist/target/*with-deps.jar
      - run: md5sum planetiler-dist/target/*with-deps.jar
      - name: 'Upload artifact'
        uses: actions/upload-artifact@v3
        with:
          name: planetiler-build
          path: planetiler-dist/target/*with-deps.jar
      - name: Install GPG Private Key
        run: |
          echo -n "${{ secrets.OSSRH_GPG_SECRET_KEY }}" | base64 --decode | gpg --batch --import
      - run: ./scripts/push-release.sh
        env:
          GITHUB_ACTOR: ${{ github.actor }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          IMAGE_TAGS: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.image_tags || 'latest,snapshot' }}
          MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }}
          MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
          OSSRH_GPG_SECRET_KEY_PASSWORD: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }}
