Skip to content

Commit 7b59f5a

Browse files
committed
ci: update release procedure
1 parent 4e9f1b5 commit 7b59f5a

File tree

2 files changed

+111
-51
lines changed

2 files changed

+111
-51
lines changed

.github/workflows/release-adapter.yml

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,60 @@
1-
name: Release
1+
name: Release Adapter
22

33
on:
44
push:
5-
tags:
6-
- 'adapter-v*.*.*'
5+
branches:
6+
- main
7+
paths:
8+
- crates/adapter/Cargo.toml
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
713

814
jobs:
9-
build:
15+
check-version:
16+
runs-on: ubuntu-latest
17+
outputs:
18+
version_changed: ${{ steps.check_version.outputs.version_changed }}
19+
new_version: ${{ steps.check_version.outputs.new_version }}
20+
steps:
21+
- uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 2
24+
- name: Check if version changed
25+
id: check_version
26+
run: |
27+
PACKAGE_NAME=$(grep '^name' crates/adapter/Cargo.toml | sed 's/name = "\(.*\)"/\1/')
28+
RELEASED_VERSION=$(cargo search $PACKAGE_NAME --limit 1 | grep -oP '(?<=").*(?=")')
29+
if [ $? -ne 0 ]; then
30+
echo "Failed to fetch released version"
31+
exit 1
32+
fi
33+
NEW_VERSION=$(grep '^version' crates/adapter/Cargo.toml | sed 's/version = "\(.*\)"/\1/')
34+
35+
if [ "$RELEASED_VERSION" != "$NEW_VERSION" ]; then
36+
echo "Version changed from $RELEASED_VERSION to $NEW_VERSION"
37+
echo "version_changed=true" >> $GITHUB_OUTPUT
38+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
39+
else
40+
echo "No version change"
41+
fi
42+
43+
publish:
44+
needs: check-version
45+
if: needs.check-version.outputs.version_changed == 'true'
1046
runs-on: ubuntu-latest
1147
defaults:
1248
run:
1349
working-directory: crates/adapter
14-
1550
steps:
16-
- name: Checkout code
17-
uses: actions/checkout@v3
18-
19-
- name: Set up Rust
20-
uses: actions-rs/toolchain@v1
21-
with:
22-
toolchain: stable
23-
override: true
24-
25-
- name: Build project
26-
run: cargo build --release
27-
28-
- name: Publish to crates.io
29-
env:
30-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
31-
run: cargo publish --token $CARGO_REGISTRY_TOKEN
51+
- uses: actions/checkout@v3
52+
- name: Set up Rust
53+
uses: actions-rs/toolchain@v1
54+
with:
55+
toolchain: stable
56+
override: true
57+
- name: Publish to crates.io
58+
env:
59+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
60+
run: cargo publish --token $CARGO_REGISTRY_TOKEN

.github/workflows/release.yml

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,70 @@
1-
name: Release
1+
name: Auto Release
22

33
on:
44
push:
5-
tags:
6-
- 'v*.*.*'
5+
branches:
6+
- main
7+
paths:
8+
- Cargo.toml
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
713

814
jobs:
9-
build:
15+
check-version:
1016
runs-on: ubuntu-latest
11-
17+
outputs:
18+
version_changed: ${{ steps.check_version.outputs.version_changed }}
19+
new_version: ${{ steps.check_version.outputs.new_version }}
1220
steps:
13-
- name: Checkout code
14-
uses: actions/checkout@v3
21+
- uses: actions/checkout@v3
22+
with:
23+
fetch-depth: 2
24+
- name: Check if version changed
25+
id: check_version
26+
run: |
27+
PACKAGE_NAME=$(grep '^name' Cargo.toml | sed 's/name = "\(.*\)"/\1/')
28+
RELEASED_VERSION=$(cargo search $PACKAGE_NAME --limit 1 | grep -oP '(?<=").*(?=")')
29+
if [ $? -ne 0 ]; then
30+
echo "Failed to fetch released version"
31+
exit 1
32+
fi
33+
NEW_VERSION=$(grep '^version' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
34+
35+
if [ "$RELEASED_VERSION" != "$NEW_VERSION" ]; then
36+
echo "Version changed from $RELEASED_VERSION to $NEW_VERSION"
37+
echo "version_changed=true" >> $GITHUB_OUTPUT
38+
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
39+
else
40+
echo "No version change"
41+
fi
1542
16-
- name: Set up Rust
17-
uses: actions-rs/toolchain@v1
18-
with:
19-
toolchain: stable
20-
override: true
21-
22-
- name: Build project
23-
run: cargo build --release
43+
create-release:
44+
needs: check-version
45+
if: needs.check-version.outputs.version_changed == 'true'
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v3
49+
- name: Create Release
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52+
run: |
53+
gh release create v${{ needs.check-version.outputs.new_version }} \
54+
--title "Release ${{ needs.check-version.outputs.new_version }}" \
55+
--generate-notes
2456
25-
# - name: Archive the build artifacts
26-
# run: tar -czvf build.tar.gz -C target/release .
27-
#
28-
# - name: Create Release
29-
# id: create_release
30-
# uses: softprops/action-gh-release@v1
31-
# with:
32-
# tag_name: ${{ github.ref }}
33-
# files: build.tar.gz
34-
# env:
35-
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36-
- name: Publish to crates.io
37-
env:
38-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
39-
run: cargo publish --token $CARGO_REGISTRY_TOKEN
57+
publish:
58+
needs: [check-version, create-release]
59+
runs-on: ubuntu-latest
60+
steps:
61+
- uses: actions/checkout@v3
62+
- name: Set up Rust
63+
uses: actions-rs/toolchain@v1
64+
with:
65+
toolchain: stable
66+
override: true
67+
- name: Publish to crates.io
68+
env:
69+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
70+
run: cargo publish --token $CARGO_REGISTRY_TOKEN

0 commit comments

Comments
 (0)