name: EarlyAccess

on:
  push:
    branches: [ main ]

jobs:
  earlyaccess:
    name: EarlyAccess
    if: github.repository == 'jreleaser/jreleaser' && startsWith(github.event.head_commit.message, 'Releasing version') != true
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Set up Java
        uses: actions/setup-java@v1
        with:
          java-version: 11

      - uses: actions/cache@v2
        with:
          path: ~/.gradle/caches
          key: ${{ runner.os }}-gradle-cache-${{ hashFiles('**/*.gradle') }}-${{ hashFiles('**/gradle.properties') }}
          restore-keys: |
            ${{ runner.os }}-gradle-

      - uses: actions/cache@v2
        with:
          path: ~/.gradle/wrapper
          key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradlew') }}
          restore-keys: |
            ${{ runner.os }}-gradlew-

      - name: Build
        run: ./gradlew -Prelease=true build -S

      - name: Version
        id: vars
        run: echo ::set-output name=version::$(cat VERSION)

      - name: Assemble
        uses: jreleaser/release-action@v1
        with:
          version: early-access
          arguments: assemble
        env:
          JRELEASER_PROJECT_VERSION: ${{ steps.vars.outputs.version }}
          JRELEASER_GITHUB_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}

      - name: Release
        uses: jreleaser/release-action@v1
        with:
          version: early-access
          arguments: full-release
        env:
          JRELEASER_PROJECT_VERSION: ${{ steps.vars.outputs.version }}
          JRELEASER_GITHUB_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
          JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
          JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
          JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
          JRELEASER_DOCKER_DEFAULT_PASSWORD: ${{ secrets.JRELEASER_DOCKER_PASSWORD }}

      - name: JReleaser output
        if: always()
        uses: actions/upload-artifact@v2
        with:
          name: artifact
          path: |
            out/jreleaser/trace.log
            out/jreleaser/output.properties
