Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 adding release flag #96

Merged
merged 6 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 0 additions & 132 deletions .github/workflows/create-release.yml

This file was deleted.

117 changes: 117 additions & 0 deletions .github/workflows/generate-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Generate Changelog

on:
workflow_call:
inputs:
version:
description: 'Semantic version of the release (e.g., v1.2.3)'
required: true
type: string
prev_version:
description: 'Previous release version (e.g., v1.2.2)'
required: false
default: ''
type: string
repository:
description: 'Repository name'
required: false
default: ${{ github.repository }}
type: string
ref:
description: 'Branch or SHA for the release'
required: false
default: ${{ github.ref }}
type: string
github_token:
description: 'GitHub token'
required: false
type: string
secrets:
token:
description: 'GitHub token'
required: false


jobs:
changelog:
runs-on: ubuntu-latest
steps:
- name: Set GITHUB_TOKEN environment variable
run: |
if [ -n "${{ inputs.github_token }}" ]; then
echo "GITHUB_TOKEN=${{ inputs.github_token }}" >> $GITHUB_ENV
else
echo "GITHUB_TOKEN=${{ secrets.token }}" >> $GITHUB_ENV
fi

- name: Checkout repository
uses: actions/checkout@v4
with:
token: "${{ env.GITHUB_TOKEN }}"
repository: "${{ inputs.repository }}"
ref: "${{ inputs.ref }}"

- name: Generate Changelog
id: changelog
env:
GITHUB_TOKEN: "${{ env.GITHUB_TOKEN }}"
run: |
set -x

REPOSITORY="${{ inputs.repository }}"
SHA="$(git rev-parse HEAD)"
echo "sha=${SHA}" >> "$GITHUB_OUTPUT"

# Get the previous tag
if [ -n "${{ inputs.prev_version }}" ] && git rev-list "${{ inputs.prev_version }}" 2> /dev/null; then
PREV_TAG="${{ inputs.prev_version }}"
else
PREV_TAG=$(gh api -H "Accept: application/vnd.github+json" "/repos/${{ inputs.repository }}/releases/latest" | jq -r '.tag_name // empty')
fi

# Generate release notes
NOTES=$(gh api --method POST \
-H "Accept: application/vnd.github+json" \
"/repos/${{ inputs.repository }}/releases/generate-notes" \
-f tag_name="${{ inputs.version }}" \
-f target_commitish="${SHA}" \
-f previous_tag_name="${PREV_TAG}" | jq -r '.body')

RELEASE_DOC="${PWD}/release.md"
echo "**Full Changelog**: https://github.com/${REPOSITORY}/commits/${{ inputs.version }}" > "${RELEASE_DOC}"

filterfunc() { echo "${NOTES}" | grep "^*\s*:$1:" | sed "s/.*:$1:\s*/* /"; }

BREAKING_CHANGES="$(filterfunc warning)"
if [ -n "${BREAKING_CHANGES}" ]; then
echo "## :warning: Breaking Changes" >> "${RELEASE_DOC}"
echo "${BREAKING_CHANGES}" >> "${RELEASE_DOC}"
echo "" >> "${RELEASE_DOC}"
fi

FEATURE_CHANGES="$(filterfunc sparkles)"
if [ -n "${FEATURE_CHANGES}" ]; then
echo "## :sparkles: Features" >> "${RELEASE_DOC}"
echo "${FEATURE_CHANGES}" >> "${RELEASE_DOC}"
echo "" >> "${RELEASE_DOC}"
fi

BUG_FIXES="$(filterfunc bug)"
if [ -n "${BUG_FIXES}" ]; then
echo "## :bug: Bug Fixes" >> "${RELEASE_DOC}"
echo "${BUG_FIXES}" >> "${RELEASE_DOC}"
echo "" >> "${RELEASE_DOC}"
fi

NEW_CONTRIB=$(echo "${NOTES}" | sed -n "/Contributors/,\$p")
if [ -n "${NEW_CONTRIB}" ]; then
echo "${NEW_CONTRIB}" >> "${RELEASE_DOC}"
else
echo "${NOTES}" | sed -n "/Changelog/,\$p" >> "${RELEASE_DOC}"
fi

- name: Upload Changelog Artifact
uses: actions/upload-artifact@v4
with:
name: changelog-artifact
path: release.md
127 changes: 23 additions & 104 deletions create-release/action.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't be afraid to replace the existing changelog stuff in here with the new action.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integrated the workflow. ptal. I had to accommodate two different ways of specifying secrets.

Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,11 @@ inputs:
description: 'The branch or SHA for the release (defaults to main)'
required: false
default: ${{ github.ref }}
outputs:
breaking-changes:
description: "Breaking changes introduced in this release"
value: ${{ steps.changelog.outputs.breaking-changes }}
features:
description: "Features introduced in this release"
value: ${{ steps.changelog.outputs.features }}
bug-fixes:
description: "Bug fixes introduced in this release"
value: ${{ steps.changelog.outputs.bug-fixes }}
new-contributors:
description: "New contributors to this release"
value: ${{ steps.changelog.outputs.new-contributors }}
is_prerelease:
description: 'Is this a pre-release?'
required: false
default: "false"

runs:
using: "composite"
steps:
Expand Down Expand Up @@ -61,103 +53,30 @@ runs:
echo "xy_version=${XY_VERSION}" >> $GITHUB_OUTPUT
id: check_tag

