name: Publish package to the Maven Central Repository and GitHub Packages
on:
  release:
    types: [created]
jobs:
  publish:
    runs-on: ubuntu-latest 
    permissions: 
      contents: read
      packages: write 
    steps:
      - name: Import GPG key
        id: import_gpg
        uses: crazy-max/ghaction-import-gpg@v4
        with:
          gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
          passphrase: ${{ secrets.PASSPHRASE }}
      - uses: actions/checkout@v2
      - name: maven-settings-action
        uses: s4u/maven-settings-action@v2.5.0
        with:
          servers: '[{"id": "sonatype-nexus-snapshots", "username": "${{ secrets.SONATYPE_NEXUS_USERNAME }}", "password": "${{ secrets.SONATYPE_NEXUS_PASSWORD }}"},{"id": "sonatype-nexus-staging", "username": "${{ secrets.SONATYPE_NEXUS_USERNAME }}", "password": "${{ secrets.SONATYPE_NEXUS_PASSWORD }}"}]'
      - name: Publish to the Maven Central Repository
        run: mvn --batch-mode deploy -P release
