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
142 changes: 142 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# Copyright 2026 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.

name: Release

on:
push:
branches:
- main
paths:
- 'Cargo.toml'
- 'zerocopy-derive/Cargo.toml'

permissions:
contents: write
id-token: write

concurrency:
group: release
cancel-in-progress: false

jobs:
check-version:
runs-on: ubuntu-latest
# Don't run this on forks.
if: github.repository == 'google/zerocopy'
outputs:
changed: ${{ steps.check.outputs.changed }}
version: ${{ steps.check.outputs.version }}
prerelease: ${{ steps.check.outputs.prerelease }}
env:
CARGO_ZEROCOPY_AUTO_INSTALL_TOOLCHAIN: 1
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0 # Fetch all history for version comparison and tags

# Checks whether zerocopy's version (in `Cargo.toml`) or zerocopy-derive's
# version (in `zerocopy-derive/Cargo.toml`) were updated in this commit.
# We check below to make sure they're the same; the point of checking both
# (which is unnecessary if the commit correctly updates both) is to catch
# situations where one is updated – we want to catch it regardless of
# *which* one is updated.
- name: Determine if version was updated
id: check
run: |
set -eo pipefail

# Get current versions
CUR_VER_ZC=$(./cargo.sh +stable metadata -q --format-version 1 | jq -r '.packages[] | select(.name == "zerocopy").version')
CUR_VER_DERIVE=$(./cargo.sh +stable metadata -q --format-version 1 | jq -r '.packages[] | select(.name == "zerocopy-derive").version')

# Get previous versions using cargo metadata by temporarily checking it out
git checkout -q HEAD^
PREV_VER_ZC=$(./cargo.sh +stable metadata -q --format-version 1 | jq -r '.packages[] | select(.name == "zerocopy").version')
PREV_VER_DERIVE=$(./cargo.sh +stable metadata -q --format-version 1 | jq -r '.packages[] | select(.name == "zerocopy-derive").version')
git checkout -q -

if [ "$CUR_VER_ZC" != "$PREV_VER_ZC" ] || [ "$CUR_VER_DERIVE" != "$PREV_VER_DERIVE" ]; then
echo "Version change detected."
echo "changed=true" >> $GITHUB_OUTPUT
echo "version=$CUR_VER_ZC" >> $GITHUB_OUTPUT

if [[ "${CUR_VER_ZC%+*}" == *-* ]]; then
echo "prerelease=true" >> $GITHUB_OUTPUT
else
echo "prerelease=false" >> $GITHUB_OUTPUT
fi
else
echo "Version unchanged."
echo "changed=false" >> $GITHUB_OUTPUT
fi

release:
needs: check-version
if: needs.check-version.outputs.changed == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
env:
CARGO_ZEROCOPY_AUTO_INSTALL_TOOLCHAIN: 1
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: Sanity check versions
run: ./ci/check_versions.sh

- name: Dry-run publish
run: |
set -eo pipefail

./cargo.sh +stable publish --dry-run --package zerocopy-derive --registry crates-io
./cargo.sh +stable publish --dry-run --package zerocopy --registry crates-io

- name: Check if tag already exists
run: |
set -eo pipefail

TAG="v${{ needs.check-version.outputs.version }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Error: Tag $TAG already exists." >&2
exit 1
fi

- name: Create git tag
run: |
set -eo pipefail

TAG="v${{ needs.check-version.outputs.version }}"
git config user.name "Google PR Creation Bot"
git config user.email "github-pull-request-creation-bot@google.com"
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"

# NOTE: Relies on OIDC to be configured for this GHA workflow.
- name: Publish zerocopy-derive
run: ./cargo.sh +stable publish --package zerocopy-derive --registry crates-io

- name: Wait for crates.io index propagation
run: sleep 30

# NOTE: Relies on OIDC to be configured for this GHA workflow.
- name: Publish zerocopy
run: ./cargo.sh +stable publish --package zerocopy --registry crates-io

- name: Create GitHub Release
uses: softprops/action-gh-release@c062e08bd5704bfa3b69f0c2a9c440319b85f3cf # v2.0.8
with:
tag_name: v${{ needs.check-version.outputs.version }}
generate_release_notes: true
prerelease: ${{ needs.check-version.outputs.prerelease == 'true' }}
latest: ${{ needs.check-version.outputs.prerelease != 'true' }}
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
[package]
edition = "2021"
name = "zerocopy"
version = "0.8.42"
version = "0.8.43"
authors = [
"Joshua Liebow-Feeser <joshlf@google.com>",
"Jack Wrenn <jswrenn@amazon.com>",
Expand Down Expand Up @@ -112,13 +112,13 @@ __internal_use_only_features_that_work_on_stable = [
]

[dependencies]
zerocopy-derive = { version = "=0.8.42", path = "zerocopy-derive", optional = true }
zerocopy-derive = { version = "=0.8.43", path = "zerocopy-derive", optional = true }

# The "associated proc macro pattern" ensures that the versions of zerocopy and
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
# See: https://github.com/matklad/macro-dep-test
[target.'cfg(any())'.dependencies]
zerocopy-derive = { version = "=0.8.42", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.8.43", path = "zerocopy-derive" }

[dev-dependencies]
# FIXME(#381) Remove this dependency once we have our own layout gadgets.
Expand All @@ -129,4 +129,4 @@ rustversion = "1.0"
static_assertions = "1.1"
testutil = { path = "testutil" }
# In tests, unlike in production, zerocopy-derive is not optional
zerocopy-derive = { version = "=0.8.42", path = "zerocopy-derive" }
zerocopy-derive = { version = "=0.8.43", path = "zerocopy-derive" }
2 changes: 1 addition & 1 deletion zerocopy-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[package]
edition = "2021"
name = "zerocopy-derive"
version = "0.8.42"
version = "0.8.43"
authors = ["Joshua Liebow-Feeser <joshlf@google.com>", "Jack Wrenn <jswrenn@amazon.com>"]
description = "Custom derive for traits from the zerocopy crate"
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
Expand Down
Loading