-
Notifications
You must be signed in to change notification settings - Fork 247
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
Changes from 3 commits
dad6ebf
f3e8684
2c801ba
ae7acb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ name: CI | |
on: | ||
pull_request: | ||
push: | ||
branches: [main, master] | ||
branches: [ main, master ] | ||
|
||
env: | ||
RUSTFLAGS: "-C debuginfo=0 -D warnings" | ||
|
@@ -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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Publish | ||
|
||
on: workflow_dispatch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" |
There was a problem hiding this comment.
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.