name: Central Sync (Create)

on:
  workflow_dispatch:
    inputs:
      buildName:
        description: "Artifactory build name"
        required: true
      buildNumber:
        description: "Artifactory build number"
        required: true
      releaseSpecFile:
        type: choice
        description: "The AQL spec file for the release files"
        options:
          - '.github/stream-apps-release-files-spec.json'
          - '.github/apps-plugin-release-files-spec.json'

jobs:
  build:
    runs-on: ubuntu22-8-32-OSS
    steps:
    - uses: actions/checkout@v3
    - uses: jfrog/setup-jfrog-cli@v3
      with:
        version: 1.46.4
      env:
        JF_ARTIFACTORY_SPRING: ${{ secrets.JF_ARTIFACTORY_SPRING }}
    - name: Download Release Files
      run: |
        jfrog rt download \
          --spec ${{ inputs.releaseSpecFile }} \
          --spec-vars "buildname=${{ inputs.buildName }};buildnumber=${{ inputs.buildNumber }}"
    # Create checksums, signatures and create staging repo
    - name: Create Nexus staging repo
      uses: jvalkeal/nexus-sync@v0
      id: nexus-sync
      with:
        url: ${{ secrets.OSSRH_URL }}
        username: ${{ secrets.OSSRH_S01_TOKEN_USERNAME }}
        password: ${{ secrets.OSSRH_S01_TOKEN_PASSWORD }}
        staging-profile-name: ${{ secrets.OSSRH_STAGING_PROFILE_NAME }}
        create: true
        upload: true
        close: true
        release: false
        generate-checksums: true
        pgp-sign: true
        pgp-sign-passphrase: ${{ secrets.GPG_PASSPHRASE }}
        pgp-sign-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
        close-timeout: 1200
        release-timeout: 1200

      # Print staging repo id
    - name: Print Staging Repo Id
      run: echo ${{ steps.nexus-sync.outputs.staged-repository-id }}
