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
120 changes: 106 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
name: Make Release
on: workflow_dispatch
on:
workflow_dispatch:
release:
types: [published]

permissions:
contents: write
pull-requests: write

jobs:
release_create:
# Dispatch-only: when this workflow also runs on release publish, this job
# must not fire again on that event (it would create a second bump PR).
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest

outputs:
Expand All @@ -13,6 +23,8 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Set up Python 3.12
uses: actions/setup-python@v5
Expand All @@ -31,17 +43,48 @@ jobs:
- name: Get version
id: get_version
run: >-
poetry version --short | sed 's/^/::set-output name=version::/'
printf 'version=%s\n' "$(poetry version --short)" >> "$GITHUB_OUTPUT"

- name: Create version bump PR
id: bump_pr
uses: peter-evans/create-pull-request@v8
env:
VERSION: ${{ steps.get_version.outputs.version }}
with:
# The release tag points at the bump commit, which must live on a
# durable branch. It lands on master when this PR is merged with a
# merge commit (see the PR body note about merge vs squash).
# With the default GITHUB_TOKEN the PR needs a maintainer click to
# run CI and merge; set MESHTASTIC_AUTOMATION_TOKEN for fully
# unattended operation (see update_protobufs.yml).
token: ${{ secrets.MESHTASTIC_AUTOMATION_TOKEN || secrets.GITHUB_TOKEN }}
branch: release-bump/${{ env.VERSION }}
delete-branch: true
title: "bump version to ${{ env.VERSION }}"
commit-message: "bump version to ${{ env.VERSION }}"
body: |
Automated version bump to ${{ env.VERSION }} from the *Make Release*
workflow.

The release tag for ${{ env.VERSION }} points at this commit. Merge
(not squash) so the tag stays reachable from master.
add-paths: pyproject.toml

- name: Checkout bump commit
# create-pull-request commits to the PR branch and leaves the
# workspace restored to the base branch, so HEAD here is the pre-bump
# commit. Check out the bump commit so the tag and every build in
# this workflow use the bumped version.
uses: actions/checkout@v4
with:
ref: ${{ steps.bump_pr.outputs.pull-request-head-sha }}
persist-credentials: false

- name: Commit updated version.
- name: Record release commit
id: commit_updated
run: |
git config --global user.name 'github-actions'
git config --global user.email 'bot@noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git add pyproject.toml
git commit -m "bump version to ${{ steps.get_version.outputs.version }}" && git push || echo "No changes to commit"
git log -n 1 --pretty=format:"%H" | tail -n 1 | awk '{print "::set-output name=sha::"$0}'
set -euo pipefail
printf 'sha=%s\n' "$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

