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

Test Workflows #105

Merged
merged 12 commits into from
Dec 18, 2023
49 changes: 49 additions & 0 deletions .github/actions/package-and-upload-artifacts/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Package and upload artifacts
description: Package a Python project and upload the artifacts and release notes
inputs:
tag-name:
description: 'The name of the tag for the GitHub release'
required: true
runs:
using: 'composite'
steps:
- name: Parse changelog for release notes
shell: bash
run: |
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=${{ inputs.tag-name }}
echo "TAG_NAME=$target_version" >> $GITHUB_ENV
content=$(extract_version_content "$changelog" "$target_version")

if [ -n "$content" ]; then
echo "::notice::Found release notes for ${target_version}"
echo "$content" >> release-notes.md
else
echo "::warning::Did not find release notes for ${target_version}"
touch release-notes.md
fi

- name: Upload release notes
uses: actions/upload-artifact@v4
with:
name: release-notes
path: release-notes.md

- name: Package and upload artifacts
if: ${{ env.PACKAGE == 'true' }}
uses: hynek/build-and-inspect-python-package@v2
40 changes: 40 additions & 0 deletions .github/actions/release/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Release
description: Create a GitHub release and upload the package to PyPI
inputs:
pypi-api-token:
description: 'PyPI API token'
required: true
tag-name:
description: 'The name of the tag for the GitHub release'
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:
name: Packages
path: dist

- name: Download release notes
uses: actions/download-artifact@v4
with:
name: release-notes

- name: Create a GitHub release
uses: softprops/action-gh-release@v1
with:
files: dist/*
tag_name: "${{ env.TAG_NAME }}"
body_path: release-notes.md

- name: Upload package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ inputs.pypi-api-token }}
83 changes: 0 additions & 83 deletions .github/workflows/release.yaml

This file was deleted.

7 changes: 4 additions & 3 deletions .github/workflows/ci.yaml → .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: CI

on:
pull_request:
types: [opened, synchronize]
branches: [master]
workflow_call:
# pull_request:
# types: [opened, synchronize]
# branches: [master]

defaults:
run:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [master]

jobs:
bumpversion:
preview-version-hint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -32,14 +32,20 @@ jobs:
echo "RELEASE_KIND=$RELEASE_KIND" >> $GITHUB_ENV
echo "release-kind=$RELEASE_KIND" >> $GITHUB_OUTPUT

- name: Get Pull Request Number
id: pr
run: |
PR_NUMBER=$(gh pr view --json number -q .number || echo "${{ github.event.number }}")
echo "pull_request_number=${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "::notice::PR_NUMBER is ${PR_NUMBER}"
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.PAT }}

- name: Bump version dry run
if: ${{ env.RELEASE_KIND != 'no-release' }}
shell: bash
run: |
PR_NUMBER=$(gh pr view --json number -q .number || echo "")
REVISION=$(git describe --tags --long | awk -F- '{print $2}')
export PR_NUMBER REVISION

# This will display a full log of what would happen if we were to bump the version.
bump-my-version bump --dry-run --verbose "$RELEASE_KIND"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: Bump the version on merge
on:
pull_request:
types: [closed]
# types: [closed]
branches: [master]

jobs:
version-hint:
version:
permissions:
id-token: write
pull-requests: read
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -32,25 +35,43 @@ jobs:
echo "release-kind=$RELEASE_KIND" >> $GITHUB_OUTPUT
echo "PACKAGE=false" >> $GITHUB_ENV

- name: Get Pull Request Number
id: pr
run: |
PR_NUMBER=$(gh pr view --json number -q .number || echo "${{ github.event.number }}")
echo "pull_request_number=${PR_NUMBER}" >> $GITHUB_OUTPUT
echo "::notice::PR_NUMBER is ${PR_NUMBER}"
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
env:
GITHUB_TOKEN: ${{ secrets.PAT }}

- name: Bump version
if: ${{ env.RELEASE_KIND != 'no-release' }}
shell: bash
run: |
PR_NUMBER=$(gh pr view --json number -q .number || echo "")
REVISION=$(git describe --tags --long | awk -F- '{print $2}')
export PR_NUMBER REVISION
case "$RELEASE_KIND" in
major|minor|patch)
bump-my-version bump --allow-dirty --verbose "$RELEASE_KIND"
git push
git push --tags
echo "TAG_NAME=$(bump-my-version show current_version)" >> $GITHUB_ENV
# git push
# git push --tags
echo "PACKAGE=true" >> $GITHUB_ENV
;;
dev)
echo "Intentionally not bumping version for dev release"
echo "Temporary dev release for testing"
bump-my-version bump --allow-dirty --verbose --no-commit "$RELEASE_KIND"
echo "TAG_NAME=$(bump-my-version show current_version)" >> $GITHUB_ENV
echo "PACKAGE=true" >> $GITHUB_ENV
# echo "Intentionally not bumping version for dev release"
;;
esac

- name: Package
if: ${{ env.PACKAGE == 'true' }}
uses: hynek/build-and-inspect-python-package@v1
# - name: Package and upload artifacts
# if: ${{ env.PACKAGE == 'true' }}
# uses: ./.github/actions/package-and-upload-artifacts
# with:
# tag-name: ${{ env.TAG_NAME }}

# - name: Create a GitHub release
# if: ${{ env.PACKAGE == 'true' }}
# uses: ./.github/actions/release
Loading