-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #682 from PetrGlad/github-ci-publish-cleanup
Trigger GitHub release/publish explicitly, CI scripts cleanup
- Loading branch information
Showing
3 changed files
with
65 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Publish | ||
|
||
on: workflow_dispatch | ||
|
||
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 | ||
|
||
- 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)" | ||
echo "Project version from Cargo.toml is $VERSION" | ||
if ! (echo "$VERSION" | grep --quiet "^[0-9]\{1,2\}\.[0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\?$"); then | ||
echo "The version format does not look like a release version, not publishing the crate." | ||
exit 1 | ||
fi | ||
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters