diff --git a/.github/actions/release/action.yaml b/.github/actions/release/action.yaml index 6c16bc3b..649bb600 100644 --- a/.github/actions/release/action.yaml +++ b/.github/actions/release/action.yaml @@ -7,15 +7,13 @@ inputs: tag-name: description: 'The name of the tag for the GitHub release' required: true + github-token: + description: 'GitHub token' + required: true runs: using: "composite" steps: - - name: Download packages built by build-and-inspect-python-package - uses: actions/download-artifact@v4 - with: - path: artifacts - - name: Download packages built by build-and-inspect-python-package uses: actions/download-artifact@v4 with: @@ -31,8 +29,9 @@ runs: uses: softprops/action-gh-release@v1 with: files: dist/* - tag_name: "${{ env.TAG_NAME }}" + tag_name: "${{ inputs.tag-name }}" body_path: release-notes.md + token: ${{ inputs.github-token }} - name: Upload package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/version.yaml b/.github/workflows/version.yaml index 40edf36f..def335ab 100644 --- a/.github/workflows/version.yaml +++ b/.github/workflows/version.yaml @@ -9,6 +9,7 @@ jobs: permissions: id-token: write pull-requests: read + contents: write runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -71,3 +72,7 @@ jobs: - name: Create a GitHub release if: ${{ env.PACKAGE == 'true' }} uses: ./.github/actions/release + with: + tag-name: ${{ env.TAG_NAME }} + github-token: ${{ secrets.PAT }} + pypi-api-token: ${{ secrets.PYPI_API_TOKEN }} diff --git a/tools/bump.sh b/tools/bump.sh index 70a34aa9..c50e8892 100755 --- a/tools/bump.sh +++ b/tools/bump.sh @@ -1,11 +1,40 @@ #!/usr/bin/env bash -rm -Rf dist -RELEASE_KIND=$(generate-changelog --output release-hint) -echo "::notice::Suggested release type is: ${RELEASE_KIND}" -PR_NUMBER=$(gh pr view --json number -q .number || echo "") -echo "::notice::PR number is: ${PR_NUMBER}" -export PR_NUMBER -bump-my-version bump -v $RELEASE_KIND -python -m build -python -m twine upload dist/* + +function extract_version_content() { + changelog=$1 + target_version=$2 + + awk -v target="$target_version" ' + /^## / { + if (found) exit; + version=$2; + if (version == target) found=1; + next; + } + found { print; } + ' <<< "$changelog" +} + +#rm -Rf dist +#RELEASE_KIND=$(generate-changelog --output release-hint) +#echo "::notice::Suggested release type is: ${RELEASE_KIND}" +#PR_NUMBER=$(gh pr view --json number -q .number || echo "") +#echo "::notice::PR number is: ${PR_NUMBER}" +#export PR_NUMBER +#bump-my-version bump -v $RELEASE_KIND +#python -m build +#python -m twine upload dist/* + +changelog=$(cat "CHANGELOG.md") +TARGET_VERSION=$(bump-my-version show current_version) +echo "TAG_NAME=$TARGET_VERSION" +NOTES=$(extract_version_content "$changelog" "$TARGET_VERSION") + + +gh release create \ + "${TARGET_VERSION}" \ + ./dist/* \ + --title "${TARGET_VERSION}" \ + --notes "${NOTES}" \ + --draft \ diff --git a/tools/create-release.sh b/tools/create-release.sh new file mode 100755 index 00000000..c3ce499f --- /dev/null +++ b/tools/create-release.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + + +function extract_version_content() { + changelog=$1 + target_version=$2 + + awk -v target="$target_version" ' + /^## / { + if (found) exit; + version=$2; + if (version == target) found=1; + next; + } + found { print; } + ' <<< "$changelog" +} + +changelog=$(cat "CHANGELOG.md") +TARGET_VERSION=$(bump-my-version show current_version) +NOTES=$(extract_version_content "$changelog" "$TARGET_VERSION") +echo "Creating a GitHub release for version ${TARGET_VERSION} with notes." +gh release create \ + "${TARGET_VERSION}" \ + ./dist/* \ + --title "${TARGET_VERSION}" \ + --notes "${NOTES}" \ + --draft