- name: Create GitHub release
uses: actions/create-release@v1
Expand All @@ -62,11 +105,14 @@ jobs:
run: >-
poetry build

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Validate distributions
# Dry-run for the PyPI upload: twine check validates the metadata PyPI
# itself would reject (long descriptions, README rendering, metadata
# syntax) without uploading anything. The real upload happens when the
# GitHub release is published (publish-to-pypi job).
run: |
python -m pip install --upgrade twine
twine check dist/*

# build-and-publish-mac:
# runs-on: macos-latest
Expand Down Expand Up @@ -115,6 +161,8 @@ jobs:
# asset_content_type: application/zip

build-and-publish-ubuntu:
# Dispatch-only, same reason as release_create.
if: github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
needs: release_create
steps:
Expand Down Expand Up @@ -181,3 +229,47 @@ jobs:
# asset_path: dist/meshtastic.exe
# asset_name: meshtastic_windows
# asset_content_type: application/zip

publish-to-pypi:
# The real PyPI upload happens when the GitHub release is published, so
# the draft release and the merge of the bump PR come first and a human
# decides when the version goes live. Nothing is uploaded on dispatch.
if: github.event_name == 'release'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout release commit
uses: actions/checkout@v4
with:
# The release tag points at the version-bump commit.
ref: refs/tags/${{ github.event.release.tag_name }}
persist-credentials: false

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Build a binary wheel and a source tarball
run: |
python -m pip install --upgrade pip
pip3 install poetry
poetry build

- name: Verify built version matches the release
run: |
set -euo pipefail
BUILT_VERSION="$(poetry version --short)"
TAG_VERSION="${GITHUB_REF_NAME#v}"
if [[ "${BUILT_VERSION}" != "${TAG_VERSION}" ]]; then
echo "::error::Built version ${BUILT_VERSION} does not match release tag ${GITHUB_REF_NAME}"
exit 1
fi
echo "Built ${BUILT_VERSION} matches release ${TAG_VERSION}"

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.14.3
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
65 changes: 53 additions & 12 deletions .github/workflows/update_protobufs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ on:
repository_dispatch:
types: [protobufs-release]

# Regens touch the same generated tree; run them one at a time instead of
# letting two dispatches race on the update branch.
concurrency:
group: update-protobufs
cancel-in-progress: false

permissions:
contents: write
pull-requests: write

jobs:
update-protobufs:
runs-on: ubuntu-latest
env:
# The secrets context cannot be referenced in a step-level `if`
# (actionlint: "context secrets is not allowed here"). Expose a flag
# that the auto-merge step can test through the env context instead.
HAS_AUTOMATION_TOKEN: ${{ secrets.MESHTASTIC_AUTOMATION_TOKEN != '' }}

steps:
- name: Checkout code
Expand Down Expand Up @@ -89,18 +101,47 @@ jobs:
run: |
./bin/regen-protobufs.sh

- name: Commit update
- name: Create protobufs update PR
id: pr
uses: peter-evans/create-pull-request@v8
env:
TARGET_VERSION: ${{ steps.version.outputs.version }}
with:
# With the default GITHUB_TOKEN the PR is created fine, but CI on it
# stays in "approval required" until a maintainer clicks "Approve
# workflows to run", and the merge is a human decision. Set
# MESHTASTIC_AUTOMATION_TOKEN (a PAT or GitHub App installation
# token with contents/pull-requests write access) to get CI and
# auto-merge with no human clicks.
token: ${{ secrets.MESHTASTIC_AUTOMATION_TOKEN || secrets.GITHUB_TOKEN }}
branch: update-protobufs/${{ env.TARGET_VERSION }}
delete-branch: true
title: "protobufs: ${{ env.TARGET_VERSION }}"
commit-message: "protobufs: ${{ env.TARGET_VERSION }}"
body: |
Regenerated `meshtastic/protobuf` bindings from
[meshtastic/protobufs ${{ env.TARGET_VERSION }}](https://github.com/meshtastic/protobufs/releases/tag/${{ env.TARGET_VERSION }}).

Generated by the *Update protobufs* workflow. Diffs under
`meshtastic/protobuf/` are generated code — review mechanically
(field additions/renames), not line-by-line.
add-paths: |
protobufs
meshtastic/protobuf

- name: Enable auto-merge
# GITHUB_TOKEN cannot enqueue into the master merge queue, so this only
# runs when MESHTASTIC_AUTOMATION_TOKEN is set.
if: >-
${{
(steps.pr.outputs.pull-request-operation == 'created' ||
steps.pr.outputs.pull-request-operation == 'updated') &&
env.HAS_AUTOMATION_TOKEN == 'true'
}}
env:
GH_TOKEN: ${{ secrets.MESHTASTIC_AUTOMATION_TOKEN }}
PR_NUMBER: ${{ steps.pr.outputs.pull-request-number }}
run: |
git config --global user.name 'github-actions'
git config --global user.email 'bot@noreply.github.com'
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
git add protobufs
git add meshtastic/protobuf
if [[ -n "$(git status --porcelain)" ]]; then
git commit -m "protobufs: ${TARGET_VERSION}"
git push
else
echo "No changes to commit"
fi
set -euo pipefail
echo "Enabling auto-merge for PR #${PR_NUMBER}"
gh pr merge "${PR_NUMBER}" --auto --merge
Loading