Skip to content

Commit

Permalink
Add release workflows
Browse files Browse the repository at this point in the history
Follow the example of houseabsolute/ubi to use cross-rs/cross to
cross-compile binaries for multiple platforms and architectures. Use
`musl` where available to support both `glibc` and `musl` Linux
distributions. Test for every push against stable, beta, and nightly,
and build archives that contain the license, readme, and change log, as
well as the `pgxn_meta` binary.

Also add a workflow to publish on crates.io, and add a dependency check
step to the lint and test workflow.

Add `CHANGELOG.md` for tracking changes, and update `Cargo.toml` for
distribution on crates.io.

Revise the README for the crate and binary.
  • Loading branch information
theory committed Aug 7, 2024
1 parent 6fb932d commit 0f2833c
Show file tree
Hide file tree
Showing 7 changed files with 337 additions and 6 deletions.
188 changes: 188 additions & 0 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
name: 🚀 Build and Release
on:
push:
branches-ignore: [wip/**]
tags: ["**"]
pull_request:
env:
CRATE_NAME: pgxn_meta
GITHUB_TOKEN: ${{ github.token }}
RUST_BACKTRACE: 1
permissions:
contents: write
jobs:
release:
name: ${{ matrix.platform.emoji }} ${{ matrix.platform.os_name }} 🦀 ${{ matrix.toolchain }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform:
- os_name: freebsd-amd64
os: ubuntu-20.04
target: x86_64-unknown-freebsd
bin: pgxn_meta
emoji: 😈
skip_tests: true
- os_name: linux-amd64
os: ubuntu-20.04
target: x86_64-unknown-linux-musl
bin: pgxn_meta
emoji: 🐧
- os_name: linux-arm64
os: ubuntu-20.04
target: aarch64-unknown-linux-musl
bin: pgxn_meta
emoji: 🐧
- os_name: linux-arm
os: ubuntu-20.04
target: arm-unknown-linux-musleabi
bin: pgxn_meta
emoji: 🐧
- os_name: linux-i686
os: ubuntu-20.04
target: i686-unknown-linux-musl
bin: pgxn_meta
emoji: 🐧
- os_name: linux-powerpc
os: ubuntu-20.04
target: powerpc-unknown-linux-gnu
bin: pgxn_meta
emoji: 🐧
- os_name: linux-powerpc64
os: ubuntu-20.04
target: powerpc64-unknown-linux-gnu
bin: pgxn_meta
emoji: 🐧
- os_name: linux-powerpc64le
os: ubuntu-20.04
target: powerpc64le-unknown-linux-gnu
bin: pgxn_meta
emoji: 🐧
- os_name: linux-riscv64
os: ubuntu-20.04
target: riscv64gc-unknown-linux-gnu
bin: pgxn_meta
emoji: 🐧
- os_name: linux-s390x
os: ubuntu-20.04
target: s390x-unknown-linux-gnu
bin: pgxn_meta
emoji: 🐧
- os_name: linux-sparc64
os: ubuntu-20.04
target: sparc64-unknown-linux-gnu
bin: pgxn_meta
emoji: 🐧
- os_name: netbsd-amd64
os: ubuntu-20.04
target: x86_64-unknown-netbsd
bin: pgxn_meta
emoji: ⛳️
skip_tests: true
- os_name: windows-arm64
os: windows-latest
target: aarch64-pc-windows-msvc
bin: pgxn_meta.exe
emoji: 🪟
skip_tests: true
- os_name: windows-i686
os: windows-latest
target: i686-pc-windows-msvc
bin: pgxn_meta.exe
emoji: 🪟
- os_name: windows-amd64
os: windows-latest
target: x86_64-pc-windows-msvc
bin: pgxn_meta.exe
emoji: 🪟
- os_name: darwin-amd64
os: darwin-latest
target: x86_64-apple-darwin
bin: pgxn_meta
emoji: 🍎
- os_name: darwin-arm64
os: darwin-latest
target: aarch64-apple-darwin
bin: pgxn_meta
emoji: 🍎
- os_name: illumos-amd64
os: ubuntu-20.04
target: x86_64-unknown-illumos
bin: pgxn_meta
emoji: 🐦‍🔥
skip_tests: true
toolchain:
- stable
- beta
- nightly
exclude:
# Not sure why this is failing.
- toolchain: nightly
platform: { os_name: linux-arm64 }
steps:
- uses: actions/checkout@v4
- name: Setup Cache
uses: Swatinem/rust-cache@v2
- name: Install musl-tools on Linux
run: sudo apt-get update --yes && sudo apt-get install --yes musl-tools
if: contains(matrix.platform.name, 'musl')
- name: Build Binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: "build"
target: ${{ matrix.platform.target }}
toolchain: ${{ matrix.toolchain }}
args: "--locked --release"
strip: true
- name: Run Tests
uses: houseabsolute/actions-rust-cross@v0
with:
command: "test"
target: ${{ matrix.platform.target }}
toolchain: ${{ matrix.toolchain }}
args: "--locked --release"
if: ${{ !matrix.platform.skip_tests }}
- name: Get the Version
if: env.VERSION == ''
run: echo "VERSION=$(grep "^version" Cargo.toml | sed -r 's/version[^"]+"([^"]+).*/\1/')" >> $GITHUB_ENV
- name: Determine Archive Name
shell: bash
run: |
echo "ARCHIVE=pgxn_meta-v$VERSION-${{ matrix.platform.os_name }}" >> $GITHUB_ENV
- name: Package Archive
shell: bash
run: |
printf "Packaging %s\n" "$ARCHIVE"
mkdir "$ARCHIVE"
cp "target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}" "$ARCHIVE"/
cp {README.md,CHANGELOG.md,LICENSE.md} "$ARCHIVE"/
if [[ "${{ matrix.platform.os }}" == "windows-latest" ]]; then
7z a "$ARCHIVE.zip" "$ARCHIVE"
else
tar czvf "$ARCHIVE.tar.gz" "$ARCHIVE"
fi
if: |
matrix.toolchain == 'stable' &&
( startsWith( github.ref, 'refs/tags/v' ) ||
github.ref == 'refs/tags/test-release' )
- name: Publish Artifacts
uses: actions/upload-artifact@v4
with:
path: "pgxn_meta-*"
if: matrix.toolchain == 'stable' && github.ref == 'refs/tags/test-release'
- name: Check the Version
shell: bash
run: |
if [ "${{ github.ref_name }}" != "v$VERSION" ]; then
printf "Cargo.toml version %s does not match tag %s\n" "$VERSION" "${{ github.ref_name }}" >&2
exit 1
fi
if: matrix.toolchain == 'stable' && startsWith( github.ref, 'refs/tags/v' )
- name: Publish GitHub Release
uses: softprops/action-gh-release@v2
with:
draft: true
files: "pgxn_meta*"
body_path: CHANGELOG.md
if: matrix.toolchain == 'stable' && startsWith( github.ref, 'refs/tags/v' )
29 changes: 29 additions & 0 deletions .github/workflows/cargo-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 📦 Cargo Publish
on:
push:
branches-ignore: [wip/**]
tags: ["**"]
pull_request:
jobs:
test:
name: 📦 Cargo ${{ startsWith(github.ref, 'refs/tags') && 'Publish' || 'Package' }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust Cache
uses: Swatinem/rust-cache@v2
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with: { toolchain: stable }
- name: Package
run: cargo publish --dry-run
- name: Publish
run: |
v="v$(grep "^version" Cargo.toml | sed -r 's/version[^"]+"([^"]+).*/\1/')"
if [ "$v" != "$GITHUB_REF_NAME" ]; then
printf "Cargo.toml version %s does not match tag %s\n" "$v" "$GITHUB_REF_NAME" >&2
exit 1
fi
cargo publish
if: startsWith( github.ref, 'refs/tags/v' )
2 changes: 2 additions & 0 deletions .github/workflows/test-and-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
uses: dtolnay/rust-toolchain@stable
- name: Run pre-commit
uses: pre-commit/action@v3.0.1
- uses: actions-rust-lang/audit@v1
name: Audit Rust Dependencies
- name: Generate Coverage
run: make cover RUST_BACKTRACE=1
- name: Publish Coverage
Expand Down
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Changelog

All notable changes to this project will be documented in this file. It uses the
[Keep a Changelog] format, and this project adheres to [Semantic Versioning].

[Keep a Changelog]: https://keepachangelog.com/en/1.1.0/
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html
"Semantic Versioning 2.0.0"

## [v0.1.0] — 2024-08-07

The theme of this release is *Cross Compilation.*

### ⚡ Improvements

* First release, everything is new!
* JSON Schema for PGXN Meta Spec v1 and v2
* JSON Schema validation using [boon]
* Comprehensive Testing
* `pgxn_meta` binary and crate

### 🏗️ Build Setup

* Built with Rust
* Use [cross] and [actions-rust-cross] to cross-compile and release binaries
for multiple OSes
* Install from [crates.io] or [GitHub]

### 📚 Documentation

* Build and install docs in the [README]

[v0.1.0]: https://github.com/pgxn/meta/compare/4c207a6...v0.1.0
[boon]: https://github.com/santhosh-tekuri/boon
[cross]: https://github.com/cross-rs/cross
[actions-rust-cross]: https://github.com/houseabsolute/actions-rust-cross
[crates.io]: https://crates.io/crates/pgxn_meta
[GitHub]: https://github.com/pgxn/meta/releases
[README]: https://github.com/pgxn/meta/blob/v0.1.0/README.md
15 changes: 14 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ name = "pgxn_meta"
version = "0.1.0"
description = "The PGXN distribution metadata specification"
repository = "https://github.com/pgxn/pgxn-meta-spec"
documentation = "https://docs.rs/pgxn_meta/"
authors = ["David E. Wheeler <david@justatheory.com>"]
readme = "README.md"
keywords = ["pgxn", "postgres", "postgresql", "extension", "validation", "distribution"]
license = "PostgreSQL"
categories = ["web-programming", "database"]
edition = "2021"
exclude = [ ".github", ".gitattributes", "target", ".vscode", ".gitignore" ]
exclude = [ ".github", ".vscode", ".gitignore", ".ci", ".pre-*.yaml"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -26,3 +28,14 @@ wax = "0.6.0"
serde_json = "1.0"

[dev-dependencies]

# workaround for https://github.com/cross-rs/cross/issues/1345
[package.metadata.cross.target.x86_64-unknown-netbsd]
pre-build = [
"mkdir -p /tmp/netbsd",
"curl https://cdn.netbsd.org/pub/NetBSD/NetBSD-9.2/amd64/binary/sets/base.tar.xz -O",
"tar -C /tmp/netbsd -xJf base.tar.xz",
"cp /tmp/netbsd/usr/lib/libexecinfo.so /usr/local/x86_64-unknown-netbsd/lib",
"rm base.tar.xz",
"rm -rf /tmp/netbsd",
]
2 changes: 2 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build.env]
passthrough = ["GITHUB_TOKEN"]
68 changes: 63 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
PGXN Meta &emsp; [![license-badge]][license] [![ci-badge]][ci] [![cov-badge]][cov] [![deps-badge]][deps]
=========
# PGXN Meta

[![license-badge]][license] [![crates-badge]][crates] [![docs-badge]][docs] [![ci-badge]][ci] [![cov-badge]][cov] [![deps-badge]][deps]


**The pgxn_meta crate provides [PGXN Meta Spec] validation**

Expand All @@ -9,8 +11,8 @@ The [PGXN Meta Spec] defines the requirements for the metadata file
(`META.json`) file for [PGXN] source distribution packages. This project
provides Rust a crates for working with spec `META.json` files.

Example
-------
Crate Usage
-----------

<details>
<summary>Click to show `Cargo.toml`.</summary>
Expand Down Expand Up @@ -51,6 +53,53 @@ func main() {
}
```

See the [`pgxn_meta` docs on docs.rs] for complete details.

Installation
------------

There are several ways to install `pgxn_meta`.

### Use `ubi`

Install the [universal binary installer (ubi)](https://github.com/houseabsolute/ubi) and
use it to install `pgxn_meta` and many other tools.

``` console
$ ubi --project pgxn/meta --in ~/bin
```

### Binary Releases

Grab the appropriate binary [release], untar or unzip it, and put the
`pgxn_meta` executable somewhere in your path.

### Cargo

Install `pgxn_meta` via `cargo` by running:

``` sh
cargo install pgxn_meta
```

See the [cargo docs] to learn where the binary will be installed.

Usage
-----

Simply execute `pgxn_meta` to validate the PGXN `META.json` file in the
current directory:

``` sh
pgxn_meta
```

If the file has a different name, simply pass it:

``` sh
pgxn_meta widget.json
```

Contributing
------------

Expand All @@ -67,6 +116,10 @@ This project is distributed under the [PostgreSQL License][license].

[license-badge]: https://img.shields.io/badge/License-PostgreSQL-blue.svg
[license]: https://opensource.org/licenses/PostgreSQL "⚖️ PostgreSQL License"
[crates-badge]: https://img.shields.io/crates/v/pgxn_meta.svg
[crates]: https://crates.io/crates/pgxn_meta
[docs-badge]: https://docs.rs/pgxn_meta/badge.svg
[docs]: https://docs.rs/pgxn_meta
[ci-badge]: https://github.com/pgxn/meta/actions/workflows/test-and-lint.yml/badge.svg
[ci]: https://github.com/pgxn/meta/actions/workflows/test-and-lint "🧪 Test and Lint"
[cov-badge]: https://codecov.io/gh/pgxn/meta/graph/badge.svg?token=5DOLLPIHEO
Expand All @@ -75,5 +128,10 @@ This project is distributed under the [PostgreSQL License][license].
[deps]: https://deps.rs/repo/github/pgxn/meta "📦 Dependency Status"
[PGXN Meta Spec]: https://rfcs.pgxn.org/0001-meta-spec-v1.html
[PGXN]: https://pgxn.org "PGXN: PostgreSQL Extension Network"
[`pgxn_meta` docs on docs.rs]: https://docs.rs/ubi/latest/pgxn_meta/
[universal binary installer (ubi)]: https://github.com/houseabsolute/ubi
[release]: https://github.com/pgxn/meta/releases
[cargo docs]: https://doc.rust-lang.org/cargo/commands/cargo-install.html
[PostgresSQL Code of Conduct]: https://www.postgresql.org/about/policies/coc/
[Issues]: https://github.con/pgxn/meta/issues
[Issues]: https://github.com/pgxn/meta/issues
[Pull Requests]: https://github.com/pgxn/meta/pulls

0 comments on commit 0f2833c

Please sign in to comment.