Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger GitHub release/publish explicitly, scripts cleanup #682

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
82 changes: 5 additions & 77 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on:
pull_request:
push:
branches: [main, master]
branches: [ main, master ]

env:
RUSTFLAGS: "-C debuginfo=0 -D warnings"
Expand All @@ -18,8 +18,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-latest, ubuntu-latest]
toolchain: [stable, beta, nightly]
os: [ macos-latest, windows-latest, ubuntu-latest ]
toolchain: [ stable, beta, nightly ]
include:
- os: macos-latest
MACOS: true
Expand All @@ -28,14 +28,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: install linux deps
run: |
sudo apt update
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The action's Ubuntu image comes with the package list already. No need to update unless we need a package that was first published several days ago.

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
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ids are only needed to refer to this step somewhere else, no need in that right now.

run: rustup toolchain install ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}

- run: cargo clippy -- -D warnings
Expand All @@ -55,72 +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
cargo-publish:
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
env:
CRATESIO_TOKEN: ${{ secrets.CRATESIO_TOKEN }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update apt
run: sudo apt update
- name: Install alsa
run: sudo apt install -y --no-install-recommends libasound2-dev pkg-config
- name: Run cargo publish for rodio
continue-on-error: true
run: |
RODIO_TMP=$(mktemp /tmp/rodioXXX.txt) || echo "::error::mktemp error"
echo "RODIO_TMP=$RODIO_TMP" >> $GITHUB_ENV
cargo publish --token $CRATESIO_TOKEN 2> $RODIO_TMP
- name: Check if rodio is already published
run: |
empty=0
RODIO_TMP="${{ env.RODIO_TMP }}"
grep -q '[^[:space:]]' < $RODIO_TMP || empty=1
[ $empty -eq 0 ] && cat $RODIO_TMP
[ $empty -eq 1 ] || grep -q "is already uploaded" < $RODIO_TMP

create-git-tag:
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- name: Check if WORKFLOW_TOKEN is set
run: |
if [ -z "${{ secrets.WORKFLOW_TOKEN }}" ]; then
echo "Personal access token WORKFLOW_TOKEN is not set"
exit 1
else
echo "Checked `WORKFLOW_TOKEN` is set"
fi
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history to list all existing tags
token: ${{ secrets.WORKFLOW_TOKEN }}
- name: Extract version from Cargo.toml
id: extract_version
run: |
version=$(awk '/\[package\]/,/^version/ { if ($1 == "version") { gsub(/"/, "", $3); print $3 } }' Cargo.toml)
echo "Version value found: $version"
echo "version=$version" >> $GITHUB_OUTPUT
- name: Check if tag exists
id: check_tag
run: |
version=${{ steps.extract_version.outputs.version }}
version_name="v$version"
if git rev-parse "refs/tags/$version_name" >/dev/null 2>&1; then
echo "Tag $version_name already exists"
echo "tag_exists=true" >> $GITHUB_OUTPUT
else
echo "Tag $version_name does not exist"
echo "tag_exists=false" >> $GITHUB_OUTPUT
fi
- name: Create and push tag
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting these steps into separate runs, in turn required to pass things between them, which is too complex.
Also sh/bash convention is to use uppercase for variable names.
(If really necessary .inputs and .outputs seems to be the way to do it).

Copy link
Collaborator

@dvdsk dvdsk Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is such pain to pass things between steps..... Honestly for my other projects the github CI just calls a bash file (thats all it does). Bash is just as cursed as these workflows but at least I know bash and I can test it locally.

if: steps.check_tag.outputs.tag_exists == 'false'
run: |
version=${{ steps.extract_version.outputs.version }}
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
version_name="v$version"
git tag -a "$version_name" -m "Release for $version_name"
git push origin $version_name
40 changes: 40 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Publish

on: workflow_dispatch
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes this workflow available for manual triggering on the project's Action tab.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call, we do not release that often so making it a conscious choice seems the right thing to do


jobs:
cargo-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.version_tag }}

- name: Fetch tags
run: git fetch --prune --unshallow --tags
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default checkout is shallow last-version-only. This also fetches all the tags. Previous version tried to clone the whole repo every time.


- name: Install linux build requirements
run: sudo apt install --yes --no-install-recommends libasound2-dev pkg-config

- name: Publish and tag
run: |
echo "Current git commit is $(git rev-list -n 1 HEAD)."
VERSION="$(yq '.package.version' Cargo.toml)"
Copy link
Collaborator Author

@PetrGlad PetrGlad Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yq is installed by default in GitHub's Ubuntu. Unfortunately it cannot write TOML yet. If it could we could also automatically update the cargo version to something likemajor.minor.(patch+1)-dev.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lots cleaner then the grep | cut etc hack we had here, nice!

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"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be the actual GitHub user that executes these scripts, and it is recommended in the checkout action documentation.

git tag --annotate "$VERSION_TAG" --message "Release version $VERSION_TAG"
git push origin "$VERSION_TAG"
17 changes: 15 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,24 @@ how to approach a particular task or contribution, don't hesitate to
reach out to the maintainers for guidance.

# Guidelines for Maintainers

Guidelines for those with write access to rodio. Adhere to them as long as makes
sense. This is a work in progress, more might follow as we get to know
what works.

Please feel free to open an issue and discuss these if you have a suggestion.

1. Do not merge your own code to main, unless of course its a trivial change.
For example spelling/grammar or fixing up a PR by someone else.
Do not merge your own code to main, unless of course its a trivial change.
For example spelling/grammar or fixing up a PR by someone else.

## 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`.
Loading