Skip to content

Commit

Permalink
Add ci publish workflow (#22)
Browse files Browse the repository at this point in the history
* Added initial workflow for publishing

* Adjusted trigger for testing purposes

* remove branch for testing

* adjusted format of release

* Reduced trigger criteria

* debugging commit

* Debugging the trigger

* removing if statement for CI passing

* release cycle verified and works

* Attempting to trigger it purely on tag based

* Added release

* workflow debugging

* Updated ReadMe and Added Release

* Updated dependencies

* Debugging

* commented out version handler

* Putting code back to state for Tagging and Release Management

* Updated if statement for checking if CI passed

* reset versioning number

* Changing order to check for tags first

* Latest changes on workflow

* adding staging release registry

* Added main check

* Making the code a bit clearer for publishing to crates.io

* Commented back in main registry push

* Removed staging registry

* Reverting back to old README

* Removed formatting change

* removed cargo.toml formatting

* removed staging registry environment variable
  • Loading branch information
ScottGibb authored Nov 18, 2024
1 parent 5b4f1d5 commit 1edb422
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Release

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

permissions:
contents: write

jobs:
# Re Run the Checks
check:
name: Check Rust
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install nightly
run: rustup toolchain add --component=rustfmt nightly
- name: Checks
run: ./ci.sh

release:
# Only run if the checks pass
name: Publish to crates.io
needs: check
runs-on: ubuntu-latest
timeout-minutes: 10
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Verify Version
run: |
TAG_VERSION=${GITHUB_REF#refs/tags/v}
CARGO_VERSION=$(grep '^version =' Cargo.toml | sed -E 's/version = "([^"]+)"/\1/')
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
echo "Version mismatch: tag is $TAG_VERSION but Cargo.toml is $CARGO_VERSION"
exit 1 # Exits with a non-zero status to fail the workflow
fi
shell: bash

- name: Set up Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable

- name: Build project
run: cargo build --release

- name: Create GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
run: |
gh release create "$tag" \
--repo="$GITHUB_REPOSITORY" \
--title="${GITHUB_REPOSITORY#*/} ${tag#v}" \
--generate-notes
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
# Publish to the main registry
run: |
echo "Publishing to crates.io"
cargo publish
# To publish to the staging/testing registry, uncomment the following lines
# run: |
# echo "Performing dry-run publish to crates.io"
# cargo publish --dry-run

0 comments on commit 1edb422

Please sign in to comment.