name: Publish package to GitHub Packages

on:
  workflow_dispatch:
  release:
    types: [published]

jobs:
  check-workflows:
    uses: ./.github/workflows/check-workflows.yml

  publish:
    needs: check-workflows
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v4
      - run: |
          cd ../
          mv opensourcecobol4j/* .
          mv libcobj/* opensourcecobol4j
      - uses: actions/setup-java@v4
        with:
          java-version: '11'
          distribution: 'temurin'
      - name: Validate Gradle wrapper
        uses: gradle/wrapper-validation-action@v3
      - name: Publish package
        uses: gradle/gradle-build-action@v3
        with:
          arguments: publish
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
