Skip to content

Commit

Permalink
Create tag after publish, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrGlad committed Jan 19, 2025
1 parent dad6ebf commit f3e8684
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 53 deletions.
37 changes: 2 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: install linux deps
run: |
sudo apt update
sudo apt install -y --no-install-recommends libasound2-dev pkg-config
- name: Install linux build requirements
run: sudo apt install --yes --no-install-recommends libasound2-dev pkg-config
if: contains(matrix.os, 'ubuntu')

- name: install ${{ matrix.toolchain }} toolchain
id: install_toolchain
run: rustup toolchain install ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}

- run: cargo clippy -- -D warnings
Expand All @@ -55,33 +52,3 @@ jobs:
# Check minimal build. `tests/seek.rs` fails if there are no decoders at all,
# adding one to make the tests check pass.
- run: cargo check --tests --lib --no-default-features --features mp3

create-git-tag:
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Checkout the code.
uses: actions/checkout@v4

- name: Fetch tags.
#### FIXME Test this (it should fetch all tags without getting the history).
run: git fetch --prune --unshallow --tags

- name: Create a tag for current version if it does not exist yet.
id: create_version_tag
run: |
echo "Current git commit is $(git rev-list -n 1 HEAD)."
VERSION="$(yq '.package.version' Cargo.toml)"
echo "Project version from Cargo.toml: $VERSION"
VERSION_TAG="v$VERSION"
if git tag | grep "$VERSION_TAG"; then
echo "Tag $VERSION_TAG already exists at $(git rev-list -n 1 $VERSION_TAG), leaving it unchanged."
else
echo "Creating new tag $VERSION_TAG ..."
###### FIXME Review this using https://github.com/actions/checkout
###### User name and email may need to be updated.
git config user.name 'github-actions'
git config user.email '[email protected]'
git tag --annotate "$VERSION_TAG" --message "Release version $VERSION_TAG"
git push origin "$VERSION_TAG"
endif
48 changes: 30 additions & 18 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
name: Publish

on:
workflow_dispatch:
inputs:
version_tag:
description: 'Rodio version git tag to publish.'
required: true
on: workflow_dispatch

jobs:
cargo-publish:
env:
CRATESIO_TOKEN: ${{ secrets.CRATESIO_TOKEN }}
runs-on: ubuntu-latest
steps:
- name: Check if the git reference looks like a version tag.
run: |
echo "${{ inputs.version_tag }}" \
| grep --quiet "^v[0-9]\{1,2\}\.[0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\?$"
- uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.version_tag }}
- name: Update list of apt packages.
run: sudo apt update
- name: Install alsa.

- name: Fetch tags
run: git fetch --prune --unshallow --tags

- name: Install linux build requirements
run: sudo apt install --yes --no-install-recommends libasound2-dev pkg-config
- name: Publish rodio to crates.io.
run: cargo publish --token "$CRATESIO_TOKEN"

- name: Publish and tag
run: |
echo "Current git commit is $(git rev-list -n 1 HEAD)."
VERSION="$(yq '.package.version' Cargo.toml)"
echo "Project version from Cargo.toml is $VERSION"
VERSION_TAG="v$VERSION"
if git tag | grep --quiet "^$VERSION_TAG$"; then
echo "Tag $VERSION_TAG already exists at $(git rev-list -n 1 $VERSION_TAG), not publishing the crate."
exit 1
fi
cargo publish --token "${{ secrets.CRATESIO_TOKEN }}"
echo "Tagging current version with $VERSION_TAG ..."
# The bot name and email is taken from here https://github.com/actions/checkout/pull/1707
# see also https://api.github.com/users/github-actions%5Bbot%5D
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag --annotate "$VERSION_TAG" --message "Release version $VERSION_TAG"
git push origin "$VERSION_TAG"
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,17 @@ We understand that every situation is unique and encourage contributors
to use their best judgment. If you have any doubts or questions about
how to approach a particular task or contribution, don't hesitate to
reach out to the maintainers for guidance.

## Guidelines for Maintainers

### Release Procedure

The project is built automatically by a GitHub action when a new revision is pushed to the master branch.
The crate is published by triggering `.github/workflows/manual.yml` GitHub action.
After the crate is successfully published a new git tag is created in the repository.

So to publish a new version
1. Update `project.version` field in `Cargo.toml`.
2. Push the changes to the `master` branch.
3. Wait until GitHub build job completes successfully.
4. [On the Actions page](https://github.com/RustAudio/rodio/actions) start `.github/workflows/manual.yml`.

0 comments on commit f3e8684

Please sign in to comment.