Skip to content

Commit

Permalink
Generate release notes out of the CHANGELOG
Browse files Browse the repository at this point in the history
Transform the topmost entry in CHANGELOG.rst to markdown and upload it
as artifact. In the deployment job this artifact is set as job summary.
  • Loading branch information
Spacetown committed Aug 16, 2024
1 parent dd250e5 commit 2b2c269
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ jobs:
python-version: ${{ matrix.python-version }}
upload-dist: ${{ matrix.upload-dist || false }} # Explicit set to false if not set
upload-app: ${{ matrix.upload-app || false }} # Explicit set to false if not set
upload-release-notes: ${{ matrix.upload-release-notes || false }} # Explicit set to false if not set
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Expand Down Expand Up @@ -120,6 +121,7 @@ jobs:
python-version: '3.12'
upload-dist: true
upload-app: true
upload-release-notes: true

# Test minimum and maximum Python version on Windows.
- os: windows-2019
Expand Down Expand Up @@ -238,6 +240,15 @@ jobs:
run: |
ls -al dist
- name: Download release notes
uses: actions/download-artifact@v4
with:
pattern: release-notes

- name: Set release notes as job summary
run: |
cat docs/build/release_notes.md >> $GITHUB_STEP_SUMMARY
- name: Push new tag
if: ${{ (github.repository == 'gcovr/gcovr') && (github.event.ref == 'refs/heads/main') && env.TAG_NEEDS_TO_BE_PUSHED == 'true' }}
run: |
Expand All @@ -252,6 +263,7 @@ jobs:
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.GCOVR_VERSION }}
body_path: docs/build/release_notes.md
files: build/*

- name: Publish to PyPi
Expand Down
25 changes: 19 additions & 6 deletions .github/workflows/gcovr-ci-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ on:
type: boolean
description: 'Upload the standalone application'
default: false
upload-release-notes:
type: boolean
description: 'Upload the release notes generated from markdown'
default: false
secrets:
CODECOV_TOKEN:
required: true
Expand All @@ -41,6 +45,8 @@ jobs:
runs-on: ${{ inputs.container && 'ubuntu-22.04' || inputs.os }}
env:
FORCE_COLOR: "1"
NOX_CONTAINER_ARGUMENTS: ${{ inputs.container && format(' --session docker_run_compiler({0}) --', inputs.gcc) || '' }}
GENERATE_DOCUMENTATION: ${{ (!inputs.container && (! startsWith(inputs.python-version,'pypy')) && (! startsWith(inputs.os,'windows-')) && (inputs.python-version != '3.8')) || (inputs.container && (inputs.gcc != 'gcc-5') && (inputs.gcc != 'gcc-6') && (inputs.gcc != 'gcc-8') && (inputs.gcc != 'gcc-9') && (inputs.gcc != 'clang-10')) }}
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -99,11 +105,11 @@ jobs:
- name: Lint files
run: |
nox --non-interactive${{ inputs.container && format(' --session "docker_run_compiler({0})" --', inputs.gcc) || '' }} --session lint
nox --non-interactive $NOX_CONTAINER_ARGUMENTS --session lint
- name: Test with pytest
run: |
nox --non-interactive${{ inputs.container && format(' --session "docker_run_compiler({0})" --', inputs.gcc) || '' }} --session tests -- --archive_differences
nox --non-interactive $NOX_CONTAINER_ARGUMENTS --session tests -- --archive_differences
- name: Upload pytest test results
if: ${{ failure() }}
Expand All @@ -127,9 +133,9 @@ jobs:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

- name: Generate documentation
if: ${{ (!inputs.container && (! startsWith(inputs.python-version,'pypy')) && (! startsWith(inputs.os,'windows-')) && (inputs.python-version != '3.8')) || (inputs.container && (inputs.gcc != 'gcc-5') && (inputs.gcc != 'gcc-6') && (inputs.gcc != 'gcc-8') && (inputs.gcc != 'gcc-9') && (inputs.gcc != 'clang-10')) }}
if: ${{ env.GENERATE_DOCUMENTATION == 'true' }}
run: |
nox --non-interactive ${{ inputs.container && format(' --session "docker_run_compiler({0})" --', inputs.gcc) || '' }} --session doc || exit 1
nox --non-interactive $NOX_CONTAINER_ARGUMENTS --session doc || exit 1
# Check if files are modified (outdated screenshots)
Status=$(git status --porcelain | grep -F '.jpeg' || exit 0)
Expand All @@ -142,9 +148,16 @@ jobs:
fi
exit 0
- name: Upload release notes
if: ${{ inputs.upload-release-notes == true && (env.GENERATE_DOCUMENTATION == 'true') }}
uses: actions/upload-artifact@v4
with:
name: release-notes
path: docs/build/release_notes.md

- name: Build and check the wheel
run: |
nox --non-interactive${{ inputs.container && format(' --session "docker_run_compiler({0})" --', inputs.gcc) || '' }} --session build_wheel
nox --non-interactive $NOX_CONTAINER_ARGUMENTS --session build_wheel
- name: Upload distribution
if: ${{ inputs.upload-dist == true }}
Expand All @@ -156,7 +169,7 @@ jobs:
- name: Build and check standalone application
if: ${{ (!inputs.container && !startsWith(inputs.python-version,'pypy')) || (inputs.container && (inputs.gcc != 'gcc-5') && (inputs.gcc != 'gcc-6')) }}
run: |
nox --non-interactive${{ inputs.container && format(' --session "docker_run_compiler({0})" --', inputs.gcc) || '' }} --session bundle_app
nox --non-interactive $NOX_CONTAINER_ARGUMENTS --session bundle_app
- name: Upload app bundle artifacts
if: ${{ inputs.upload-app == true }}
Expand Down
30 changes: 30 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,36 @@ def doc(session: nox.Session) -> None:
readme_html = session.create_tmp() + "/README.html"
session.run("rst2html5.py", "--strict", "README.rst", readme_html)

session.log("Create release_notes.md out of CHANGELOG.rst...")
changelog_rst = Path("CHANGELOG.rst")
with changelog_rst.open(encoding="utf-8") as fh_in:
lines = fh_in.readlines()

out_lines = []
iter_lines = iter(lines)
for line in iter_lines:
if line.startswith("------------"):
next(iter_lines)
break
if (line.rstrip())[:-1] == ":":
raise RuntimeError(f"Found section start before release ID: {line}")
else:
raise RuntimeError(f"Start of release changes not found in {changelog_rst}.")

for line in iter_lines:
if re.fullmatch(r"\d+\.\d+\s+\(.+\)", line.rstrip()):
break
line, _ = re.subn(r"``", r"`", line)
line, _ = re.subn(r":option:", r"", line)
line, _ = re.subn(r":issue:`(\d+)`", r"#\1", line)
out_lines.append(line)
else:
raise RuntimeError(f"End of release changes not found in {changelog_rst}.")

release_notes_md = Path() / "doc" / "build" / "release_notes.md"
with release_notes_md.open("w", encoding="utf-8") as fh_out:
fh_out.writelines(out_lines)


@nox.session
def tests(session: nox.Session) -> None:
Expand Down

0 comments on commit 2b2c269

Please sign in to comment.