Skip to content

Publish to crates.io #6

Publish to crates.io

Publish to crates.io #6

Workflow file for this run

name: Publish to crates.io
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
workflow_dispatch:
inputs:
tag:
description: "Tag to release (e.g. v0.1.0)"
required: true
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
ref: master
- name: Validate tag format
id: version
run: |
TAG="${{ github.event.inputs.tag || env.GITHUB_REF_NAME }}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "ERROR: tag '$TAG' is not in vX.Y.Z format" >&2
exit 1
fi
VERSION="${TAG#v}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Setup Rust
uses: esp-rs/xtensa-toolchain@v1.6
with:
default: true
buildtargets: esp32
ldproxy: true
- name: Enable caching
uses: Swatinem/rust-cache@v2
- name: Bump version in Cargo.toml
run: |
VERSION="${{ steps.version.outputs.version }}"
MANIFEST="esp-wifi-provisioning/Cargo.toml"
if ! grep -q '^version = ' "$MANIFEST"; then
echo "ERROR: could not find 'version = ' in $MANIFEST" >&2
exit 1
fi
sed -i "0,/^version = .*/s//version = \"$VERSION\"/" "$MANIFEST"
echo "Bumped $MANIFEST to $VERSION"
grep '^version = ' "$MANIFEST"
- name: Commit version bump
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add esp-wifi-provisioning/Cargo.toml
# The xtensa-toolchain action leaves untracked zip files in the
# working directory; skip the commit gracefully if the version was
# already correct and nothing actually changed.
if git diff --cached --quiet; then
echo "Cargo.toml already at version ${{ steps.version.outputs.version }}, skipping commit"
else
git commit -m "chore: bump version to ${{ steps.version.outputs.version }}"
git push origin master
fi
- name: Move tag to version bump commit
run: |
TAG="${{ steps.version.outputs.tag }}"
git tag -f "$TAG"
git push origin "refs/tags/$TAG" --force
- name: Publish to crates.io
continue-on-error: true
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --package esp-wifi-provisioning --allow-dirty
- name: Create GitHub release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create "${{ steps.version.outputs.tag }}" \
--title "${{ steps.version.outputs.tag }}" \
--generate-notes \
--verify-tag