googleapis / release-please-action

automated releases based on conventional commits
Apache License 2.0
1.71k stars 212 forks source link

Add version outputs for created PRs #684

Open uriklar opened 1 year ago

uriklar commented 1 year ago

TL;DR

I'm trying to use the action outputs in a slack notification message but for some reason they are blank

Expected behavior

steps.release.outputs.pr has the value of the created PR

Observed behavior

Value is empty

Action YAML

on:
  push:
    branches:
      - master
name: release-please
env:
  GITHUB_TOKEN: ${{ secrets.SCOPED_TOKEN }}
jobs:
  release-please:
    if: ${{ !contains(github.event.pull_request.labels.*.name, 'autorelease') }}
    runs-on: ubuntu-latest

    steps:
      - name: Create Release PR
        uses: google-github-actions/release-please-action@v3
        id: release
        with:
          token: ${{ secrets.SCOPED_TOKEN }}
          release-type: node
          package-name: "MY_PACKAGE_NAME"
          labels: autorelease

      - name: Slack Notification
        uses: rtCamp/action-slack-notify@v2
        env:
          SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
          SLACK_CHANNEL: SLACK_CHANNEL
          SLACK_MESSAGE: 'Release PR has been created for version : ${{ steps.release.outputs.major }}.${{ steps.release.outputs.minor }}.${{ steps.release.outputs.patch }}. See it here: https://github.com/OWNER/REPO/pull/${{ steps.release.outputs.pr_number }}'
          MSG_MINIMAL: true

Log output

28s
Run google-github-actions/release-please-action@v3
✔ Looking for latest release on branch: master with prefix: PREFIX
❯ Fetching merge commits on branch master with cursor: undefined
❯ Found latest release pull request: 506 version: 11.4.0
❯ Fetching releases with cursor undefined
✔ Building releases
✔ Building strategies by path
❯ .: node
✔ Looking for latest release on branch: master with prefix: PREFIX
❯ Fetching merge commits on branch master with cursor: undefined
❯ Found latest release pull request: 506 version: 11.4.0
❯ Fetching releases with cursor undefined
✔ Building pull requests
✔ Building strategies by path
❯ .: node
✔ Collecting release commit SHAs
❯ release search depth: 400
❯ Fetching releases with cursor undefined
❯ Found release for path ., v11.4.0
❯ release for path: ., version: 11.4.0, sha: SHA
✔ Collecting commits since all latest releases
❯ commit search depth: 500
✔ Splitting 7 commits by path
✔ Building candidate release pull request for path: .
❯ type: node
❯ targetBranch: master
❯ commit could not be parsed: feb6ca287d8c960881e5eea49477396e2a311416 remove comment
❯ commits: 6
✔ Considering: 6 commits
❯ component: 
❯ pull request title pattern: undefined
✔ Looking for open release pull requests
✔ found 0 open release pull requests.
✔ Looking for snoozed release pull requests
✔ found 0 snoozed release pull requests.
❯ Fetching package-lock.json from branch master
✔ updating from 11.4.0 to 11.4.1
❯ Fetching npm-shrinkwrap.json from branch master
⚠ file npm-shrinkwrap.json did not exist
⚠ file samples/package.json did not exist
❯ Fetching samples/package.json from branch master
❯ Fetching CHANGELOG.md from branch master
❯ Fetching package.json from branch master
✔ updating from 11.4.0 to 11.4.1
❯ Fetching .release-please-manifest.json from branch master
⚠ file .release-please-manifest.json did not exist
✔ Starting GitHub PR workflow...
✔ Successfully found branch HEAD sha "1b92cc5bed65da52de8ce9157bf96e405e56d2f3".
✔ Skipping branch creation step...
✔ Got the latest commit tree
✔ Successfully created a tree with the desired changes with SHA 8e0f0a5dea23862bab2ff3902ae2d4c233de500d
✔ Successfully created commit. See commit at https://api.github.com/
✔ Updating reference to fb76150d735a729cb2373889d4be2d9584e9461c
✔ Successfully updated reference fb76150d735a729cb2373889d4be2d9584e9461c
✔ Successfully opened pull request available at url: 
✔ Successfully opened pull request: 510.
✔ Successfully added labels autorelease to issue: 510
1s
Run rtCamp/action-slack-notify@v2
  env:
    GITHUB_TOKEN: ***
    SLACK_WEBHOOK: ***
    SLACK_CHANNEL: ***
    SLACK_COLOR: good
    SLACK_MESSAGE: Release PR has been created for version : ... See it here: https://github.com/OWNER/REPO/pull/
    MSG_MINIMAL: true

Additional information

No response

chrislemke commented 1 year ago

I started using it yesterday and have/had the same problem.

In conventionalcommits summary it said:

types other than fix: and feat: are allowed, for example @commitlint/config-conventional (based on the Angular convention) recommends build:, chore:, ci:, docs:, style:, refactor:, perf:, test:, and others.

Some of those types (e.g. ci:) did not appear in my changelog. But after changing: z changelog-types everything works fine.

ygueguin commented 1 year ago

Hi @uriklar, i get the same problem, if i don't miss, the pr_number output is populate only once you validate the PR. To catch the pr number before validate the PR, i used this :

echo ${{ toJSON(steps.release.outputs.pr) }} >> pr.json
echo "pr_number=$(jq -r '.number' pr.json)" >> $GITHUB_OUTPUT
kurtisvg commented 1 year ago

Can confirm that the outputs are unset (even the ones that shouldn't be) when release-please doesn't do a release.

It would be much nicer for debugging actions if these outputs are always set to some value -- even if it's "none" or "". At least then they outputs will show in the debug logs, which makes it much easier to tell what's going on.

yshrsmz commented 1 year ago

It would be nice if major/minor/patch values are available even if outputs.release_created is false.

I'd like to create & publish a snapshot release with that value.

dsiguero commented 1 year ago

Can't see any reason why outputs.major, outputs.minor and outputs.patch aren't set when the release is not created, if they're used for the PR title (so they're computed anyway).

bcoe commented 1 year ago

@dsiguero would you like to send a patch that sets the outputs when a release is not created? My one concern is that perhaps people are using these outputs to decide whether the next step in the action should execute, we should make this a breaking change IMO.

chingor13 commented 11 months ago

A release pull request could contain several components that have different versions. It might be possible to expose more data in the output of the release PRs created.

intrepidvaillant commented 10 months ago

It would be nice if major/minor/patch values are available even if outputs.release_created is false.

I'd like to create & publish a snapshot release with that value.

I have a workaround for that. It is not pretty but it do work.

jobs:
  release-please:
    runs-on: ubuntu-latest
    outputs:
      tag: ${{ steps.extract_version.outputs.version }}
    steps:
      - uses: google-github-actions/release-please-action@v4
        id: release-please
        with:
          release-type: <your_release_type>
          token: <your_pat_token>
      - name: Extract version
        id: extract_version
        run: |
          VERSION=$(echo '${{ steps.release-please.outputs.pr }}' | jq -r '.title' | grep -oP '(?<=release )\d+\.\d+\.\d+')
          echo "version=$VERSION" >> $GITHUB_OUTPUT

      - name: Use Version
        run: echo "The new version is ${{ steps.extract_version.outputs.version }}"
nishkarsh-beamery commented 6 months ago

What's the status on this? It would be useful to have this feature, in my case, I would like to tag container images with these version values and then later deploy the selected version when the release PR is merged.