Skip to content

Commit d93b1f3

Browse files
authored
Merge pull request #682 from PetrGlad/github-ci-publish-cleanup
Trigger GitHub release/publish explicitly, CI scripts cleanup
2 parents d9c599e + ae7acb4 commit d93b1f3

File tree

3 files changed

+65
-79
lines changed

3 files changed

+65
-79
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: CI
33
on:
44
pull_request:
55
push:
6-
branches: [main, master]
6+
branches: [ main, master ]
77

88
env:
99
RUSTFLAGS: "-C debuginfo=0 -D warnings"
@@ -18,8 +18,8 @@ jobs:
1818
strategy:
1919
fail-fast: false
2020
matrix:
21-
os: [macos-latest, windows-latest, ubuntu-latest]
22-
toolchain: [stable, beta, nightly]
21+
os: [ macos-latest, windows-latest, ubuntu-latest ]
22+
toolchain: [ stable, beta, nightly ]
2323
include:
2424
- os: macos-latest
2525
MACOS: true
@@ -28,14 +28,11 @@ jobs:
2828
steps:
2929
- uses: actions/checkout@v4
3030

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

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

4138
- run: cargo clippy -- -D warnings
@@ -55,72 +52,3 @@ jobs:
5552
# Check minimal build. `tests/seek.rs` fails if there are no decoders at all,
5653
# adding one to make the tests check pass.
5754
- run: cargo check --tests --lib --no-default-features --features mp3
58-
cargo-publish:
59-
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
60-
env:
61-
CRATESIO_TOKEN: ${{ secrets.CRATESIO_TOKEN }}
62-
runs-on: ubuntu-latest
63-
steps:
64-
- uses: actions/checkout@v4
65-
- name: Update apt
66-
run: sudo apt update
67-
- name: Install alsa
68-
run: sudo apt install -y --no-install-recommends libasound2-dev pkg-config
69-
- name: Run cargo publish for rodio
70-
continue-on-error: true
71-
run: |
72-
RODIO_TMP=$(mktemp /tmp/rodioXXX.txt) || echo "::error::mktemp error"
73-
echo "RODIO_TMP=$RODIO_TMP" >> $GITHUB_ENV
74-
cargo publish --token $CRATESIO_TOKEN 2> $RODIO_TMP
75-
- name: Check if rodio is already published
76-
run: |
77-
empty=0
78-
RODIO_TMP="${{ env.RODIO_TMP }}"
79-
grep -q '[^[:space:]]' < $RODIO_TMP || empty=1
80-
[ $empty -eq 0 ] && cat $RODIO_TMP
81-
[ $empty -eq 1 ] || grep -q "is already uploaded" < $RODIO_TMP
82-
83-
create-git-tag:
84-
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
85-
runs-on: ubuntu-latest
86-
steps:
87-
- name: Check if WORKFLOW_TOKEN is set
88-
run: |
89-
if [ -z "${{ secrets.WORKFLOW_TOKEN }}" ]; then
90-
echo "Personal access token WORKFLOW_TOKEN is not set"
91-
exit 1
92-
else
93-
echo "Checked `WORKFLOW_TOKEN` is set"
94-
fi
95-
- name: Checkout code
96-
uses: actions/checkout@v4
97-
with:
98-
fetch-depth: 0 # Fetch all history to list all existing tags
99-
token: ${{ secrets.WORKFLOW_TOKEN }}
100-
- name: Extract version from Cargo.toml
101-
id: extract_version
102-
run: |
103-
version=$(awk '/\[package\]/,/^version/ { if ($1 == "version") { gsub(/"/, "", $3); print $3 } }' Cargo.toml)
104-
echo "Version value found: $version"
105-
echo "version=$version" >> $GITHUB_OUTPUT
106-
- name: Check if tag exists
107-
id: check_tag
108-
run: |
109-
version=${{ steps.extract_version.outputs.version }}
110-
version_name="v$version"
111-
if git rev-parse "refs/tags/$version_name" >/dev/null 2>&1; then
112-
echo "Tag $version_name already exists"
113-
echo "tag_exists=true" >> $GITHUB_OUTPUT
114-
else
115-
echo "Tag $version_name does not exist"
116-
echo "tag_exists=false" >> $GITHUB_OUTPUT
117-
fi
118-
- name: Create and push tag
119-
if: steps.check_tag.outputs.tag_exists == 'false'
120-
run: |
121-
version=${{ steps.extract_version.outputs.version }}
122-
git config --global user.name 'github-actions'
123-
git config --global user.email '[email protected]'
124-
version_name="v$version"
125-
git tag -a "$version_name" -m "Release for $version_name"
126-
git push origin $version_name

.github/workflows/publish.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Publish
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
cargo-publish:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
with:
12+
ref: ${{ inputs.version_tag }}
13+
14+
- name: Fetch tags
15+
run: git fetch --prune --unshallow --tags
16+
17+
- name: Install linux build requirements
18+
run: sudo apt install --yes --no-install-recommends libasound2-dev pkg-config
19+
20+
- name: Publish and tag
21+
run: |
22+
echo "Current git commit is $(git rev-list -n 1 HEAD)."
23+
24+
VERSION="$(yq '.package.version' Cargo.toml)"
25+
echo "Project version from Cargo.toml is $VERSION"
26+
if ! (echo "$VERSION" | grep --quiet "^[0-9]\{1,2\}\.[0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\?$"); then
27+
echo "The version format does not look like a release version, not publishing the crate."
28+
exit 1
29+
fi
30+
31+
VERSION_TAG="v$VERSION"
32+
if git tag | grep --quiet "^$VERSION_TAG$"; then
33+
echo "Tag $VERSION_TAG already exists at $(git rev-list -n 1 $VERSION_TAG), not publishing the crate."
34+
exit 1
35+
fi
36+
37+
cargo publish --token "${{ secrets.CRATESIO_TOKEN }}"
38+
39+
echo "Tagging current version with $VERSION_TAG ..."
40+
# The bot name and email is taken from here https://github.com/actions/checkout/pull/1707
41+
# see also https://api.github.com/users/github-actions%5Bbot%5D
42+
git config user.name "github-actions[bot]"
43+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
44+
git tag --annotate "$VERSION_TAG" --message "Release version $VERSION_TAG"
45+
git push origin "$VERSION_TAG"

CONTRIBUTING.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,24 @@ how to approach a particular task or contribution, don't hesitate to
141141
reach out to the maintainers for guidance.
142142

143143
# Guidelines for Maintainers
144+
144145
Guidelines for those with write access to rodio. Adhere to them as long as makes
145146
sense. This is a work in progress, more might follow as we get to know
146147
what works.
147148

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

150-
1. Do not merge your own code to main, unless of course its a trivial change.
151-
For example spelling/grammar or fixing up a PR by someone else.
151+
Do not merge your own code to main, unless of course its a trivial change.
152+
For example spelling/grammar or fixing up a PR by someone else.
153+
154+
## Release Procedure
155+
156+
The project is built automatically by a GitHub action when a new revision is pushed to the master branch.
157+
The crate is published by triggering `.github/workflows/publish.yml` GitHub action.
158+
After the crate is successfully published a new version's git tag is created in the repository.
159+
160+
So to publish a new version
161+
1. Update `project.version` field in `Cargo.toml`.
162+
2. Push the changes to the `master` branch.
163+
3. Wait until GitHub build job completes successfully.
164+
4. [On the Actions page](https://github.com/RustAudio/rodio/actions) start `.github/workflows/publish.yml`.

0 commit comments

Comments
 (0)