Skip to content
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
24 changes: 24 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Not a workflow: GitHub reads the generated-release-notes configuration from this path and
# nowhere else. The release itself is cut by the workflow under `.github/workflows/`.
#
# The generated list is appended under the hand-written CHANGELOG.md section, so it exists to
# credit contributors and link every pull request, not to describe the release. Dependency and
# tooling bumps are grouped so they do not sit between the real changes.
changelog:
exclude:
authors:
- github-actions[bot]
categories:
- title: Changes
labels:
- "*"
exclude:
labels:
- dependencies
- github_actions
- pre_commit
- title: Dependency and tooling updates
labels:
- dependencies
- github_actions
- pre_commit
16 changes: 10 additions & 6 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ on:
- unlabeled
branches:
- master
- main

permissions:
contents: read
Expand All @@ -28,33 +27,38 @@ jobs:
# The job runs unconditionally and decides inside the step, rather than skipping on an
# `if`: a skipped job reports as neither passing nor failing, and the reason a PR is
# exempt belongs in the log where the next reader will look for it.
- name: Require a changelog entry beside an engine change
- name: Require a changelog entry beside a user-visible change
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
# contains() matches an array element exactly, so a label carrying a comma or a
# name this one is a prefix of cannot be mistaken for it
SKIP_LABELLED: ${{ contains(github.event.pull_request.labels.*.name, 'no-changelog') }}
IS_DEPENDABOT: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
run: |
set -euo pipefail

if [ "${SKIP_LABELLED}" = "true" ]; then
echo "Labelled no-changelog; entry not required."
exit 0
fi
if [ "${IS_DEPENDABOT}" = "true" ]; then
echo "Dependency bump; the generated release notes list these under their own heading."
exit 0
fi

changed="$(gh api --paginate "repos/${REPOSITORY}/pulls/${PR_NUMBER}/files" --jq '.[].filename')"

if ! printf '%s\n' "${changed}" | grep -q '^src/smda/'; then
echo "No files under src/smda/ changed; entry not required."
if ! printf '%s\n' "${changed}" | grep -qE '^(src/smda/|pyproject.toml$)'; then
echo "No shipped files changed; entry not required."
exit 0
fi

if printf '%s\n' "${changed}" | grep -qx 'CHANGELOG.md'; then
echo "CHANGELOG.md touched beside the engine change."
echo "CHANGELOG.md touched beside the change."
exit 0
fi

echo "::error file=CHANGELOG.md::This PR changes src/smda/ but does not touch CHANGELOG.md. Add an entry under ## Unreleased describing what moved and what it cost, or apply the no-changelog label if the change genuinely needs no entry."
echo "::error file=CHANGELOG.md::This PR changes shipped files but does not touch CHANGELOG.md. Add an entry under ## [Unreleased], or apply the no-changelog label if the change genuinely needs no entry."
exit 1
266 changes: 266 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
name: Publish release

# A manual run rehearses against TestPyPI and stops before the GitHub release.
on:
push:
tags:
- "v*"
workflow_dispatch:

permissions:
contents: read

# A cancelled publish can leave PyPI holding some files of a version and not others, and the
# version number cannot be reused afterwards.
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false

defaults:
run:
shell: bash

env:
PYTHON_VERSION: "3.11"

jobs:
verify:
name: Verify the tag
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
actions: read
issues: read
outputs:
version: ${{ steps.guard.outputs.version }}
prerelease: ${{ steps.guard.outputs.prerelease }}
steps:
- name: Refuse anything that is not a tag
env:
REF_TYPE: ${{ github.ref_type }}
REF_NAME: ${{ github.ref_name }}
run: |
if [ "${REF_TYPE}" != "tag" ]; then
echo "::error::Run this from a tag, not ${REF_TYPE} ${REF_NAME}."
exit 1
fi

- name: Checkout the tag
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Check the tag against the packaged version and the changelog
id: guard
env:
TAG: ${{ github.ref_name }}
run: |
python .github/workflows/scripts/release_guard.py \
--tag "${TAG}" --notes release-notes.md --github-output "${GITHUB_OUTPUT}"

- name: Check the tag is on master
env:
TAG: ${{ github.ref_name }}
run: |
git fetch --quiet origin master
if ! git merge-base --is-ancestor "${TAG}" origin/master; then
echo "::error::${TAG} is not an ancestor of master; releases are cut from master."
exit 1
fi

- name: Check CI passed on this commit
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
SHA: ${{ github.sha }}
run: |
conclusion=$(gh api \
"repos/${REPO}/actions/workflows/ci.yml/runs?head_sha=${SHA}&status=completed" \
--jq '.workflow_runs[0].conclusion // ""')
if [ -z "${conclusion}" ]; then
echo "::error::No completed CI run for ${SHA}. Wait for master to go green, then re-run."
exit 1
fi
if [ "${conclusion}" != "success" ]; then
echo "::error::CI concluded '${conclusion}' for ${SHA}. Fix master before releasing."
exit 1
fi
echo "CI passed on ${SHA}"

