Skip to content

Commit

Permalink
workflows: Add awk magic to GH changelog generation
Browse files Browse the repository at this point in the history
* Create a changelog file with awk
* Add both "dist" and "changelog" to artifact
* This changes the artifact handling: Now the dist
  directory is inside the artifact (instead of the contents
  of the directory being in the directory): this means the
  default path now works for `download-artifact`
* Dump changelog into the release body

Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
  • Loading branch information
jku committed Apr 6, 2024
1 parent 2d6fc74 commit c1d390d
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/cd.yml
Expand Up @@ -30,17 +30,20 @@ jobs:
- name: Install build dependency
run: python3 -m pip install --constraint requirements/build.txt build

- name: Build binary wheel and source tarball
run: PIP_CONSTRAINT=requirements/build.txt python3 -m build --sdist --wheel --outdir dist/ .
- name: Build binary wheel, source tarball and changelog
env:
TAG: ${{ github.ref_name }}
run: |
PIP_CONSTRAINT=requirements/build.txt python3 -m build --sdist --wheel --outdir dist/ .
awk "/## $TAG/{flag=1; next} /## v/{flag=0} flag" docs/CHANGELOG.md > changelog
- name: Store build artifacts
uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1
# NOTE: The GitHub release page contains the release artifacts too, but using
# GitHub upload/download actions seems robuster: there is no need to compute
# download URLs and tampering with artifacts between jobs is more limited.
with:
name: build-artifacts
path: dist
path: |
dist
changelog
candidate_release:
name: Release candidate on Github for review
Expand All @@ -55,7 +58,6 @@ jobs:
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
with:
name: build-artifacts
path: dist

- id: gh-release
name: Publish GitHub release draft
Expand All @@ -68,7 +70,7 @@ jobs:
repo: context.repo.repo,
name: '${{ github.ref_name }}-rc',
tag_name: '${{ github.ref }}',
body: 'Release waiting for review...',
body: fs.readFileSync('changelog', 'utf8'),
});
fs.readdirSync('dist/').forEach(file => {
Expand All @@ -95,7 +97,6 @@ jobs:
uses: actions/download-artifact@c850b930e6ba138125429b7e5c93fc707a7f8427 # v4.1.4
with:
name: build-artifacts
path: dist

- name: Publish binary wheel and source tarball on PyPI
# Only attempt pypi upload in upstream repository
Expand All @@ -111,7 +112,4 @@ jobs:
repo: context.repo.repo,
release_id: '${{ needs.candidate_release.outputs.release_id }}',
name: '${{ github.ref_name }}',
body: 'See [CHANGELOG.md](https://github.com/' +
context.repo.owner + '/' + context.repo.repo +
'/blob/${{ github.ref_name }}/docs/CHANGELOG.md) for details.'
})

0 comments on commit c1d390d

Please sign in to comment.