release-please-action icon indicating copy to clipboard operation
release-please-action copied to clipboard

Run a Gradle publish on creation of tag or release.

Open stewartbryson opened this issue 3 years ago • 3 comments

TL;DR

I have 2 action YAML files... one for release-please called release-please.yml and one for the Gradle build, test and publish called gradle-build.yml. gradle-build.yml runs on pull requests successfully, but I also want it to run on the creation of either the release or the tag associated with it (I don't care which one). I have tried an on statement for tag creation, release creation, and release publication, but it never triggers. I assume there is something in release-please that prohibits the releases it creates from triggering actions.

Expected behavior

I expect that a created tag, a created release, or a published release would trigger my additional action YAML workflow.

Observed behavior

No additional workflow is executed after release-please creates the release.

Action YAML

# First YAML file called gradle.build.yml

# This is a basic workflow to help you get started with Actions

name: Build

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  # I have tried tag:created release:created as well.
  release:
    types:
      - published
  pull_request:
    branches:
      - main

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Environment variables for every step
    env:
      GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}


    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: checkout-repository
        uses: actions/checkout@v2
        with:
          fetch-depth: '0' # will fetch the entire history

      - id: auth
        uses: google-github-actions/[email protected]
        with:
          credentials_json: ${{ secrets.gcp_dev }}

      # Apply snapshot on PR merges
      - name: gradle-apply-snapshot
        if: ${{ github.event_name == 'pull_request' }}
        uses: gradle/gradle-build-action@v2
        with:
          arguments: applySnapshot -S

      # Build and publish artifacts
      # Publish to snapshot or release depending on version number
      - name: gradle-build
        uses: gradle/gradle-build-action@v2
        with:
          arguments: build integration buildDashboard publish -S

      # Eventually other steps for publishing docs, etc.

# Second YAML file called release-please.yml

# This is a basic workflow to help you get started with Actions

name: Release

# Controls when the workflow will run
on:
  # Only pushes to main
  push:
    branches:
      - main

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  release:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Release Please
      - name: release-please
        uses: GoogleCloudPlatform/release-please-action@v2
        with:
          release-type: simple
          package-name: synthesis-lib
          version-file: version.txt

Additional information

Perhaps there is a better way to orchestrate the publication of Java libs upon creation of the release, but this seemed like the right way. Perhaps trying to the the release-please release PR merge to execute the Java lib publication is reasonable.

stewartbryson avatar Dec 07 '21 23:12 stewartbryson

I believe you are bumping into a limitation of using the default GITHUB_TOKEN, see:

https://docs.github.com/en/actions/learn-github-actions/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token

If you create an alternate token, this should address the issue; let me know if this does the trick.

bcoe avatar Dec 20 '21 19:12 bcoe

Thanks @bcoe... I appreciate this. Let me ask this... is there another, more preferred way to do a "publish" step? This is the publishing of Java libs upon release? It needs to happen after the new release, because Gradle uses the new version number when publishing the library.

stewartbryson avatar Dec 20 '21 19:12 stewartbryson

I'm using the Manifest release strategy, but this is how I did the uploading of assets to a release after release-please runs.

Hopefully, this helps you and any passerby.

# ...

    steps:
      - name: 🙌 Prepare release
        id: release-please
        uses: GoogleCloudPlatform/release-please-action@v3
        with:
          command: manifest
          config-file: .github/release-please.json
          token: ${{ secrets.GITHUB_TOKEN }}

      # ...

      - name: 📢 Publish new release
        if: ${{ steps.release-please.outputs.release_created }}
        run: ./gradlew publish

      - name: 📦 Upload artifacts
        if: ${{ steps.release-please.outputs.release_created }}
        uses: svenstaro/upload-release-action@v2
        with:
          tag: ${{ steps.release-please.outputs.tag_name }}
          file: '**/build/libs/*'
          file_glob: true
          overwrite: true
          repo_token: ${{ secrets.GITHUB_TOKEN }}

axieum avatar Jan 31 '22 00:01 axieum

It looks like a solution is posted.

tmatsuo avatar Oct 04 '22 23:10 tmatsuo