name: Publish package to GitHub Packages
on: [push]
jobs:
  publishing:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-java@v1
        with:
          java-version: 17
      - name: Rewrite version
        run: |
          branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
          cat gradle.properties | sed -e "s/^version=\([0-9\.]*\)/version=\1-branch_$branch-build${{ github.run_number }}/" > gradle.properties.tmp
          rm gradle.properties
          mv gradle.properties.tmp gradle.properties
      - name: Build
        run: ./gradlew build
      - name: Publish to Gitea
        continue-on-error: true
        run: ./gradlew publishAllPublicationsToGiteaRepository
        env:
          GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
      - name: Publish
        continue-on-error: true
        run: ./gradlew --no-parallel publishAllPublicationsToGithubPackagesRepository
        env:
          GITHUBPACKAGES_USER: ${{ github.actor }}
          GITHUBPACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }}