Skip to content

Commit 0140e88

Browse files
committed
add check-release-status
1 parent e95e99e commit 0140e88

File tree

1 file changed

+78
-43
lines changed

1 file changed

+78
-43
lines changed

.github/workflows/rust-release.yml

Lines changed: 78 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,78 @@ env:
3434
RUST_BACKTRACE: full
3535

3636
jobs:
37+
check-release-status:
38+
name: Check Release Status
39+
runs-on: depot-ubuntu-latest
40+
outputs:
41+
has_changes: ${{ steps.check_changes.outputs.has_changes }}
42+
should_release: ${{ steps.check_version.outputs.should_release }}
43+
current_version: ${{ steps.check_version.outputs.current_version }}
44+
latest_version: ${{ steps.check_version.outputs.latest_version }}
45+
steps:
46+
- uses: actions/checkout@v4
47+
with:
48+
fetch-depth: 0
49+
- name: Check if there are changes since last release
50+
id: check_changes
51+
working-directory: ./rust/main
52+
run: |
53+
# Get latest agents-v* tag
54+
LATEST_TAG=$(git tag -l "agents-v*" --sort=-version:refname | grep -E "^agents-v[0-9]+\.[0-9]+\.[0-9]+$" | head -1)
55+
56+
if [ -z "$LATEST_TAG" ]; then
57+
echo "No previous release found"
58+
echo "has_changes=true" >> $GITHUB_OUTPUT
59+
else
60+
# Check if there are commits to rust/main since last release
61+
COMMITS_SINCE=$(git log "$LATEST_TAG"..HEAD --oneline -- . | wc -l)
62+
echo "Commits since $LATEST_TAG: $COMMITS_SINCE"
63+
64+
if [ "$COMMITS_SINCE" -gt 0 ]; then
65+
echo "Found $COMMITS_SINCE commit(s) since last release"
66+
echo "has_changes=true" >> $GITHUB_OUTPUT
67+
else
68+
echo "No commits since last release"
69+
echo "has_changes=false" >> $GITHUB_OUTPUT
70+
fi
71+
fi
72+
- name: Check if version changed (for publish decision)
73+
id: check_version
74+
working-directory: ./rust/main
75+
run: |
76+
# Get current version from Cargo.toml
77+
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
78+
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
79+
echo "Current Cargo.toml version: $CURRENT_VERSION"
80+
81+
# Get latest agents-v* tag
82+
LATEST_TAG=$(git tag -l "agents-v*" --sort=-version:refname | grep -E "^agents-v[0-9]+\.[0-9]+\.[0-9]+$" | head -1)
83+
84+
if [ -z "$LATEST_TAG" ]; then
85+
echo "latest_version=" >> $GITHUB_OUTPUT
86+
echo "No previous release tag found, will create first release"
87+
echo "should_release=true" >> $GITHUB_OUTPUT
88+
else
89+
LATEST_VERSION=$(echo "$LATEST_TAG" | sed 's/agents-v//')
90+
echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT
91+
echo "Latest released version: $LATEST_VERSION"
92+
93+
if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then
94+
echo "Version has changed ($LATEST_VERSION -> $CURRENT_VERSION)"
95+
echo "should_release=true" >> $GITHUB_OUTPUT
96+
else
97+
echo "Version unchanged"
98+
echo "should_release=false" >> $GITHUB_OUTPUT
99+
fi
100+
fi
101+
37102
release-pr:
38103
name: Update Release PR
39104
runs-on: depot-ubuntu-latest
40-
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !inputs.prerelease)
105+
needs: check-release-status
106+
if: |
107+
(github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !inputs.prerelease)) &&
108+
needs.check-release-status.outputs.has_changes == 'true'
41109
steps:
42110
- uses: actions/checkout@v4
43111
with:
@@ -68,67 +136,34 @@ jobs:
68136
publish:
69137
name: Publish Release
70138
runs-on: depot-ubuntu-latest
139+
needs: [check-release-status, release-pr]
140+
# Allow release-pr to be skipped (for prereleases)
71141
if: |
72-
(github.event_name == 'push' &&
73-
github.ref == 'refs/heads/main') ||
74-
(github.event_name == 'workflow_dispatch' && inputs.prerelease)
142+
always() &&
143+
!failure() &&
144+
!cancelled() &&
145+
github.ref == 'refs/heads/main' &&
146+
((github.event_name == 'workflow_dispatch' && inputs.prerelease) ||
147+
(github.event_name == 'push' && needs.check-release-status.outputs.should_release == 'true'))
75148
steps:
76149
- uses: actions/checkout@v4
77150
with:
78151
fetch-depth: 0
79-
- name: Check if should release
80-
id: check_version
81-
working-directory: ./rust/main
82-
run: |
83-
# For manual prereleases, always release
84-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
85-
echo "Manual prerelease triggered, will release"
86-
echo "should_release=true" >> $GITHUB_OUTPUT
87-
exit 0
88-
fi
89-
90-
# For push events, check if version changed
91-
# Get current version from Cargo.toml
92-
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
93-
echo "Current Cargo.toml version: $CURRENT_VERSION"
94-
95-
# Get latest agents-v* tag
96-
LATEST_TAG=$(git tag -l "agents-v*" --sort=-version:refname | grep -E "^agents-v[0-9]+\.[0-9]+\.[0-9]+$" | head -1)
97-
98-
if [ -z "$LATEST_TAG" ]; then
99-
echo "No previous release tag found, will create first release"
100-
echo "should_release=true" >> $GITHUB_OUTPUT
101-
else
102-
LATEST_VERSION=$(echo "$LATEST_TAG" | sed 's/agents-v//')
103-
echo "Latest released version: $LATEST_VERSION"
104-
105-
if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then
106-
echo "Version has changed, proceeding with release"
107-
echo "should_release=true" >> $GITHUB_OUTPUT
108-
else
109-
echo "Version unchanged, skipping release"
110-
echo "should_release=false" >> $GITHUB_OUTPUT
111-
fi
112-
fi
113152
- name: Install git-cliff
114-
if: steps.check_version.outputs.should_release == true
115153
uses: taiki-e/install-action@v2
116154
with:
117155
tool: git-cliff
118156
- name: Determine version and create release
119-
if: steps.check_version.outputs.should_release == true
120157
working-directory: ./rust/main
121158
env:
122159
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
123160
IS_PRERELEASE: ${{ github.event_name == 'workflow_dispatch' && inputs.prerelease }}
124161
PRERELEASE_SUFFIX: ${{ inputs.prerelease_suffix }}
162+
BASE_VERSION: ${{ needs.check-release-status.outputs.current_version }}
125163
run: |
126164
git config user.name "github-actions[bot]"
127165
git config user.email "github-actions[bot]@users.noreply.github.com"
128166
129-
# Get base version from Cargo.toml
130-
BASE_VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
131-
132167
# Determine final version based on release type
133168
if [ "$IS_PRERELEASE" = "true" ]; then
134169
# Pre-release: append suffix

0 commit comments

Comments
 (0)