- name: Check the milestone for this tag is finished
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
TAG: ${{ github.ref_name }}
run: |
open_items=$(gh api "repos/${REPO}/milestones?state=all&per_page=100" \
--jq "[.[] | select(.title == \"${TAG}\")] | .[0].open_issues // \"none\"")
if [ "${open_items}" = "none" ]; then
echo "::notice::No milestone named ${TAG}; releasing without one."
elif [ "${open_items}" != "0" ]; then
echo "::error::Milestone ${TAG} still has ${open_items} open item(s)."
exit 1
else
echo "Milestone ${TAG} reads 100%"
fi

- name: Keep the release notes for the later jobs
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: release-notes
path: release-notes.md
if-no-files-found: error

build:
name: Build and check the distribution
needs: verify
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout the tag
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Build the sdist and the wheel
run: |
python -m pip install --upgrade pip build twine
python -m build
python -m twine check --strict dist/*

# -P keeps the checkout off sys.path, so the import cannot fall back to the source tree
- name: Smoke-test the built wheel
env:
VERSION: ${{ needs.verify.outputs.version }}
run: |
python -m venv /tmp/smoke
/tmp/smoke/bin/python -m pip install --upgrade pip
/tmp/smoke/bin/python -m pip install dist/smda-"${VERSION}"-py3-none-any.whl
/tmp/smoke/bin/python -P - <<'PY'
import os
import pathlib

import smda
from smda.Disassembler import Disassembler
from smda.SmdaConfig import SmdaConfig

installed = pathlib.Path(smda.__file__).parent
assert "site-packages" in str(installed), f"imported a source tree: {installed}"
assert smda.__version__ == os.environ["VERSION"], smda.__version__
assert (installed / "py.typed").exists(), "py.typed did not ship"

raw = pathlib.Path("tests/cutwail_xored").read_bytes()
report = Disassembler(SmdaConfig()).disassembleUnmappedBuffer(
bytes(byte ^ (index % 256) for index, byte in enumerate(raw))
)
assert report.status == "ok", report.status
assert report.num_functions > 0, "the wheel recovered nothing"
print(f"smda {smda.__version__}: {report.num_functions} functions, status {report.status}")
PY

- name: Keep the distribution for the later jobs
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: distribution
path: dist/
if-no-files-found: error

publish:
name: Publish to ${{ github.event_name == 'workflow_dispatch' && 'TestPyPI' || 'PyPI' }}
needs: [verify, build]
runs-on: ubuntu-latest
timeout-minutes: 15
environment:
name: ${{ github.event_name == 'workflow_dispatch' && 'testpypi' || 'pypi' }}
url: ${{ github.event_name == 'workflow_dispatch' && 'https://test.pypi.org/p/smda' || 'https://pypi.org/p/smda' }}
permissions:
# mandatory for trusted publishing, and it must be the only credential in the job
id-token: write
steps:
- name: Fetch the distribution
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: distribution
path: dist

- name: Publish
uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # v1.14.2
with:
# empty resolves to PyPI: the canonical input carries no default and the action falls
# through to the deprecated alias, which defaults to the real index
repository-url: ${{ github.event_name == 'workflow_dispatch' && 'https://test.pypi.org/legacy/' || '' }}
# a PyPI collision means the version is already public, so only a rehearsal skips it
skip-existing: ${{ github.event_name == 'workflow_dispatch' }}
attestations: true
print-hash: true

release:
name: Create the GitHub release
needs: [verify, build, publish]
if: github.event_name != 'workflow_dispatch'
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
issues: write
steps:
- name: Fetch the distribution
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: distribution
path: dist

- name: Fetch the release notes
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: release-notes

# --generate-notes appends its list under --notes-file rather than replacing it, so the
# changelog section leads and `.github/release.yml` groups what follows. A pre-release
# is marked as such and never becomes "latest".
- name: Create the release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
TAG: ${{ github.ref_name }}
PRERELEASE: ${{ needs.verify.outputs.prerelease }}
run: |
shopt -s failglob
flags=(--latest)
if [ "${PRERELEASE}" = "true" ]; then
flags=(--prerelease --latest=false)
fi
gh release create "${TAG}" dist/* \
--repo "${REPO}" \
--title "${TAG}" \
--notes-file release-notes.md \
--generate-notes \
--verify-tag \
"${flags[@]}"

- name: Close the milestone for this tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
TAG: ${{ github.ref_name }}
run: |
number=$(gh api "repos/${REPO}/milestones?state=open&per_page=100" \
--jq "[.[] | select(.title == \"${TAG}\")] | .[0].number // \"\"")
if [ -z "${number}" ]; then
echo "No open milestone named ${TAG}; nothing to close."
else
gh api -X PATCH "repos/${REPO}/milestones/${number}" -f state=closed >/dev/null
echo "Closed milestone ${TAG}"
fi
Loading