Skip to content

Commit f6ac162

Browse files
committed
add release.yml
1 parent 08a9efa commit f6ac162

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
CRATES="protocol oauth core discovery audio metadata playback connect"
2+
3+
CURRENT_TAG=$(git describe --abbrev=0)
4+
LAST_TAG=$(git describe --abbrev=0 $CURRENT_TAG^)
5+
6+
BIN_VERSION=$(cat ./Cargo.toml | awk "/version/{print; exit}" | cut -d\" -f 2)
7+
8+
SIMPLE_VERSION_REGEX="^v?([0-9]+)\.([0-9]+)\.([0-9]+)$"
9+
if [[ $LAST_TAG =~ $SIMPLE_VERSION_REGEX ]]; then
10+
last_major="${BASH_REMATCH[1]}"
11+
last_minor="${BASH_REMATCH[2]}"
12+
last_patch="${BASH_REMATCH[3]}"
13+
else
14+
echo "regex for tag didn't match"
15+
exit 1
16+
fi
17+
18+
if [[ $BIN_VERSION =~ $SIMPLE_VERSION_REGEX ]]; then
19+
if [ "$last_major" != "${BASH_REMATCH[1]}" ] || [ "$last_minor" != "${BASH_REMATCH[2]}" ]; then
20+
echo "[]"
21+
exit 0
22+
elif [ "$last_patch" == "${BASH_REMATCH[3]}" ]; then
23+
echo "version didn't change"
24+
exit 1
25+
fi
26+
else
27+
echo "regex for bin version didn't match"
28+
exit 1
29+
fi
30+
31+
# if we go through here, we build a patch version and only want to update the crates that have changed
32+
AWK_CRATES=$(echo "$CRATES" | tr ' ' '|')
33+
DIFF_CRATES=$(git diff $LAST_TAG... --stat --name-only \
34+
| awk '/(rs|proto)$/{print}' \
35+
| awk "/($AWK_CRATES)/{print}" \
36+
| cut -d '/' -f 1 \
37+
| uniq \
38+
| tr '\n' ' ' \
39+
| xargs \
40+
| tr ' ' '|' )
41+
42+
EXCLUDED_DIFF=$(echo $CRATES \
43+
| tr ' ' '\n' \
44+
| awk "!/($DIFF_CRATES)/{print}" \
45+
| tr '\n' ' ' \
46+
| xargs \
47+
| sed "s/ /\" }\, { \"crate\": \"/g")
48+
49+
echo "[ { \"crate\": \"$EXCLUDED_DIFF\" } ]"

.github/workflows/release.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: release.yml
2+
on:
3+
release:
4+
types:
5+
- created
6+
workflow_dispatch:
7+
8+
jobs:
9+
get-excluded-crates:
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
outputs:
14+
excluded: ${{ steps.excluded-crates.outputs.EXCLUDE }}
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v5
18+
with:
19+
fetch-tags: true
20+
21+
- name: Get excluded crates
22+
id: excluded-crates
23+
run: |
24+
EXCLUDE=$(./.github/scripts/get-excluded-crates.sh)
25+
echo "excluding [$EXCLUDE]"
26+
echo EXCLUDE=$EXCLUDE >> ${GITHUB_OUTPUT}
27+
28+
publish-crates:
29+
name: Publish crate librespot-${{ matrix.crate }}
30+
needs: [ get-excluded-crates ]
31+
runs-on: ubuntu-latest
32+
permissions:
33+
contents: read
34+
strategy:
35+
max-parallel: 1 # for sequential execution because the order of publishing the crates is important
36+
matrix:
37+
# order is important
38+
crate:
39+
- protocol
40+
- oauth
41+
- core
42+
- discovery
43+
- audio
44+
- metadata
45+
- playback
46+
- connect
47+
# not all crates needs to be published all the time
48+
exclude: ${{ fromJSON(needs.get-excluded-crates.outputs.excluded) }}
49+
steps:
50+
- name: Checkout code
51+
uses: actions/checkout@v5
52+
53+
- name: Install Rust toolchain
54+
uses: dtolnay/rust-toolchain@stable
55+
56+
- name: Cache Rust dependencies
57+
uses: Swatinem/rust-cache@v2
58+
59+
- name: Install dependencies
60+
if: ${{ contains('connect playback', matrix.crate ) }} # only install the dep when the crate requires it
61+
run: sudo apt-get update && sudo apt-get install -y libasound2-dev
62+
63+
- name: Verify librespot-${{ matrix.crate }}
64+
run: cargo publish --package librespot-${{ matrix.crate }} --dry-run
65+
66+
- name: Publish librespot-${{ matrix.crate }}
67+
if: ${{ !env.ACT }}
68+
env:
69+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
70+
run: |
71+
if [ "${{ matrix.crate }}" = "protocol" ]; then
72+
cargo publish --package librespot-${{ matrix.crate }} --no-verify
73+
else
74+
cargo publish --package librespot-${{ matrix.crate }}
75+
fi
76+
77+
publish-binary:
78+
name: publish librespot binary
79+
needs: [ publish-crates ]
80+
runs-on: ubuntu-latest
81+
permissions:
82+
contents: read
83+
steps:
84+
- name: Checkout code
85+
uses: actions/checkout@v5
86+
87+
- name: Install Rust toolchain
88+
uses: dtolnay/rust-toolchain@stable
89+
90+
- name: Cache Rust dependencies
91+
uses: Swatinem/rust-cache@v2
92+
93+
- name: Install dependencies
94+
run: sudo apt-get update && sudo apt-get install -y libasound2-dev
95+
96+
- name: Verify librespot
97+
run: cargo publish --dry-run --allow-dirty
98+
99+
- name: Publish librespot
100+
if: ${{ !env.ACT }}
101+
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}

0 commit comments

Comments
 (0)