absolute-version / commit-and-tag-version

Fork of the excellent standard-version. Automate versioning and CHANGELOG generation, with semver.org and conventionalcommits.org :trophy:
ISC License
385 stars 36 forks source link

How to retrieve the generated CHANGELOG part (only the latest changes) in lifecycle scripts #88

Closed davidsneighbour closed 4 months ago

davidsneighbour commented 1 year ago

I am aware of #38, but I can't see how this can be helpful for my special use case. After the tag is created, I would like to create a release on GitHub via REST API.

The script to clear probable questions:

# create a release on GitHub
GITHUB_REPO=https://github.com/${GITHUB_REPOSLUG}
URL="$GITHUB_REPO"/"releases/edit/v""$VERSION"
curl \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: token ${GITHUB_SECRET}" \
  https://api.github.com/repos/"${GITHUB_REPOSLUG}"/releases \
  -d "{\"tag_name\":\"v${VERSION}\",\"name\":\"v${VERSION}\",\"draft\":false,\"prerelease\":false,\"generate_release_notes\":true}"
xdg-open "${URL}" &>>/dev/null

The body value in the payload could contain the list of changes.

Is there an easy way to obtain the changelog changes at some point or do I have to create a post-changelog-creation hook that takes a diff of the changelog into a temporary file to reuse later on? That would be my current idea to implement this.

Thanks for any suggestions.

ceng-p commented 1 year ago

Did you figure a solution to your problem?

davidsneighbour commented 1 year ago

no, sorry.

TimothyJones commented 1 year ago

Long term, it would be good to have this in the tool directly, but here's a short bash snippet I wrote for pact-js that reads the release notes for a github release:

(it also fails if there are no release notes)

# It's easier to read the release notes
# from the commit-and-tag-version tool before it runs
RELEASE_NOTES="$(npx commit-and-tag-version --dry-run | awk 'BEGIN { flag=0 } /^---$/ { if (flag == 0) { flag=1 } else { flag=2 }; next } flag == 1')"

# Don't release if there are no changes
if [ "$(echo "$RELEASE_NOTES" | wc -l)" -eq 1 ] ; then
    echo "ERROR: This release would have no release notes. Does it include changes?"
    echo "   - You must have at least one fix / feat commit to generate release notes"
    echo "*** STOPPING RELEASE PROCESS ***"
    exit 1
fi
TimothyJones commented 1 year ago

(I wrote this before I forked commit-and-tag-version)

Houtheyfa commented 10 months ago

@davidsneighbour check this thread: https://github.com/conventional-changelog/standard-version/issues/610#issuecomment-683337506

The idea is to save the output in a different file other than the Changelog.md, then pass it to your API call. standard-version -i RELEASE_BODY.md --skip.commit [other options]

davidsneighbour commented 4 months ago

I am closing this and recommend reading the link by @Houtheyfa.

The following two lines in my prerelease hook create a file changes.md with the changelog:

RELEASE_NOTES="$(npx commit-and-tag-version --dry-run | awk 'BEGIN { flag=0 } /^---$/ { if (flag == 0) { flag=1 } else { flag=2 }; next } flag == 1')"
echo "${RELEASE_NOTES}" >changes.md

The curl call in the original issue text is working only if the changes are not too large, else I have to add the text in changes.md manually to the release.