- name: Checkout code
uses: actions/checkout@v4
- name: Generate Changelog
uses: ./.github/workflows/generate-changelog.yml
with:
fetch-depth: 0
repository: ${{ inputs.repository }}
ref: ${{ inputs.ref }}
path: ${{ inputs.repository }}
token: ${{ inputs.github_token }}

- name: Make changelog
working-directory: ./${{ inputs.repository }}
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
shell: bash
run: |
set -x
set +o pipefail

# Details we need in order to create the release
REPOSITORY=${{ inputs.repository }}
echo "owner=${REPOSITORY%/*}" >> $GITHUB_OUTPUT
echo "repo=${REPOSITORY#*/}" >> $GITHUB_OUTPUT
SHA=$(git rev-parse HEAD)
echo "sha=${SHA}" >> $GITHUB_OUTPUT

# Let GitHub format the commits
if [ -n "${{ inputs.prev_version }}" ] && git rev-list ${{ inputs.prev_version }} 2> /dev/null; then
PREV_TAG="${{ inputs.prev_version }}"
else
PREV_TAG=$(gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" repos/${{ inputs.repository }}/releases/latest | jq -r '.tag_name // empty')
fi
NOTES=$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
repos/${{ inputs.repository }}/releases/generate-notes \
-f tag_name="${{ inputs.version }}" \
-f target_commitish="${{ inputs.ref }}" \
-f previous_tag_name="${PREV_TAG}" | jq -r '.body')
filterfunc() { echo "${NOTES}" | grep "^*\s*:$1:" | sed "s/.*:$1:\s*/* /"; }
version: ${{ github.event.inputs.version }}
prev_version: ${{ github.event.inputs.prev_version }}
repository: ${{ github.event.inputs.repository }}
ref: ${{ github.event.inputs.ref }}
github_token: ${{ inputs.github_token }}

RELEASE_DOC="${PWD}/release.md"
echo "release_doc=${RELEASE_DOC}" >> $GITHUB_ENV

BREAKING_CHANGES="$(filterfunc warning)"
if [ -n "${BREAKING_CHANGES}" ]; then
echo "## :warning: Breaking Changes" >> ${RELEASE_DOC}
echo "${BREAKING_CHANGES}" >> ${RELEASE_DOC}
echo "" >> ${RELEASE_DOC}
echo "breaking-changes<<nEOFn" >> $GITHUB_OUTPUT
echo "${BREAKING_CHANGES}" >> $GITHUB_OUTPUT
echo "nEOFn" >> $GITHUB_OUTPUT
fi

FEATURE_CHANGES="$(filterfunc sparkles)"
if [ -n "${FEATURE_CHANGES}" ]; then
echo "## :sparkles: Features" >> ${RELEASE_DOC}
echo "${FEATURE_CHANGES}" >> ${RELEASE_DOC}
echo "" >> ${RELEASE_DOC}
echo "features<<nEOFn" >> $GITHUB_OUTPUT
echo "${FEATURE_CHANGES}" >> $GITHUB_OUTPUT
echo "nEOFn" >> $GITHUB_OUTPUT
fi

BUG_FIXES="$(filterfunc bug)"
if [ -n "${BUG_FIXES}" ]; then
echo "## :bug: Bug Fixes" >> ${RELEASE_DOC}
echo "${BUG_FIXES}" >> ${RELEASE_DOC}
echo "" >> ${RELEASE_DOC}
echo "bug-fixes<<nEOFn" >> $GITHUB_OUTPUT
echo "${BUG_FIXES}" >> $GITHUB_OUTPUT
echo "nEOFn" >> $GITHUB_OUTPUT
fi

# TODO(djzager): More? could make this workflow accept as an argument whether or not
# to include other types (ie. seedling, docs)
- name: Download Changelog
uses: actions/download-artifact@v4
with:
name: changelog-artifact
path: .

# Add contributors as GitHub would have added them
NEW_CONTRIB=$(echo "${NOTES}" | sed -n "/Contributors/,\$p")
if [ -n "${NEW_CONTRIB}" ]; then
echo "${NEW_CONTRIB}" >> ${RELEASE_DOC}
echo "new-contributors<<nEOFn" >> $GITHUB_OUTPUT
echo "${NEW_CONTRIB}" | head -n -3 >> $GITHUB_OUTPUT
echo "nEOFn" >> $GITHUB_OUTPUT
else
echo "${NOTES}" | sed -n "/Changelog/,\$p" >> ${RELEASE_DOC}
fi
id: changelog

- uses: ncipollo/release-action@main
with:
owner: ${{ steps.changelog.outputs.owner }}
repo: ${{ steps.changelog.outputs.repo }}
owner: ${{ github.repository_owner }}
repo: ${{ inputs.repository }}
tag: ${{ inputs.version }}
commit: ${{ steps.changelog.outputs.sha }}
bodyFile: ${{ env.release_doc }}
commit: ${{ github.sha }}
bodyFile: release.md
draft: false
prerelease: ${{ steps.check_tag.outputs.is_prerelease }}
prerelease: ${{ inputs.is_prerelease }}
skipIfReleaseExists: true
token: ${{ inputs.github_token }}
token: ${{ inputs.github_token }}
Loading